mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 11:20:09 +00:00 
			
		
		
		
	added loading and generation of JSON structure... apears that no-single-image-transitions is broken for some reason...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									4a00b4f75f
								
							
						
					
					
						commit
						70101c18c3
					
				| @ -27,6 +27,11 @@ var MOVE_DELTA = 50 | |||||||
| // NOTE: of only one callback is given then it will be called after the 
 | // NOTE: of only one callback is given then it will be called after the 
 | ||||||
| // 		 class change...
 | // 		 class change...
 | ||||||
| // 		 a way around this is to pass an empty function as callback_b
 | // 		 a way around this is to pass an empty function as callback_b
 | ||||||
|  | // the resulting function understands the folowing arguments:
 | ||||||
|  | // 	- 'on'			: switch mode on
 | ||||||
|  | // 	- 'off'			: switch mode off
 | ||||||
|  | // 	- '?'			: return current state ('on'|'off')
 | ||||||
|  | // 	- no arguments	: toggle the state
 | ||||||
| function createCSSClassToggler(elem, css_class, callback_a, callback_b){ | function createCSSClassToggler(elem, css_class, callback_a, callback_b){ | ||||||
| 	// prepare the pre/post callbacks...
 | 	// prepare the pre/post callbacks...
 | ||||||
| 	if(callback_b == null){ | 	if(callback_b == null){ | ||||||
| @ -38,12 +43,18 @@ function createCSSClassToggler(elem, css_class, callback_a, callback_b){ | |||||||
| 	} | 	} | ||||||
| 	// build the acual toggler function...
 | 	// build the acual toggler function...
 | ||||||
| 	return function(action){ | 	return function(action){ | ||||||
| 		if(action == null){ | 		if(action == null || action == '?'){ | ||||||
|  | 			var getter = action == '?' ? true : false | ||||||
| 			action = 'on' | 			action = 'on' | ||||||
| 			// get current state...
 | 			// get current state...
 | ||||||
| 			if( $(elem).hasClass(css_class) ){ | 			if( $(elem).hasClass(css_class) ){ | ||||||
| 				action = 'off' | 				action = 'off' | ||||||
| 			} | 			} | ||||||
|  | 			if(getter){ | ||||||
|  | 				// as the above actions indicate intent and not state, 
 | ||||||
|  | 				// we'll need to swap the values...
 | ||||||
|  | 				return action == 'on' ? 'off' : 'on' | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 		if(callback_pre != null){ | 		if(callback_pre != null){ | ||||||
| 			callback_pre(action) | 			callback_pre(action) | ||||||
| @ -234,6 +245,9 @@ function setupControlElements(){ | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | /**************************************************** Serialization **/ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| function loadImages(json){ | function loadImages(json){ | ||||||
| 	var images = json.images | 	var images = json.images | ||||||
| 	var ribbon = $('.ribbon').last() | 	var ribbon = $('.ribbon').last() | ||||||
| @ -253,6 +267,71 @@ function loadImages(json){ | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | /* | ||||||
|  |  * format: | ||||||
|  |  * 	{ | ||||||
|  |  * 		ribbons: [ | ||||||
|  |  * 			0: { | ||||||
|  |  * 				url: <image-URL>, | ||||||
|  |  * 				id: <image-id> | ||||||
|  |  * 			},				 | ||||||
|  |  * 			... | ||||||
|  |  * 		] | ||||||
|  |  * 	} | ||||||
|  |  */ | ||||||
|  | function buildJSON(){ | ||||||
|  | 	var ribbons = $('.ribbon') | ||||||
|  | 	res = { | ||||||
|  | 		ribbons: [] | ||||||
|  | 	} | ||||||
|  | 	for(var i=0; i < ribbons.length; i++){ | ||||||
|  | 		var images = $(ribbons[i]).children('.image') | ||||||
|  | 		var ribbon = [] | ||||||
|  | 		res.ribbons[res.ribbons.length] = ribbon | ||||||
|  | 		for(var j=0; j < images.length; j++){ | ||||||
|  | 			var image = $(images[j]) | ||||||
|  | 			ribbon[ribbon.length] = { | ||||||
|  | 				// unwrap the url...
 | ||||||
|  | 				// XXX would be nice to make this a relative path...
 | ||||||
|  | 				url: /url\((.*)\)/.exec(image.css('background-image'))[1], | ||||||
|  | 				id: image.attr('id'), | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return res | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // XXX add incremental or partial updates...
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | // XXX might be good to add images as packs here, not one by one...
 | ||||||
|  | function loadJSON(data){ | ||||||
|  | 	var ribbons = data.ribbons | ||||||
|  | 	var field = $('.field') | ||||||
|  | 
 | ||||||
|  | 	// drop all old content...
 | ||||||
|  | 	field.children().remove() | ||||||
|  | 
 | ||||||
|  | 	for(var i=0; i < ribbons.length; i++){ | ||||||
|  | 		var images = ribbons[i] | ||||||
|  | 		// create ribbon...
 | ||||||
|  | 		var ribbon = $('<div class="ribbon"></div>') | ||||||
|  | 			.appendTo(field) | ||||||
|  | 		for(var j=0; j < images.length; j++){ | ||||||
|  | 			var image = $(images[j]) | ||||||
|  | 			// create image...
 | ||||||
|  | 			$('<div class="image"></div>') | ||||||
|  | 				.css({ 'background-image': 'url('+image.attr('url')+')' }) | ||||||
|  | 				// set a unique id for each image...
 | ||||||
|  | 				.attr({'id': image.attr('id')}) | ||||||
|  | 				.click(setCurrentImage) | ||||||
|  | 				.appendTo(ribbon) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	$('.image').first().click() | ||||||
|  | } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| /*************************************************** Event Handlers **/ | /*************************************************** Event Handlers **/ | ||||||
| 
 | 
 | ||||||
| @ -331,7 +410,6 @@ function makeKeyboardHandler(keybindings, unhandled){ | |||||||
| 	if(unhandled == null){ | 	if(unhandled == null){ | ||||||
| 		unhandled = function(){return false} | 		unhandled = function(){return false} | ||||||
| 	} | 	} | ||||||
| 	console.log(keybindings) |  | ||||||
| 	return function(evt){ | 	return function(evt){ | ||||||
| 		var key = evt.keyCode | 		var key = evt.keyCode | ||||||
| 		// XXX ugly...
 | 		// XXX ugly...
 | ||||||
|  | |||||||
| @ -4,7 +4,8 @@ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| .single-image-mode .controller, .single-image-mode .controller-mini { | .single-image-mode .controller, | ||||||
|  | .single-image-mode .controller-mini { | ||||||
| 	opacity: 0.2; | 	opacity: 0.2; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -27,13 +28,16 @@ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| .single-image-mode .current.image:hover, .single-image-mode .current.image { | .single-image-mode .current.image:hover, | ||||||
|  | .single-image-mode .current.image { | ||||||
| 	opacity: 1.0; | 	opacity: 1.0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /* disabled animations */ | /* disabled animations */ | ||||||
| .single-image-mode.no-single-image-transitions .image, .single-image-mode.no-single-image-transitions .ribbon { | /* XXX for some reason this stopped working... */ | ||||||
|  | .single-image-mode.no-single-image-transitions .image, | ||||||
|  | .single-image-mode.no-single-image-transitions .ribbon { | ||||||
| 	-webkit-transition: none; | 	-webkit-transition: none; | ||||||
| 	-moz-transition: none; | 	-moz-transition: none; | ||||||
| 	-o-transition: all 0 ease; | 	-o-transition: all 0 ease; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user