mervynyang
3/21/2017 - 1:35 AM

proxySynchronousFile

proxySynchronousFile

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)
		}
	}
}