mirror of
				https://github.com/flynx/PortableMag.git
				synced 2025-10-31 12:00:11 +00:00 
			
		
		
		
	fixed a couple of bugs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									21fca66036
								
							
						
					
					
						commit
						0d4e7aaeae
					
				
							
								
								
									
										36
									
								
								lib/jli.js
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								lib/jli.js
									
									
									
									
									
								
							| @ -13,14 +13,14 @@ | ||||
| 
 | ||||
| /*********************************************************************/ | ||||
| 
 | ||||
| // this will create a function that will cycle through a class_list on elem 
 | ||||
| // This will create a function that will cycle through a class_list on elem 
 | ||||
| // calling the optional callbacks before and/or after.
 | ||||
| // if class_list is given as a string, then this will create a toggler that 
 | ||||
| // If class_list is given as a string, then this will create a toggler that 
 | ||||
| // will turn the given class on the element on and off.
 | ||||
| //
 | ||||
| // elem is a jquery compatible object; default use-case: a css selector.
 | ||||
| // Elem is a jquery compatible object; default use-case: a css selector.
 | ||||
| //
 | ||||
| // if class_list is a string, the resulting function understands the 
 | ||||
| // If class_list is a string, the resulting function understands the 
 | ||||
| // folowing arguments:
 | ||||
| // 	- <index>		: 0 for 'off' and 1 for 'on' (see below)
 | ||||
| // 	- 'on'			: switch mode on -- add class
 | ||||
| @ -28,7 +28,7 @@ | ||||
| // 	- '?'			: return current state ('on'|'off')
 | ||||
| // 	- no arguments	: toggle the state
 | ||||
| //
 | ||||
| // otherwise, if class_list is a list of strings:
 | ||||
| // Otherwise, if class_list is a list of strings:
 | ||||
| //  - <index>		: explicitly set the state to index in class_list
 | ||||
| //  - <class-name>	: explicitly set a class from the list
 | ||||
| // 	- '?'			: return current state ('on'|'off')
 | ||||
| @ -45,6 +45,17 @@ | ||||
| // 		to write the classes without leading dots, this now will normalize
 | ||||
| // 		the class list, so now this will correctly treat both dotted 
 | ||||
| // 		and non-dotted class names...
 | ||||
| //
 | ||||
| //
 | ||||
| // This also takes one or two callbacks. If only one is given then it is
 | ||||
| // called after (post) the change is made. If two are given then the first
 | ||||
| // is called before the change and the second after the change.
 | ||||
| // The callbacks are passed the current action.
 | ||||
| //
 | ||||
| // NOTE: the pre-callback will get the "intent" action, i.e. the state the
 | ||||
| // 		we are changing into but the changes are not yet made.
 | ||||
| // NOTE: if the pre-callback explicitly returns false, then the change will
 | ||||
| // 		not be made.
 | ||||
| function createCSSClassToggler(elem, class_list, callback_a, callback_b){ | ||||
| 	var bool_action = false | ||||
| 	if(typeof(class_list) == typeof('')){ | ||||
| @ -55,8 +66,8 @@ function createCSSClassToggler(elem, class_list, callback_a, callback_b){ | ||||
| 	// NOTE: this is here because I've made the error of including a 
 | ||||
| 	// 		leading "." almost every time I use this after I forget 
 | ||||
| 	// 		the UI...
 | ||||
| 	class_list = $(class_list).map(function(i, e){ | ||||
| 		return $(e.split(' ')).map(function(i, c){ | ||||
| 	class_list = $(class_list).map(function(_, e){ | ||||
| 		return $(e.split(' ')).map(function(_, c){ | ||||
| 			c = c.trim() | ||||
| 			return c[0] == '.' ? c.slice(1) : c | ||||
| 		}).toArray().join(' ') | ||||
| @ -122,8 +133,11 @@ function createCSSClassToggler(elem, class_list, callback_a, callback_b){ | ||||
| 		} | ||||
| 
 | ||||
| 		// pre callback...
 | ||||
| 		if(callback_a != null){ | ||||
| 			callback_a(action) | ||||
| 		if(callback_pre != null){ | ||||
| 			var res = callback_pre(action) | ||||
| 			if(res === false){ | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| 		// update the element...
 | ||||
| 		elem.removeClass(class_list.join(' ')) | ||||
| @ -131,8 +145,8 @@ function createCSSClassToggler(elem, class_list, callback_a, callback_b){ | ||||
| 			elem.addClass(cls) | ||||
| 		} | ||||
| 		// post callback...
 | ||||
| 		if(callback_b != null){ | ||||
| 			callback_b(action) | ||||
| 		if(callback_post != null){ | ||||
| 			callback_post(action) | ||||
| 		} | ||||
| 
 | ||||
| 		return action | ||||
|  | ||||
| @ -93,7 +93,6 @@ var _PAGE_VIEW | ||||
| var togglePageView = createCSSClassToggler( | ||||
| 	'.viewer',  | ||||
| 	'page-view-mode', | ||||
| 	null, | ||||
| 	// post-change callback...
 | ||||
| 	function(action){ | ||||
| 		if(action == 'on'){ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user