Created
March 21, 2017 01:35
-
-
Save yy-dev7/dd837c80d7cf321be36cd246f05858d1 to your computer and use it in GitHub Desktop.
proxySynchronousFile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var synchronousFile = function(id) { | |
console.log('开始同步文件,id 为: ' + id); | |
} | |
// 虚拟代理http请求 | |
var proxySynchronousFile = (function() { | |
var cache = [], timer | |
return function(id) { | |
cache.push(id) | |
if (timer) { | |
return | |
} | |
timer = setTimeout(function() { | |
synchronousFile(cache.join(',')) | |
clearTimeout(timer) | |
timer = null | |
cache.length = 0 | |
}, 3000) | |
} | |
}()) | |
var checkbox = document.getElementsByTagName('input') | |
for (var i = 0, c; c = checkbox[i++];) { | |
c.onclick = function() { | |
if (this.checked) { | |
proxySynchronousFile(this.id) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment