mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	added event handlers to makeDeferredPool(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									2f6ca2891c
								
							
						
					
					
						commit
						59caf58c1f
					
				| @ -1189,9 +1189,10 @@ progress:not(value)::-webkit-progress-bar { | |||||||
|   top: 20px; |   top: 20px; | ||||||
|   margin: 5px; |   margin: 5px; | ||||||
|   padding: 2px; |   padding: 2px; | ||||||
|  |   border-radius: 5px; | ||||||
|  |   background: rgba(0, 0, 0, 0.1); | ||||||
| } | } | ||||||
| .progress-container:hover { | .progress-container:hover { | ||||||
|   border-radius: 5px; |  | ||||||
|   background: rgba(0, 0, 0, 0.8); |   background: rgba(0, 0, 0, 0.8); | ||||||
| } | } | ||||||
| .progress-container:empty { | .progress-container:empty { | ||||||
| @ -1268,6 +1269,18 @@ progress:not(value)::-webkit-progress-bar { | |||||||
|   text-shadow: none; |   text-shadow: none; | ||||||
|   opacity: 0.8; |   opacity: 0.8; | ||||||
| } | } | ||||||
|  | .light.viewer progress::-webkit-progress-bar { | ||||||
|  |   border: solid 1px silver; | ||||||
|  | } | ||||||
|  | .light.viewer .progress-container { | ||||||
|  |   background: rgba(0, 0, 0, 0.05); | ||||||
|  | } | ||||||
|  | .light.viewer .progress-container:hover { | ||||||
|  |   background: rgba(0, 0, 0, 0.5); | ||||||
|  | } | ||||||
|  | .light.viewer .progress-bar { | ||||||
|  |   color: silver; | ||||||
|  | } | ||||||
| .gray.viewer, | .gray.viewer, | ||||||
| .gray.viewer .overlay-block .background { | .gray.viewer .overlay-block .background { | ||||||
|   background: #333; |   background: #333; | ||||||
|  | |||||||
| @ -1238,9 +1238,10 @@ progress:not(value)::-webkit-progress-bar { | |||||||
| 	top: 20px; | 	top: 20px; | ||||||
| 	margin: 5px; | 	margin: 5px; | ||||||
| 	padding: 2px; | 	padding: 2px; | ||||||
|  | 	border-radius: 5px; | ||||||
|  | 	background: rgba(0,0,0,0.1); | ||||||
| } | } | ||||||
| .progress-container:hover { | .progress-container:hover { | ||||||
| 	border-radius: 5px; |  | ||||||
| 	background: rgba(0,0,0,0.8); | 	background: rgba(0,0,0,0.8); | ||||||
| } | } | ||||||
| .progress-container:empty { | .progress-container:empty { | ||||||
| @ -1326,6 +1327,18 @@ progress:not(value)::-webkit-progress-bar { | |||||||
| 
 | 
 | ||||||
| 	opacity: 0.8; | 	opacity: 0.8; | ||||||
| } | } | ||||||
|  | .light.viewer progress::-webkit-progress-bar { | ||||||
|  | 	border: solid 1px silver; | ||||||
|  | } | ||||||
|  | .light.viewer .progress-container { | ||||||
|  | 	background: rgba(0,0,0,0.05); | ||||||
|  | } | ||||||
|  | .light.viewer .progress-container:hover { | ||||||
|  | 	background: rgba(0,0,0,0.5); | ||||||
|  | } | ||||||
|  | .light.viewer .progress-bar { | ||||||
|  | 	color: silver; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| .gray.viewer, | .gray.viewer, | ||||||
| .gray.viewer .overlay-block .background { | .gray.viewer .overlay-block .background { | ||||||
|  | |||||||
| @ -622,7 +622,15 @@ jQuery.fn.sortChildren = function(func){ | |||||||
| // 			NOTE: this will return false ONLY when the pool is empty.
 | // 			NOTE: this will return false ONLY when the pool is empty.
 | ||||||
| //
 | //
 | ||||||
| //
 | //
 | ||||||
| // Handler/callback registration:
 | // Event handler/callback registration:
 | ||||||
|  | //
 | ||||||
|  | // 		.on(evt, func) -> pool
 | ||||||
|  | // 			Register a handler (func) for an event (evt).
 | ||||||
|  | //
 | ||||||
|  | // 		.off(evt[, func]) -> pool
 | ||||||
|  | // 			Remove a handler (func) form and event (evt).
 | ||||||
|  | // 			NOTE: if func is omitted, remove all handlers from the given
 | ||||||
|  | // 					event...
 | ||||||
| //
 | //
 | ||||||
| // 		.progress(func) -> pool
 | // 		.progress(func) -> pool
 | ||||||
| // 			Register a progress handler.
 | // 			Register a progress handler.
 | ||||||
| @ -630,6 +638,8 @@ jQuery.fn.sortChildren = function(func){ | |||||||
| // 			passed:
 | // 			passed:
 | ||||||
| // 				- workers done count
 | // 				- workers done count
 | ||||||
| // 				- workers total count
 | // 				- workers total count
 | ||||||
|  | // 			Short hand for:
 | ||||||
|  | // 				.on('progress', func) -> pool
 | ||||||
| // 			NOTE: the total number of workers can change as new workers
 | // 			NOTE: the total number of workers can change as new workers
 | ||||||
| // 					are added or the queue is cleared...
 | // 					are added or the queue is cleared...
 | ||||||
| // 			
 | // 			
 | ||||||
| @ -639,18 +649,27 @@ jQuery.fn.sortChildren = function(func){ | |||||||
| // 			This will get passed:
 | // 			This will get passed:
 | ||||||
| // 				- workers done count
 | // 				- workers done count
 | ||||||
| // 				- workers total count
 | // 				- workers total count
 | ||||||
|  | // 			Short hand for:
 | ||||||
|  | // 				.on('fail', func) -> pool
 | ||||||
| // 			NOTE: this will not stop the execution of other handlers.
 | // 			NOTE: this will not stop the execution of other handlers.
 | ||||||
| //
 | //
 | ||||||
| // 		.pause(func) -> pool
 | // 		.pause(func) -> pool
 | ||||||
| // 			Register a pause handler.
 | // 			Register a pause handler.
 | ||||||
| // 			This handler is called after the last worker finishes when 
 | // 			This handler is called after the last worker finishes when 
 | ||||||
| // 			the queue is paused.
 | // 			the queue is paused.
 | ||||||
|  | // 			Short hand for:
 | ||||||
|  | // 				.on('progress', func) -> pool
 | ||||||
|  | //
 | ||||||
|  | // 		.resume(func) -> pool
 | ||||||
|  | // 			Short hand for:
 | ||||||
|  | // 				.on('resume', func) -> pool
 | ||||||
| //
 | //
 | ||||||
| // 		.depleted(func) -> pool
 | // 		.depleted(func) -> pool
 | ||||||
| // 			Register a depleted pool handler.
 | // 			Register a depleted pool handler.
 | ||||||
| // 			The handler will get called when the queue and pool are empty
 | // 			The handler will get called when the queue and pool are empty
 | ||||||
| // 			(depleted) and the last worker is done.
 | // 			(depleted) and the last worker is done.
 | ||||||
| //
 | // 			Short hand for:
 | ||||||
|  | // 				.on('deplete', func) -> pool
 | ||||||
| //
 | //
 | ||||||
| // XXX should this be an object or a factory???
 | // XXX should this be an object or a factory???
 | ||||||
| // XXX add a clean handler removal scheme (a-la jQuery event on/off)
 | // XXX add a clean handler removal scheme (a-la jQuery event on/off)
 | ||||||
| @ -661,24 +680,19 @@ function makeDeferredPool(size, paused){ | |||||||
| 		: size | 		: size | ||||||
| 	paused = paused == null ? false : paused | 	paused = paused == null ? false : paused | ||||||
| 
 | 
 | ||||||
| 	var event_names = [ |  | ||||||
| 		'deplete', |  | ||||||
| 		'progress', |  | ||||||
| 		'pause', |  | ||||||
| 		// XXX
 |  | ||||||
| 		//'resume',
 |  | ||||||
| 		'fail' |  | ||||||
| 	] |  | ||||||
| 
 | 
 | ||||||
| 	var Pool = { | 	var Pool = { | ||||||
| 		pool: [], | 		pool: [], | ||||||
| 		queue: [], | 		queue: [], | ||||||
| 		size: size, | 		size: size, | ||||||
| 
 | 
 | ||||||
| 		_deplete_handlers: [], | 		_event_handlers: { | ||||||
| 		_progress_handlers: [], | 			'deplete': [], | ||||||
| 		_pause_handlers: [], | 			'progress': [], | ||||||
| 		_fail_handlers: [], | 			'pause': [], | ||||||
|  | 			'resume': [], | ||||||
|  | 			'fail': [] | ||||||
|  | 		}, | ||||||
| 
 | 
 | ||||||
| 		_paused: paused, | 		_paused: paused, | ||||||
| 	} | 	} | ||||||
| @ -705,7 +719,7 @@ function makeDeferredPool(size, paused){ | |||||||
| 				// prepare to remove self from pool...
 | 				// prepare to remove self from pool...
 | ||||||
| 				var i = pool.indexOf(worker) | 				var i = pool.indexOf(worker) | ||||||
| 
 | 
 | ||||||
| 				Pool._progress_handlers.forEach(function(func){ | 				Pool._event_handlers['progress'].forEach(function(func){ | ||||||
| 					func(pool.length - pool.len(), pool.length + queue.length) | 					func(pool.length - pool.len(), pool.length + queue.length) | ||||||
| 				}) | 				}) | ||||||
| 
 | 
 | ||||||
| @ -722,7 +736,7 @@ function makeDeferredPool(size, paused){ | |||||||
| 				if(that._paused == true){ | 				if(that._paused == true){ | ||||||
| 					// if pool is empty fire the pause event...
 | 					// if pool is empty fire the pause event...
 | ||||||
| 					if(pool.len() == 0){ | 					if(pool.len() == 0){ | ||||||
| 						Pool._pause_handlers.forEach(function(func){ | 						Pool._event_handlers['pause'].forEach(function(func){ | ||||||
| 							func() | 							func() | ||||||
| 						}) | 						}) | ||||||
| 					} | 					} | ||||||
| @ -743,7 +757,7 @@ function makeDeferredPool(size, paused){ | |||||||
| 					// 		pushed to pool just before it's "compacted"...
 | 					// 		pushed to pool just before it's "compacted"...
 | ||||||
| 					pool.length = 0 | 					pool.length = 0 | ||||||
| 				 | 				 | ||||||
| 					that._deplete_handlers.forEach(function(func){ | 					that._event_handlers['deplete'].forEach(function(func){ | ||||||
| 						func(l) | 						func(l) | ||||||
| 					}) | 					}) | ||||||
| 				} | 				} | ||||||
| @ -752,7 +766,7 @@ function makeDeferredPool(size, paused){ | |||||||
| 				that._fill() | 				that._fill() | ||||||
| 			}) | 			}) | ||||||
| 			.fail(function(){ | 			.fail(function(){ | ||||||
| 				Pool._fail_handlers.forEach(function(func){ | 				Pool._event_handlers['fail'].forEach(function(func){ | ||||||
| 					func(pool.length - pool.len(), pool.length + queue.length) | 					func(pool.length - pool.len(), pool.length + queue.length) | ||||||
| 				}) | 				}) | ||||||
| 				deferred.reject.apply(deferred, arguments) | 				deferred.reject.apply(deferred, arguments) | ||||||
| @ -831,27 +845,37 @@ function makeDeferredPool(size, paused){ | |||||||
| 		if(func == null){ | 		if(func == null){ | ||||||
| 			this._paused = true | 			this._paused = true | ||||||
| 		} else { | 		} else { | ||||||
| 			this._pause_handlers.push(func) | 			this.on('pause', func) | ||||||
| 		} | 		} | ||||||
| 		return this | 		return this | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// XXX do we need a resume callback???
 |  | ||||||
| 	// XXX test...
 | 	// XXX test...
 | ||||||
| 	Pool.resume = function(){ | 	Pool.resume = function(func){ | ||||||
|  | 		if(func == null){ | ||||||
| 			this._paused = false | 			this._paused = false | ||||||
|  | 			this._event_handlers['resume'].forEach(function(f){ f() }) | ||||||
| 			this._fill() | 			this._fill() | ||||||
|  | 		} else { | ||||||
|  | 			this.on('resume', func) | ||||||
|  | 		} | ||||||
| 		return this | 		return this | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	// Generic event handlers...
 | 	// Generic event handlers...
 | ||||||
| 	Pool.on = function(evt, handler){ | 	Pool.on = function(evt, handler){ | ||||||
| 		// XXX
 | 		this._event_handlers[evt].push(handler) | ||||||
| 		return this | 		return this | ||||||
| 	} | 	} | ||||||
|  | 	// NOTE: if this is not given a handler, it will clear all handlers 
 | ||||||
|  | 	// 		from the given event...
 | ||||||
| 	Pool.off = function(evt, handler){ | 	Pool.off = function(evt, handler){ | ||||||
| 		// XXX
 | 		if(handler != null){ | ||||||
|  | 			this._event_handlers[evt].splice(this._event_handlers[evt].indexOf(handler), 1) | ||||||
|  | 		} else { | ||||||
|  | 			this._event_handlers[evt] = [] | ||||||
|  | 		} | ||||||
| 		return this | 		return this | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -868,8 +892,7 @@ function makeDeferredPool(size, paused){ | |||||||
| 	// 		finish, as this may get called after last worker is done and
 | 	// 		finish, as this may get called after last worker is done and
 | ||||||
| 	// 		the next is queued...
 | 	// 		the next is queued...
 | ||||||
| 	Pool.depleted = function(func){ | 	Pool.depleted = function(func){ | ||||||
| 		this._deplete_handlers.push(func) | 		return this.on('deplete', func) | ||||||
| 		return this |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Register queue progress handler...
 | 	// Register queue progress handler...
 | ||||||
| @ -881,15 +904,13 @@ function makeDeferredPool(size, paused){ | |||||||
| 	// 	- workers done
 | 	// 	- workers done
 | ||||||
| 	// 	- total workers (done + queued)
 | 	// 	- total workers (done + queued)
 | ||||||
| 	Pool.progress = function(func){ | 	Pool.progress = function(func){ | ||||||
| 		this._progress_handlers.push(func) | 		return this.on('progress', func) | ||||||
| 		return this |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Register worker fail handler...
 | 	// Register worker fail handler...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	Pool.fail = function(func){ | 	Pool.fail = function(func){ | ||||||
| 		this._fail_handlers.push(func) | 		return this.on('fail', func) | ||||||
| 		return this |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user