| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | if(typeof(module) !== 'undefined' && module.exports){ | 
					
						
							|  |  |  | 	var NW = true | 
					
						
							|  |  |  | 	var gui = require('nw.gui') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  | 	var NW = false | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-20 14:50:54 +03:00
										 |  |  | define(function(require){ var module = {} | 
					
						
							| 
									
										
										
										
											2015-09-07 15:06:45 +03:00
										 |  |  | console.log('>>> browse') | 
					
						
							| 
									
										
										
										
											2015-06-20 14:50:54 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 02:52:51 +03:00
										 |  |  | // XXX
 | 
					
						
							|  |  |  | var object = require('../../object') | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | var widget = require('./widget') | 
					
						
							| 
									
										
										
										
											2015-06-22 04:00:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-20 20:51:43 +03:00
										 |  |  | // NOTE: the widget itself does not need a title, that's the job for
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | //		a container widget (dialog, field, ...)
 | 
					
						
							|  |  |  | //		...it can be implemented trivially via an attribute and a :before
 | 
					
						
							|  |  |  | //		CSS class...
 | 
					
						
							|  |  |  | var BrowserClassPrototype = { | 
					
						
							|  |  |  | 	// construct the dom...
 | 
					
						
							|  |  |  | 	make: function(options){ | 
					
						
							|  |  |  | 		var browser = $('<div>') | 
					
						
							|  |  |  | 			.addClass('browse') | 
					
						
							|  |  |  | 			// make thie widget focusable...
 | 
					
						
							|  |  |  | 			// NOTE: tabindex 0 means automatic tab indexing and -1 means 
 | 
					
						
							|  |  |  | 			//		focusable bot not tabable...
 | 
					
						
							|  |  |  | 			//.attr('tabindex', -1)
 | 
					
						
							|  |  |  | 			.attr('tabindex', 0) | 
					
						
							|  |  |  | 			// focus the widget if something inside is clicked...
 | 
					
						
							|  |  |  | 			.click(function(){ | 
					
						
							|  |  |  | 				$(this).focus() | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 		if(options.flat){ | 
					
						
							|  |  |  | 			browser.addClass('flat') | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// path...
 | 
					
						
							|  |  |  | 		var path = $('<div>') | 
					
						
							|  |  |  | 			.addClass('v-block path') | 
					
						
							| 
									
										
										
										
											2015-06-22 05:57:15 +03:00
										 |  |  | 			/* | 
					
						
							|  |  |  | 			.click(function(){ | 
					
						
							|  |  |  | 				// XXX set contenteditable...
 | 
					
						
							|  |  |  | 				// XXX set value to path...
 | 
					
						
							|  |  |  | 				// XXX select all...
 | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			.on('blur', function(){ | 
					
						
							|  |  |  | 				// XXX unset contenteditable...
 | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			.keyup(function(){ | 
					
						
							|  |  |  | 				// XXX update path...
 | 
					
						
							|  |  |  | 				// 		- set /../..../ to path
 | 
					
						
							|  |  |  | 				// 		- use the part after the last '/' ad filter...
 | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		  	*/ | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 		if(options.show_path == false){ | 
					
						
							|  |  |  | 			path.hide() | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		browser | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 			.append(path) | 
					
						
							|  |  |  | 			// list...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 			.append($('<div>') | 
					
						
							|  |  |  | 				   .addClass('v-block list')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return browser | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | // XXX Q: should we make a base list dialog and build this on that or
 | 
					
						
							| 
									
										
										
										
											2015-06-20 20:51:43 +03:00
										 |  |  | //		simplify this to implement a list (removing the path and disabling
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | //		traversal)??
 | 
					
						
							|  |  |  | var BrowserPrototype = { | 
					
						
							|  |  |  | 	dom: null, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-18 03:34:15 +03:00
										 |  |  | 	// option defaults and doc...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	options: { | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 		// Initial path...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		//path: null,
 | 
					
						
							| 
									
										
										
										
											2015-05-18 03:34:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 		//show_path: true,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Enable/disable user selection filtering...
 | 
					
						
							| 
									
										
										
										
											2015-07-11 19:42:13 +03:00
										 |  |  | 		// NOTE: this only affects starting the filter...
 | 
					
						
							| 
									
										
										
										
											2015-06-20 20:51:43 +03:00
										 |  |  | 		filter: true, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 		// Enable/disable full path editing...
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 		// NOTE: as with .filter above, this only affects .startFullPathEdit(..)
 | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 		fullPathEdit: true, | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 		// If false will disable traversal...
 | 
					
						
							|  |  |  | 		// NOTE: if false this will also disable traversal up.
 | 
					
						
							|  |  |  | 		// NOTE: this will not disable manual updates or explicit path 
 | 
					
						
							|  |  |  | 		// 		setting.
 | 
					
						
							|  |  |  | 		// NOTE: another way to disable traversal is to set 
 | 
					
						
							|  |  |  | 		// 		.not-traversable on the .browse element
 | 
					
						
							|  |  |  | 		traversable: true, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Handle keys that are not bound...
 | 
					
						
							| 
									
										
										
										
											2015-05-18 03:34:15 +03:00
										 |  |  | 		// NOTE: to disable, set ot undefined.
 | 
					
						
							|  |  |  | 		logKeys: function(k){ window.DEBUG && console.log(k) }, | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// If set disables leading and trailing '/' on list and path 
 | 
					
						
							|  |  |  | 		// elements.
 | 
					
						
							|  |  |  | 		// This is mainly used for flat list selectors.
 | 
					
						
							|  |  |  | 		flat: false, | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// List of events that will not get propagated outside the browser...
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 		// NOTE: these are local events defined on the widget, so it 
 | 
					
						
							|  |  |  | 		// 		would not be logical to propagate them up the DOM, but if
 | 
					
						
							|  |  |  | 		// 		such behavior is desired one could always change the 
 | 
					
						
							|  |  |  | 		// 		configuration ;)
 | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 		nonPropagatedEvents: [ | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 			'push', | 
					
						
							|  |  |  | 			'pop', | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 			'open', | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 			'update', | 
					
						
							|  |  |  | 			'select', | 
					
						
							|  |  |  | 			'deselect', | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 		], | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 	// XXX TEST: this should prevent event propagation...
 | 
					
						
							| 
									
										
										
										
											2015-07-13 14:29:42 +03:00
										 |  |  | 	// XXX should we have things like ctrl-<number> for fast selection 
 | 
					
						
							|  |  |  | 	// 		in filter mode???
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	keyboard: { | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 		FullPathEdit: { | 
					
						
							|  |  |  | 			pattern: '.browse .path[contenteditable]', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// keep text editing action from affecting the selection...
 | 
					
						
							|  |  |  | 			ignore: [ | 
					
						
							|  |  |  | 					'Backspace', | 
					
						
							|  |  |  | 					'Up', | 
					
						
							|  |  |  | 					'Down', | 
					
						
							|  |  |  | 					'Left', | 
					
						
							|  |  |  | 					'Right', | 
					
						
							|  |  |  | 					'Home', | 
					
						
							|  |  |  | 					'End', | 
					
						
							|  |  |  | 					'Enter', | 
					
						
							|  |  |  | 					'Esc', | 
					
						
							|  |  |  | 					'/', | 
					
						
							|  |  |  | 					'A', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 					// let the system handle copy paste...
 | 
					
						
							| 
									
										
										
										
											2015-07-11 17:42:15 +03:00
										 |  |  | 					'C', 'V', 'X', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// enter numbers as-is...
 | 
					
						
							|  |  |  | 					'#1', '#2', '#3', '#4', '#5', '#6', '#7', '#8', '#9', | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 				], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Enter: 'stopFullPathEdit!', | 
					
						
							|  |  |  | 			Esc: 'abortFullPathEdit!', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 		Filter: { | 
					
						
							|  |  |  | 			pattern: '.browse .path div.cur[contenteditable]', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 05:57:15 +03:00
										 |  |  | 			// keep text editing action from affecting the selection...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 			ignore: [ | 
					
						
							|  |  |  | 					'Backspace', | 
					
						
							|  |  |  | 					'Left', | 
					
						
							|  |  |  | 					'Right', | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 					'Home', | 
					
						
							|  |  |  | 					'End', | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 					'Enter', | 
					
						
							|  |  |  | 					'Esc', | 
					
						
							| 
									
										
										
										
											2015-06-18 01:41:57 +03:00
										 |  |  | 					'/', | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 					'A', | 
					
						
							| 
									
										
										
										
											2015-06-28 05:23:31 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 					// let the system handle copy paste...
 | 
					
						
							| 
									
										
										
										
											2015-07-11 17:42:15 +03:00
										 |  |  | 					'C', 'V', 'X', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// enter numbers as-is...
 | 
					
						
							|  |  |  | 					'#1', '#2', '#3', '#4', '#5', '#6', '#7', '#8', '#9', | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 				], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-11 19:42:13 +03:00
										 |  |  | 			// XXX should this be an action or a push????
 | 
					
						
							|  |  |  | 			//Enter: 'action!',
 | 
					
						
							|  |  |  | 			Enter: 'push!', | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 			Esc: 'stopFilter!', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		General: { | 
					
						
							|  |  |  | 			pattern: '.browse', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 02:34:06 +03:00
										 |  |  | 			Up: 'prev!', | 
					
						
							|  |  |  | 			Down: 'next!', | 
					
						
							| 
									
										
										
										
											2015-06-25 05:26:41 +03:00
										 |  |  | 			Left: { | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 				default: 'pop!', | 
					
						
							|  |  |  | 				ctrl: 'update!: "/"', | 
					
						
							| 
									
										
										
										
											2015-06-25 05:26:41 +03:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 			Backspace: 'Left', | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 			Right: 'push', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 			Home: 'select!: "first"', | 
					
						
							|  |  |  | 			End: 'select!: "last"', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// XXX add page up and page down...
 | 
					
						
							|  |  |  | 			// XXX
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 			Enter: 'action', | 
					
						
							|  |  |  | 			Esc: 'close', | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			'/': 'startFilter!', | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			A: { | 
					
						
							|  |  |  | 				ctrl: 'startFullPathEdit!', | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2015-07-11 16:52:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-11 17:29:41 +03:00
										 |  |  | 			// XXX should these be select???
 | 
					
						
							|  |  |  | 			// XXX should these be relative to visible area or absolute 
 | 
					
						
							|  |  |  | 			// 		to current list regardless of scroll (as is now)???
 | 
					
						
							|  |  |  | 			// XXX should these work while filtering??
 | 
					
						
							|  |  |  | 			'#1': 'push: "0!"', | 
					
						
							|  |  |  | 			'#2': 'push: "1!"', | 
					
						
							|  |  |  | 			'#3': 'push: "2!"', | 
					
						
							|  |  |  | 			'#4': 'push: "3!"', | 
					
						
							|  |  |  | 			'#5': 'push: "4!"', | 
					
						
							|  |  |  | 			'#6': 'push: "5!"', | 
					
						
							|  |  |  | 			'#7': 'push: "6!"', | 
					
						
							|  |  |  | 			'#8': 'push: "7!"', | 
					
						
							|  |  |  | 			'#9': 'push: "8!"', | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 23:43:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	// Normalize path...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This converts the path into a universal absolute array 
 | 
					
						
							|  |  |  | 	// representation, taking care of relative path constructs including
 | 
					
						
							|  |  |  | 	// '.' (current path) and '..' (up one level)
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// XXX does this need to handle trailing '/'???
 | 
					
						
							|  |  |  | 	// 		...the problem is mainly encoding a trailing '/' into an 
 | 
					
						
							|  |  |  | 	// 		array, adding a '' at the end seems both obvious and 
 | 
					
						
							|  |  |  | 	// 		artificial...
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	// XXX is this the correct name???
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:37:14 +03:00
										 |  |  | 	// 		...should this be .normalizePath(..)???
 | 
					
						
							|  |  |  | 	path2list: function(path){ | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 		var splitter = /[\\\/]/ | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(typeof(path) == typeof('str')){ | 
					
						
							|  |  |  | 			path = path | 
					
						
							|  |  |  | 				.split(splitter) | 
					
						
							|  |  |  | 				.filter(function(e){ return e != '' }) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// we've got a relative path...
 | 
					
						
							|  |  |  | 		if(path[0] == '.' || path[0] == '..'){ | 
					
						
							|  |  |  | 			path = this.path.concat(path) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		path = path | 
					
						
							|  |  |  | 			// clear the '..'...
 | 
					
						
							|  |  |  | 			// NOTE: we reverse to avoid setting elements with negative
 | 
					
						
							|  |  |  | 			// 		indexes if we have a leading '..'
 | 
					
						
							|  |  |  | 			.reverse() | 
					
						
							|  |  |  | 			.map(function(e, i){ | 
					
						
							|  |  |  | 				if(e == '..'){ | 
					
						
							|  |  |  | 					e = '.' | 
					
						
							|  |  |  | 					path[i] = '.' | 
					
						
							|  |  |  | 					path[i+1] = '.' | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return e | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			.reverse() | 
					
						
							|  |  |  | 			// filter out '.'...
 | 
					
						
							|  |  |  | 			.filter(function(e){ return e != '.' }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return path | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 23:43:14 +03:00
										 |  |  | 	// Trigger jQuery events on Browser...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 	// This will pass the Browser instance to .source attribute of the
 | 
					
						
							| 
									
										
										
										
											2015-06-24 23:43:14 +03:00
										 |  |  | 	// event object triggered.
 | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 	// NOTE: event propagation for some events is disabled by binding 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// 		to them handlers that stop propagation in .__init__(..).
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 	// 		The list of non-propagated events in defined in 
 | 
					
						
							|  |  |  | 	// 		.options.nonPropagatedEvents
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// XXX triggering events from here and from jQuery/dom has a 
 | 
					
						
							|  |  |  | 	// 		different effect...
 | 
					
						
							|  |  |  | 	trigger: widget.triggerEventWithSource, | 
					
						
							| 
									
										
										
										
											2015-06-24 23:43:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 04:00:55 +03:00
										 |  |  | 	// proxy event api...
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 	on: widget.proxyToDom('on'), | 
					
						
							|  |  |  | 	one: widget.proxyToDom('one'), | 
					
						
							|  |  |  | 	off: widget.proxyToDom('off'), | 
					
						
							|  |  |  | 	bind: widget.proxyToDom('bind'), | 
					
						
							|  |  |  | 	unbind: widget.proxyToDom('unbind'), | 
					
						
							|  |  |  | 	deligate: widget.proxyToDom('deligate'), | 
					
						
							|  |  |  | 	undeligate: widget.proxyToDom('undeligate'), | 
					
						
							| 
									
										
										
										
											2015-06-22 04:00:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// specific events...
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 	focus: widget.proxyToDom('focus'), | 
					
						
							|  |  |  | 	blur: widget.proxyToDom('blur'), | 
					
						
							| 
									
										
										
										
											2015-06-22 04:00:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 	// base api...
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 	// XXX should these set both the options and dom???
 | 
					
						
							|  |  |  | 	get flat(){ | 
					
						
							|  |  |  | 		return !this.dom.hasClass('flat') || this.options.flat | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set flat(value){ | 
					
						
							|  |  |  | 		if(value){ | 
					
						
							|  |  |  | 			this.dom.addClass('flat') | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this.dom.removeClass('flat') | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.options.flat = value | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX should these set both the options and dom???
 | 
					
						
							|  |  |  | 	get traversable(){ | 
					
						
							|  |  |  | 		return !this.dom.hasClass('not-traversable') && this.options.traversable | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set traversable(value){ | 
					
						
							|  |  |  | 		if(value){ | 
					
						
							|  |  |  | 			this.dom.removeClass('not-traversable') | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this.dom.addClass('not-traversable') | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.options.traversable = value | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// Get/set the listed path...
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// On more info on setting the path see .update(..)
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// NOTE: .path = <path> is equivalent to .update(<path>) 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 	// NOTE: if the string path assigned does not contain a trailing '/'
 | 
					
						
							|  |  |  | 	// 		the path will be loaded up to the last item and the last item
 | 
					
						
							|  |  |  | 	// 		will be selected (see .update(..) for example).
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	// NOTE: to avoid duplicating and syncing data, the actual path is 
 | 
					
						
							|  |  |  | 	//		stored in DOM...
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 	// NOTE: path returned does not include the currently selected list 
 | 
					
						
							|  |  |  | 	// 		element, just the path to the current list...
 | 
					
						
							|  |  |  | 	// 		To get the path with selection use: .selectionPath prop
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	get path(){ | 
					
						
							|  |  |  | 		var skip = false | 
					
						
							| 
									
										
										
										
											2015-03-21 18:20:59 +03:00
										 |  |  | 		return this.dom.find('.path .dir:not(.cur)') | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 			.map(function(i, e){ return $(e).text() }) | 
					
						
							|  |  |  | 			.toArray() | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set path(value){ | 
					
						
							|  |  |  | 		return this.update(value) | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 	// String path...
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// This is the same as .path but returns a string result.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NOTE: this does not include the selected element, i.e. the returned 
 | 
					
						
							|  |  |  | 	// 		path always ends with a trailing '/'.
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 	// NOTE: the setter is just a shorthand to .path setter for uniformity...
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// XXX need to append '/' only if traversable...
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 	get strPath(){ | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 		return '/' + this.path.join('/') + '/' | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	set strPath(value){ | 
					
						
							|  |  |  | 		this.path = value | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 14:29:42 +03:00
										 |  |  | 	// Get/set path with selection...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// NOTE: this always returns the selected element last if one is 
 | 
					
						
							|  |  |  | 	// 		selected, if no element is selected this is equivalent to 
 | 
					
						
							|  |  |  | 	// 		.strPath
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 	// NOTE: the setter is just a shorthand to .path setter for uniformity...
 | 
					
						
							| 
									
										
										
										
											2015-07-13 14:29:42 +03:00
										 |  |  | 	get selectionPath(){ | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 		return this.strPath + (this.selected || '') | 
					
						
							| 
									
										
										
										
											2015-07-13 14:29:42 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	set selectionPath(value){ | 
					
						
							|  |  |  | 		this.path = value | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 	// Get/set current selection (text)...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// NOTE: .selected = <value> is equivalent to .select(<value>) for 
 | 
					
						
							|  |  |  | 	// 		more info on accepted values see .select(..)
 | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 	get selected(){ | 
					
						
							|  |  |  | 		var e = this.select('!') | 
					
						
							|  |  |  | 		if(e.length <= 0){ | 
					
						
							|  |  |  | 			return null | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return e.text() | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set selected(value){ | 
					
						
							|  |  |  | 		return this.select(value) | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 	// Copy/Paste actions...
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-11 22:26:06 +03:00
										 |  |  | 	// XXX use 'Text' for IE...
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 	copy: function(){ | 
					
						
							|  |  |  | 		var path = this.strPath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(NW){ | 
					
						
							|  |  |  | 			gui.Clipboard.get() | 
					
						
							|  |  |  | 				.set(path, 'text') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// browser...
 | 
					
						
							|  |  |  | 		// XXX use 'Test' for IE...
 | 
					
						
							|  |  |  | 		} else if(event != undefined){ | 
					
						
							|  |  |  | 			event.clipboardData.setData('text/plain', path) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return path | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	paste: function(str){ | 
					
						
							|  |  |  | 		// generic...
 | 
					
						
							|  |  |  | 		if(str != null){ | 
					
						
							|  |  |  | 			this.path = str | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// nw.js
 | 
					
						
							|  |  |  | 		} else if(NW){ | 
					
						
							|  |  |  | 			this.path = gui.Clipboard.get() | 
					
						
							|  |  |  | 				.get('text') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// browser...
 | 
					
						
							|  |  |  | 		// XXX use 'Test' for IE...
 | 
					
						
							|  |  |  | 		} else if(event != undefined){ | 
					
						
							|  |  |  | 			this.path = event.clipboardData.getData('text/plain') | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 14:29:42 +03:00
										 |  |  | 	// update (load) path...
 | 
					
						
							| 
									
										
										
										
											2015-03-22 02:12:30 +03:00
										 |  |  | 	// 	- build the path
 | 
					
						
							|  |  |  | 	// 	- build the element list
 | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 	// 	- bind to control events
 | 
					
						
							| 
									
										
										
										
											2015-03-22 02:12:30 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// This will trigger the 'update' event.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-24 18:21:49 +03:00
										 |  |  | 	// For uniformity and ease of access from DOM, this will also set the
 | 
					
						
							|  |  |  | 	// 'path' html attribute on the .browse element.
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 	// If the given string path does not end with a '/' then the path
 | 
					
						
							|  |  |  | 	// up to the last item will be loaded and the last item loaded.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Examle:
 | 
					
						
							|  |  |  | 	// 		Load and select...
 | 
					
						
							|  |  |  | 	// 		'/some/path/there'		-> .update('/some/path/')
 | 
					
						
							|  |  |  | 	// 									.select('there')
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 		Load path only...
 | 
					
						
							|  |  |  | 	// 		'/some/path/there/'		-> .update('/some/path/there/')
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 	// NOTE: setting the DOM attr 'path' works one way, navigating to a
 | 
					
						
							|  |  |  | 	// 		different path will overwrite the attr but setting a new 
 | 
					
						
							|  |  |  | 	// 		value to the html attr will not affect the actual path.
 | 
					
						
							|  |  |  | 	// NOTE: .path = <some-path> is equivalent to .update(<some-path>)
 | 
					
						
							|  |  |  | 	// 		both exist at the same time to enable chaining...
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 	// NOTE: this will scroll the path to show the last element for paths
 | 
					
						
							|  |  |  | 	// 		that do not fit in view...
 | 
					
						
							| 
									
										
										
										
											2015-06-24 18:21:49 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-20 20:51:43 +03:00
										 |  |  | 	// XXX need a way to handle path errors in the extension API...
 | 
					
						
							|  |  |  | 	// 		...for example, if .list(..) can't list or lists a different
 | 
					
						
							|  |  |  | 	// 		path due to an error, we need to be able to render the new
 | 
					
						
							|  |  |  | 	// 		path both in the path and list sections...
 | 
					
						
							|  |  |  | 	// 		NOTE: current behaviour is not wrong, it just not too flexible...
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 	update: function(path, list){ | 
					
						
							| 
									
										
										
										
											2015-03-22 02:12:30 +03:00
										 |  |  | 		path = path || this.path | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		var browser = this.dom | 
					
						
							|  |  |  | 		var that = this | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 		var focus = browser.find(':focus').length > 0 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 		list = list || this.list | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 		// string path and terminated with '/' -- no selection...
 | 
					
						
							|  |  |  | 		if(typeof(path) == typeof('str') && !/[\\\/]/.test(path.trim().slice(-1))){ | 
					
						
							| 
									
										
										
										
											2015-07-14 16:37:14 +03:00
										 |  |  | 			path = this.path2list(path) | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 			var selection = path.pop() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2015-07-14 16:37:14 +03:00
										 |  |  | 			path = this.path2list(path) | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 			var selection = null | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 		// clear the ui...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		var p = browser.find('.path').empty() | 
					
						
							|  |  |  | 		var l = browser.find('.list').empty() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 18:20:59 +03:00
										 |  |  | 		var c = [] | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		// fill the path field...
 | 
					
						
							|  |  |  | 		path.forEach(function(e){ | 
					
						
							| 
									
										
										
										
											2015-03-21 18:20:59 +03:00
										 |  |  | 			c.push(e) | 
					
						
							|  |  |  | 			var cur = c.slice() | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 			p.append($('<div>') | 
					
						
							|  |  |  | 				.addClass('dir') | 
					
						
							| 
									
										
										
										
											2015-03-21 18:20:59 +03:00
										 |  |  | 				.click(function(){ | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 					if(that.traversable){ | 
					
						
							|  |  |  | 						that | 
					
						
							|  |  |  | 							.update(cur.slice(0, -1))  | 
					
						
							|  |  |  | 							.select('"'+cur.pop()+'"') | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-03-21 18:20:59 +03:00
										 |  |  | 				}) | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 				.text(e)) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-20 20:51:43 +03:00
										 |  |  | 		// add current selection indicator...
 | 
					
						
							| 
									
										
										
										
											2015-06-22 05:57:15 +03:00
										 |  |  | 		var txt | 
					
						
							| 
									
										
										
										
											2015-03-21 18:20:59 +03:00
										 |  |  | 		p.append($('<div>') | 
					
						
							|  |  |  | 			.addClass('dir cur') | 
					
						
							|  |  |  | 			.click(function(){ | 
					
						
							| 
									
										
										
										
											2015-07-11 22:02:09 +03:00
										 |  |  | 				event.stopPropagation() | 
					
						
							| 
									
										
										
										
											2015-07-11 19:42:13 +03:00
										 |  |  | 				that.toggleFilter('on') | 
					
						
							| 
									
										
										
										
											2015-06-18 01:41:57 +03:00
										 |  |  | 			}) | 
					
						
							|  |  |  | 			.on('blur', function(){ | 
					
						
							| 
									
										
										
										
											2015-07-11 22:16:35 +03:00
										 |  |  | 				that.toggleFilter('off') | 
					
						
							| 
									
										
										
										
											2015-06-18 01:41:57 +03:00
										 |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2015-06-22 05:57:15 +03:00
										 |  |  | 			/* XXX does the right thing (replaces the later .focus(..)  | 
					
						
							|  |  |  | 			 * 		and .keyup(..)) but does not work in IE... | 
					
						
							|  |  |  | 			.on('input', function(){ | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 				that.filterList($(this).text()) | 
					
						
							| 
									
										
										
										
											2015-06-22 05:57:15 +03:00
										 |  |  | 			}) | 
					
						
							|  |  |  | 			*/ | 
					
						
							|  |  |  | 			// only update if text changed...
 | 
					
						
							|  |  |  | 			.focus(function(){ | 
					
						
							|  |  |  | 				txt = $(this).text() | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			.keyup(function(){ | 
					
						
							|  |  |  | 				var cur  = $(this).text() | 
					
						
							|  |  |  | 				if(txt != cur){ | 
					
						
							|  |  |  | 					txt = cur | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 					that.filterList(cur) | 
					
						
							| 
									
										
										
										
											2015-06-22 05:57:15 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-03-21 18:20:59 +03:00
										 |  |  | 			})) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// handle path scroll..
 | 
					
						
							|  |  |  | 		var e = p.children().last() | 
					
						
							|  |  |  | 		// scroll to the end when wider than view...
 | 
					
						
							|  |  |  | 		if(e.length > 0 && p.width() < p[0].scrollWidth){ | 
					
						
							|  |  |  | 			// scroll all the way to the right...
 | 
					
						
							|  |  |  | 			p.scrollLeft(p[0].scrollWidth) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// keep left aligned...
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			p.scrollLeft(0) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		// fill the children list...
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 		// NOTE: this will be set to true if make(..) is called at least once...
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 		var interactive = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 		var make = function(p, traversable){ | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 			p = p + '' | 
					
						
							|  |  |  | 			var dir = /[\\\/]\s*$/ | 
					
						
							|  |  |  | 			traversable = dir.test(p) && traversable == null ? true : traversable | 
					
						
							|  |  |  | 			traversable = traversable == null ? false : traversable | 
					
						
							|  |  |  | 			p = p.replace(dir, '') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 			interactive = true | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 			var res = $('<div>') | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 				// handle clicks ONLY when not disabled...
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 				.click(function(){ | 
					
						
							|  |  |  | 					if(!$(this).hasClass('disabled')){ | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 						that.push($(this).text())  | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 				.text(p) | 
					
						
							|  |  |  | 				.appendTo(l) | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 			if(!traversable){ | 
					
						
							|  |  |  | 				res.addClass('not-traversable') | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return res | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 		// build the list...
 | 
					
						
							|  |  |  | 		var res = list.call(this, path, make) | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 		// second API: make is not called and .list(..) returns an Array
 | 
					
						
							|  |  |  | 		// that will get loaded as list items...
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 		if(!interactive){ | 
					
						
							|  |  |  | 			res.forEach(make) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 		this.dom.attr('path', this.strPath) | 
					
						
							| 
									
										
										
										
											2015-06-22 04:00:55 +03:00
										 |  |  | 		this.trigger('update') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 14:31:44 +03:00
										 |  |  | 		// select the item...
 | 
					
						
							|  |  |  | 		if(selection){ | 
					
						
							|  |  |  | 			this.select(selection) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 		// maintain focus within the widget...
 | 
					
						
							|  |  |  | 		if(focus && browser.find(':focus').length == 0){ | 
					
						
							|  |  |  | 			this.focus() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 	// Filter the item list...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 	// 	General signature...
 | 
					
						
							|  |  |  | 	// 	.filter(<pattern>[, <rejected-handler>][, <ignore-disabled>])
 | 
					
						
							|  |  |  | 	// 		-> elements
 | 
					
						
							|  |  |  | 	// 	
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Get all elements...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 	// 	.filter()
 | 
					
						
							|  |  |  | 	// 	.filter('*')
 | 
					
						
							|  |  |  | 	// 		-> all elements
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 	// 	Get all elements containing a string...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 	// 	.filter(<string>)
 | 
					
						
							|  |  |  | 	// 		-> elements
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 	// 	Get all elements matching a regexp...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:18:28 +03:00
										 |  |  | 	// 	.filter(<regexp>)
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 	// 		-> elements
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 	// 	Filter the elements via a function...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 	// 	.filter(<function>)
 | 
					
						
							|  |  |  | 	// 		-> elements
 | 
					
						
							| 
									
										
										
										
											2015-06-21 20:19:15 +03:00
										 |  |  | 	// 		NOTE: the elements passed to the <function> on each iteration
 | 
					
						
							|  |  |  | 	// 			are unwrapped for compatibility with jQuery API.
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 	// 	Get specific element...
 | 
					
						
							|  |  |  | 	// 	.filter(<index>)
 | 
					
						
							|  |  |  | 	// 	.filter(<jQuery-obj>)
 | 
					
						
							|  |  |  | 	// 		-> element
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:51:11 +03:00
										 |  |  | 	//		-> $()
 | 
					
						
							| 
									
										
										
										
											2015-06-21 20:19:15 +03:00
										 |  |  | 	// 		NOTE: when passing a jQuery-obj it will be returned iff it's
 | 
					
						
							|  |  |  | 	// 			an element.
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:51:11 +03:00
										 |  |  | 	// 		NOTE: unlike .select(..) index overflow will produce empty 
 | 
					
						
							|  |  |  | 	// 			lists rather than to/bottom elements.
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 	// If <rejected-handler> function is passed it will get called with 
 | 
					
						
							|  |  |  | 	// every element that was rejected by the predicate / not matching 
 | 
					
						
							|  |  |  | 	// the pattern.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 	// By default, <ignore-disabled> is true, thus this will ignore 
 | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 	// disabled elements. If <ignore_disabled> is false then disabled 
 | 
					
						
							|  |  |  | 	// elements will be searched too.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-29 18:49:31 +03:00
										 |  |  | 	// NOTE: this will filter every item loaded regardless of visibility.
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:18:28 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-21 20:19:15 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 	// Extended string patterns:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// The pattern string is split by whitespace and each resulting 
 | 
					
						
							|  |  |  | 	// substring is searched independently.
 | 
					
						
							|  |  |  | 	// Order is not considered.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Examples:
 | 
					
						
							|  |  |  | 	// 		'aaa'			- matches any element containing 'aaa'
 | 
					
						
							| 
									
										
										
										
											2015-06-21 20:19:15 +03:00
										 |  |  | 	// 							(Same as: /aaa/)
 | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 	// 		'aa bb'			- matches any element containing both 'aa'
 | 
					
						
							|  |  |  | 	// 							AND 'bb' in any order.
 | 
					
						
							| 
									
										
										
										
											2015-06-21 20:19:15 +03:00
										 |  |  | 	// 							(Same as: /aa.*bb|bb.*aa/)
 | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-21 20:19:15 +03:00
										 |  |  | 	// NOTE: currently there is no way to search for whitespace explicitly,
 | 
					
						
							|  |  |  | 	// 		at this point this is "by-design" as an experiment on how
 | 
					
						
							|  |  |  | 	// 		vital this feature is.
 | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-20 20:51:43 +03:00
										 |  |  | 	// TODO need to support glob / nested patterns...
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 	// 		..things like /**/a*/*moo/ should list all matching items in
 | 
					
						
							|  |  |  | 	// 		a single list.
 | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 	filter: function(pattern, a, b){ | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 		pattern = pattern == null ? '*' : pattern | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 		var ignore_disabled = typeof(a) == typeof(true) ? a : b | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 		ignore_disabled = ignore_disabled == null ? true : ignore_disabled | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 		var rejected = typeof(a) == typeof(true) ? null : a | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var that = this | 
					
						
							|  |  |  | 		var browser = this.dom | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-29 18:49:31 +03:00
										 |  |  | 		var elems = browser.find('.list>div' + (ignore_disabled ? ':not(.disabled)' : '')) | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(pattern == '*'){ | 
					
						
							|  |  |  | 			return elems  | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// function...
 | 
					
						
							|  |  |  | 		if(typeof(pattern) == typeof(function(){})){ | 
					
						
							|  |  |  | 			var filter = function(i, e){ | 
					
						
							| 
									
										
										
										
											2015-06-21 20:19:15 +03:00
										 |  |  | 				e = e[0] | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 				if(!pattern.call(e, i, e)){ | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 					if(rejected){ | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 						rejected.call(e, i, e) | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					return false | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return true | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// regexp...
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 		} else if(pattern.constructor == RegExp){ | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 			var filter = function(i, e){ | 
					
						
							|  |  |  | 				if(!pattern.test($(e).text())){ | 
					
						
							|  |  |  | 					if(rejected){ | 
					
						
							| 
									
										
										
										
											2015-06-19 19:13:11 +03:00
										 |  |  | 						rejected.call(e, i, e) | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					return false | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return true | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// string...
 | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 		// NOTE: this supports several space-separated patterns.
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 		// XXX support glob...
 | 
					
						
							|  |  |  | 		} else if(typeof(pattern) == typeof('str')){ | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 			var pl = pattern.trim().split(/\s+/) | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 			var filter = function(i, e){ | 
					
						
							|  |  |  | 				e = $(e) | 
					
						
							|  |  |  | 				var t = e.text() | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 				for(var p=0; p < pl.length; p++){ | 
					
						
							|  |  |  | 					var i = t.search(pl[p]) | 
					
						
							|  |  |  | 					if(!(i >= 0)){ | 
					
						
							|  |  |  | 						if(rejected){ | 
					
						
							|  |  |  | 							rejected.call(e, i, e) | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						return false | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return true | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// number...
 | 
					
						
							|  |  |  | 		} else if(typeof(pattern) == typeof(123)){ | 
					
						
							|  |  |  | 			return elems.eq(pattern) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// jQuery object...
 | 
					
						
							|  |  |  | 		} else if(elems.index(pattern) >= 0){ | 
					
						
							|  |  |  | 			return pattern | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// unknown pattern...
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			return $() | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return elems.filter(filter) | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 	// Filter list elements...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This will set the .filtered-out class on all non-matching elements.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Use .filterList('*') to clear filter and show all elements.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// NOTE: see .filter(..) for docs on actual filtering.
 | 
					
						
							|  |  |  | 	// NOTE: this does not affect any UI modes, for list filtering mode
 | 
					
						
							| 
									
										
										
										
											2015-07-11 19:42:13 +03:00
										 |  |  | 	// 		see: .toggleFilter(..)...
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 	filterList: function(pattern){ | 
					
						
							|  |  |  | 		var that = this | 
					
						
							|  |  |  | 		var browser = this.dom | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// show all...
 | 
					
						
							|  |  |  | 		if(pattern == null || pattern.trim() == '*'){ | 
					
						
							| 
									
										
										
										
											2015-07-29 18:49:31 +03:00
										 |  |  | 			browser.find('.filtered-out') | 
					
						
							|  |  |  | 				.removeClass('filtered-out') | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 			// clear the highlighting...
 | 
					
						
							|  |  |  | 			browser.find('.list b') | 
					
						
							|  |  |  | 				.replaceWith(function() { return this.innerHTML }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// basic filter...
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			var p = RegExp('(' + pattern.trim().split(/\s+/).join('|') + ')', 'g') | 
					
						
							|  |  |  | 			this.filter(pattern, | 
					
						
							|  |  |  | 					// rejected...
 | 
					
						
							|  |  |  | 					function(i, e){ | 
					
						
							|  |  |  | 						e | 
					
						
							|  |  |  | 							.addClass('filtered-out') | 
					
						
							|  |  |  | 							.removeClass('selected') | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					// NOTE: setting this to true will not remove disabled
 | 
					
						
							|  |  |  | 					// 		elements from view as they will neither get 
 | 
					
						
							| 
									
										
										
										
											2015-07-29 18:49:31 +03:00
										 |  |  | 					// 		included in the filter nor in the filtered out
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 					// 		thus it will require manual setting of the
 | 
					
						
							|  |  |  | 					// 		.filtered-out class
 | 
					
						
							|  |  |  | 					false) | 
					
						
							| 
									
										
										
										
											2015-07-29 18:49:31 +03:00
										 |  |  | 				// passed...
 | 
					
						
							|  |  |  | 				.removeClass('filtered-out') | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 				// NOTE: this will mess up (clear) any highlighting that was 
 | 
					
						
							|  |  |  | 				// 		present before...
 | 
					
						
							|  |  |  | 				.each(function(_, e){ | 
					
						
							|  |  |  | 					e = $(e) | 
					
						
							|  |  |  | 					var t = e.text() | 
					
						
							|  |  |  | 					e.html(t.replace(p, '<b>$1</b>')) | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:18:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// internal actions...
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 	// full path editing...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 	// 	start ---->	edit --(enter)--> stop (accept)
 | 
					
						
							|  |  |  | 	// 				  |
 | 
					
						
							|  |  |  | 	// 			 	 +-------(esc)--> abort (reset)
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 	// NOTE: the event handlers for this are set in .__init__()...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 	// XXX should these be a toggle???
 | 
					
						
							|  |  |  | 	startFullPathEdit: function(){ | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 		if(this.options.fullPathEdit){ | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 			var browser = this.dom | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 			var path = this.strPath | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 			var orig = this.selected | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 			browser | 
					
						
							|  |  |  | 				.attr('orig-path', path) | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 				.attr('orig-selection', orig) | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			var range = document.createRange() | 
					
						
							|  |  |  | 			var selection = window.getSelection() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var e = browser.find('.path') | 
					
						
							|  |  |  | 				.text(path) | 
					
						
							|  |  |  | 				.attr('contenteditable', true) | 
					
						
							|  |  |  | 				.focus() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			range.selectNodeContents(e[0]) | 
					
						
							|  |  |  | 			selection.removeAllRanges() | 
					
						
							|  |  |  | 			selection.addRange(range) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	abortFullPathEdit: function(){ | 
					
						
							|  |  |  | 		var browser = this.dom | 
					
						
							|  |  |  | 		var e = browser.find('.path') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var path = '/' + browser.attr('orig-path') | 
					
						
							|  |  |  | 		var selection = browser.attr('orig-selection') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.stopFullPathEdit(path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(selection != ''){ | 
					
						
							|  |  |  | 			this.select(selection)	 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	stopFullPathEdit: function(path){ | 
					
						
							|  |  |  | 		var browser = this.dom | 
					
						
							|  |  |  | 			.removeAttr('orig-path') | 
					
						
							|  |  |  | 			.removeAttr('orig-selection') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var e = browser.find('.path') | 
					
						
							|  |  |  | 			.removeAttr('contenteditable') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 		this.path = path || e.text() | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 		return this | 
					
						
							|  |  |  | 			.focus() | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 	// list filtering...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	start ---->	edit / select --(enter)--> action (use selection)
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:30:58 +03:00
										 |  |  | 	// 					 |
 | 
					
						
							|  |  |  | 	// 					 +-------(blur/esc)--> exit (clear)
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 	// NOTE: the action as a side effect exits the filter (causes blur 
 | 
					
						
							|  |  |  | 	// 		on filter field)...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 	// NOTE: this uses .filter(..) for actual filtering...
 | 
					
						
							| 
									
										
										
										
											2015-07-11 19:42:13 +03:00
										 |  |  | 	// NOTE: on state change this will return this...
 | 
					
						
							|  |  |  | 	toggleFilter: CSSClassToggler( | 
					
						
							|  |  |  | 		function(){ return this.dom },  | 
					
						
							|  |  |  | 		'filtering', | 
					
						
							|  |  |  | 		// do not enter filter mode if filtering is disabled...
 | 
					
						
							|  |  |  | 		function(action){ return action != 'on' || this.options.filter }, | 
					
						
							|  |  |  | 		function(action){ | 
					
						
							|  |  |  | 			// on...
 | 
					
						
							|  |  |  | 			if(action == 'on'){ | 
					
						
							|  |  |  | 				var range = document.createRange() | 
					
						
							|  |  |  | 				var selection = window.getSelection() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var that = this | 
					
						
							|  |  |  | 				var e = this.dom.find('.path .dir.cur') | 
					
						
							|  |  |  | 					//.text('')
 | 
					
						
							|  |  |  | 					.attr('contenteditable', true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// place the cursor...
 | 
					
						
							|  |  |  | 				//range.setStart(e[0], 0)
 | 
					
						
							|  |  |  | 				//range.collapse(true)
 | 
					
						
							|  |  |  | 				range.selectNodeContents(e[0]) | 
					
						
							|  |  |  | 				selection.removeAllRanges() | 
					
						
							|  |  |  | 				selection.addRange(range) | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 			// off...
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				this.filterList('*') | 
					
						
							|  |  |  | 				this.dom | 
					
						
							|  |  |  | 					.find('.path .dir.cur') | 
					
						
							|  |  |  | 						.text('') | 
					
						
							|  |  |  | 						.removeAttr('contenteditable') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// NOTE: we might select an item outside of the current visible
 | 
					
						
							|  |  |  | 				// 		area, thus re-selecting it after we remove the filter 
 | 
					
						
							|  |  |  | 				// 		will place it correctly.
 | 
					
						
							|  |  |  | 				this.select(this.select('!')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				this.focus() | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-06-22 18:17:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-11 19:42:13 +03:00
										 |  |  | 			return this | 
					
						
							|  |  |  | 		}), | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// shorthands mostly for use as actions...
 | 
					
						
							| 
									
										
										
										
											2015-07-11 19:42:13 +03:00
										 |  |  | 	startFilter: function(){ return this.toggleFilter('on') }, | 
					
						
							|  |  |  | 	stopFilter: function(){ return this.toggleFilter('off') }, | 
					
						
							| 
									
										
										
										
											2015-06-26 15:22:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Toggle filter view mode...
 | 
					
						
							|  |  |  | 	toggleFilterViewMode: function(){ | 
					
						
							| 
									
										
										
										
											2015-06-18 00:23:23 +03:00
										 |  |  | 		this.dom.toggleClass('show-filtered-out') | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 	// XXX should this be a toggler???
 | 
					
						
							|  |  |  | 	disableElements: function(pattern){ | 
					
						
							|  |  |  | 		this.filter(pattern, false) | 
					
						
							|  |  |  | 			.addClass('disabled') | 
					
						
							|  |  |  | 			.removeClass('selected') | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	enableElements: function(pattern){ | 
					
						
							|  |  |  | 		this.filter(pattern, false) | 
					
						
							|  |  |  | 			.removeClass('disabled') | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 	// Select an element from current list...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-05-17 03:52:21 +03:00
										 |  |  | 	//	Get selected element if it exists, otherwise select and return 
 | 
					
						
							|  |  |  | 	//	the first...
 | 
					
						
							|  |  |  | 	//	.select()
 | 
					
						
							|  |  |  | 	//		-> elem
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	Get selected element if it exists, null otherwise...
 | 
					
						
							|  |  |  | 	//	.select('!')
 | 
					
						
							|  |  |  | 	//		-> elem
 | 
					
						
							|  |  |  | 	//		-> $()
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	//	Select first/last child
 | 
					
						
							|  |  |  | 	//	.select('first')
 | 
					
						
							|  |  |  | 	//	.select('last')
 | 
					
						
							|  |  |  | 	//		-> elem
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-05-17 03:52:21 +03:00
										 |  |  | 	//	Select previous/next child
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	//	.select('prev')
 | 
					
						
							|  |  |  | 	//	.select('next')
 | 
					
						
							|  |  |  | 	//		-> elem
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	Deselect
 | 
					
						
							|  |  |  | 	//	.select('none')
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 	//		-> $()
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	//	Select element by sequence number
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 	//	NOTE: negative numbers count from the tail.
 | 
					
						
							|  |  |  | 	//	NOTE: overflowing selects the first/last element.
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	//	.select(<number>)
 | 
					
						
							|  |  |  | 	//		-> elem
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-11 16:52:35 +03:00
										 |  |  | 	//	Select element by absolute sequence number
 | 
					
						
							|  |  |  | 	//	This is the same as above but will count disabled elements...
 | 
					
						
							|  |  |  | 	//	NOTE: this will not select unselectable (disabled) elements.
 | 
					
						
							|  |  |  | 	//	.select('<number>!')
 | 
					
						
							|  |  |  | 	//		-> elem
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 	//	Select element by its full or partial text...
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 	//	NOTE: if text matches one of the reserved commands above use 
 | 
					
						
							|  |  |  | 	//		quotes to escape it...
 | 
					
						
							|  |  |  | 	//	.select('<text>')
 | 
					
						
							|  |  |  | 	//	.select("'<text>'")
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	//	.select('"<text>"')
 | 
					
						
							|  |  |  | 	//		-> elem
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 	//	Select element via a regular expression...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 	//	.select(<regexp>)
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 	//		-> elem
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 	//		-> $()
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 	//	Select jQuery object...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	//	.select(<elem>)
 | 
					
						
							|  |  |  | 	//		-> elem
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 	//		-> $()
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// This will return a jQuery object.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// This will trigger the 'select' or 'deselect' events.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-24 18:21:49 +03:00
										 |  |  | 	// For uniformity and ease of access from DOM, this will also set 
 | 
					
						
							|  |  |  | 	// the value attr on the .browse element.
 | 
					
						
							|  |  |  | 	// NOTE: this is one way and setting the html attribute "value" will
 | 
					
						
							|  |  |  | 	// 		not affect the selection, but changing the selection will 
 | 
					
						
							|  |  |  | 	// 		overwrite the attribute.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 	// NOTE: if multiple matches occur this will select the first.
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 	// NOTE: 'none' will always return an empty jQuery object, to get 
 | 
					
						
							|  |  |  | 	// 		the selection state before deselecting use .select('!')
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 	// NOTE: this uses .filter(..) for string and regexp matching...
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:06:08 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// XXX should we unconditionally clear string quotes or can an item 
 | 
					
						
							|  |  |  | 	// 		contain '"' or "'"?
 | 
					
						
							|  |  |  | 	// 		...currently the outer quotes are cleared.
 | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 	select: function(elem, filtering){ | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		var browser = this.dom | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 		var pattern = '.list>div:not(.disabled):not(.filtered-out):visible' | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 		var elems = browser.find(pattern) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		if(elems.length == 0){ | 
					
						
							|  |  |  | 			return $() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-11 19:42:13 +03:00
										 |  |  | 		filtering = filtering == null ? this.toggleFilter('?') == 'on' : filtering | 
					
						
							| 
									
										
										
										
											2015-07-11 16:52:35 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 		// empty list/string selects none...
 | 
					
						
							|  |  |  | 		elem = elem != null && elem.length == 0 ? 'none' : elem | 
					
						
							|  |  |  | 		// 0 or no args (null) selects first...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 		elem = elem == 0 ? 'first' : elem | 
					
						
							|  |  |  | 		// no args -> either we start with the selected or the first...
 | 
					
						
							|  |  |  | 		if(elem == null){ | 
					
						
							|  |  |  | 			var cur = this.select('!') | 
					
						
							|  |  |  | 			elem = cur.length == 0 ? 'first' : cur | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-11 16:52:35 +03:00
										 |  |  | 		// special case: absolute position...
 | 
					
						
							|  |  |  | 		if(/\d+!/.test(elem)){ | 
					
						
							|  |  |  | 			elem = this.filter(parseInt(elem), false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(elems.index(elem) < 0){ | 
					
						
							|  |  |  | 				return this.select('none') | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return this.select(elem) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		// first/last...
 | 
					
						
							|  |  |  | 		if(elem == 'first' || elem == 'last'){ | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 			return this.select(elems[elem](), filtering) | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		// prev/next...
 | 
					
						
							|  |  |  | 		} else if(elem == 'prev' || elem == 'next'){ | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 			var to = this.select('!', filtering)[elem + 'All'](pattern).first() | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 			if(to.length == 0){ | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 				return this.select(elem == 'prev' ? 'last' : 'first', filtering) | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 			this.select('none', filtering) | 
					
						
							|  |  |  | 			return this.select(to, filtering) | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// deselect...
 | 
					
						
							|  |  |  | 		} else if(elem == 'none'){ | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 			if(!filtering){ | 
					
						
							|  |  |  | 				browser.find('.path .dir.cur').empty() | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-06-22 04:08:24 +03:00
										 |  |  | 			elems = elems | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 				.filter('.selected') | 
					
						
							|  |  |  | 				.removeClass('selected') | 
					
						
							| 
									
										
										
										
											2015-06-22 04:08:24 +03:00
										 |  |  | 			this.trigger('deselect', elems) | 
					
						
							| 
									
										
										
										
											2015-06-18 17:13:04 +03:00
										 |  |  | 			return $() | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// strict...
 | 
					
						
							|  |  |  | 		} else if(elem == '!'){ | 
					
						
							|  |  |  | 			return elems.filter('.selected') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// number...
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 		// NOTE: on overflow this will get the first/last element...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		} else if(typeof(elem) == typeof(123)){ | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 			return this.select($(elems.slice(elem)[0] || elems.slice(-1)[0] ), filtering) | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// string...
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 		} else if(typeof(elem) == typeof('str')){ | 
					
						
							| 
									
										
										
										
											2015-06-25 05:06:08 +03:00
										 |  |  | 			// clear quotes...
 | 
					
						
							|  |  |  | 			// XXX can an item contain '"' or "'"???
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 			if(/^'.*'$|^".*"$/.test(elem.trim())){ | 
					
						
							|  |  |  | 				elem = elem.trim().slice(1, -1) | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 			return this.select(this.filter(elem).first(), filtering) | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 		// regexp...
 | 
					
						
							|  |  |  | 		} else if(elem.constructor === RegExp){ | 
					
						
							| 
									
										
										
										
											2015-06-18 18:09:02 +03:00
										 |  |  | 			return this.select(this.filter(elem).first(), filtering) | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		// element...
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 			elem = $(elem).first() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(elem.length == 0){ | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 				this.select(null, filtering) | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2015-07-11 22:26:06 +03:00
										 |  |  | 				// clear selection...
 | 
					
						
							| 
									
										
										
										
											2015-06-18 00:13:30 +03:00
										 |  |  | 				this.select('none', filtering) | 
					
						
							|  |  |  | 				if(!filtering){ | 
					
						
							|  |  |  | 					browser.find('.path .dir.cur').text(elem.text()) | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-06-18 02:34:06 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// handle scroll position...
 | 
					
						
							|  |  |  | 				var p = elem.scrollParent() | 
					
						
							|  |  |  | 				var S = p.scrollTop() | 
					
						
							|  |  |  | 				var H = p.height() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var h = elem.height() | 
					
						
							|  |  |  | 				var t = elem.offset().top - p.offset().top | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var D = 3 * h  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// too low...
 | 
					
						
							|  |  |  | 				if(t+h+D > H){ | 
					
						
							|  |  |  | 					p.scrollTop(S + (t+h+D) - H) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// too high...
 | 
					
						
							|  |  |  | 				} else if(t < D){ | 
					
						
							|  |  |  | 					p.scrollTop(S + t - D) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-11 22:26:06 +03:00
										 |  |  | 				// now do the selection...
 | 
					
						
							| 
									
										
										
										
											2015-06-22 04:08:24 +03:00
										 |  |  | 				elem.addClass('selected') | 
					
						
							| 
									
										
										
										
											2015-06-24 18:21:49 +03:00
										 |  |  | 				browser.attr('value', elem.text()) | 
					
						
							| 
									
										
										
										
											2015-06-22 04:08:24 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 04:00:55 +03:00
										 |  |  | 				this.trigger('select', elem) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 04:08:24 +03:00
										 |  |  | 				return elem | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:06:08 +03:00
										 |  |  | 	// Select next/prev element...
 | 
					
						
							| 
									
										
										
										
											2015-05-17 03:52:21 +03:00
										 |  |  | 	next: function(elem){ | 
					
						
							|  |  |  | 		if(elem != null){ | 
					
						
							|  |  |  | 			this.select(elem) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.select('next') | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	prev: function(elem){ | 
					
						
							|  |  |  | 		if(elem != null){ | 
					
						
							|  |  |  | 			this.select(elem) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.select('prev') | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Push an element to path / go down one level...
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:06:08 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// This will trigger the 'push' event.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-11 22:16:35 +03:00
										 |  |  | 	// NOTE: if the element is not traversable it will be opened.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	// XXX might be a good idea to add a live traversable check...
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 	// XXX revise event...
 | 
					
						
							| 
									
										
										
										
											2015-07-11 17:29:41 +03:00
										 |  |  | 	push: function(pattern){ | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		var browser = this.dom  | 
					
						
							| 
									
										
										
										
											2015-07-11 17:29:41 +03:00
										 |  |  | 		var cur = this.select('!') | 
					
						
							|  |  |  | 		var elem = this.select(pattern || '!') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// item not found...
 | 
					
						
							|  |  |  | 		if(elem.length == 0 && pattern != null){ | 
					
						
							|  |  |  | 			return this | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// nothing selected, select first and exit...
 | 
					
						
							| 
									
										
										
										
											2015-07-11 17:29:41 +03:00
										 |  |  | 		if(cur.length == 0 && elem.length == 0){ | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 			this.select() | 
					
						
							|  |  |  | 			return this | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// if not traversable call the action...
 | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 		if(!this.traversable || elem.hasClass('not-traversable')){ | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 			return this.action() | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 		var path = this.path | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 		var txt = elem.text() | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 		path.push(elem.text()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 		// XXX should this be before or after the actual path update???
 | 
					
						
							|  |  |  | 		// XXX can we cancel the update from a handler???
 | 
					
						
							|  |  |  | 		this.trigger('push', path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 		// do the actual traverse...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		this.path = path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.select() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2015-06-25 05:06:08 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 03:52:21 +03:00
										 |  |  | 	// Pop an element off the path / go up one level...
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:06:08 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// This will trigger the 'pop' event.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 	// XXX revise event...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	pop: function(){ | 
					
						
							|  |  |  | 		var browser = this.dom | 
					
						
							| 
									
										
										
										
											2015-06-21 16:12:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(!this.traversable){ | 
					
						
							|  |  |  | 			return this | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		var path = this.path | 
					
						
							|  |  |  | 		var dir = path.pop() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 		// XXX should this be before or after the actual path update???
 | 
					
						
							|  |  |  | 		// XXX can we cancel the update from a handler???
 | 
					
						
							|  |  |  | 		this.trigger('pop', path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		this.update(path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.select('"'+dir+'"') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	// Pre-open action...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// This opens (.open(..)) the selected item and if none are selected
 | 
					
						
							|  |  |  | 	// selects the default (.select()) and exits.
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	action: function(){ | 
					
						
							|  |  |  | 		var elem = this.select('!') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// nothing selected, select first and exit...
 | 
					
						
							|  |  |  | 		if(elem.length == 0){ | 
					
						
							|  |  |  | 			this.select() | 
					
						
							|  |  |  | 			return this | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 		var path = this.path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		path.push(elem.text()) | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var res = this.open(path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return res | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 04:00:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:36:40 +03:00
										 |  |  | 	// Extension methods...
 | 
					
						
							|  |  |  | 	// ...these are resolved from .options
 | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Open action...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 	// 	Open current element...
 | 
					
						
							|  |  |  | 	// 	NOTE: if no element selected this will do nothing.
 | 
					
						
							|  |  |  | 	// 	NOTE: this will return the return of .options.open(..) or the 
 | 
					
						
							|  |  |  | 	// 		full path if null is returned...
 | 
					
						
							|  |  |  | 	// 	.open()
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	// 		-> object
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Open a path...
 | 
					
						
							|  |  |  | 	// 	.open(<path>)
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	// 		-> object
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Register an open event handler...
 | 
					
						
							|  |  |  | 	// 	.open(<function>)
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// The following signatures are relative from current context via 
 | 
					
						
							|  |  |  | 	// .select(..), see it for more details...
 | 
					
						
							|  |  |  | 	// NOTE: this will also select the opened element, so to get the full
 | 
					
						
							|  |  |  | 	// 		path from the handler just get the current path and value:
 | 
					
						
							|  |  |  | 	// 			browser.dom.attr('path') +'/'+ browser.dom.attr('value')
 | 
					
						
							| 
									
										
										
										
											2015-07-13 14:29:42 +03:00
										 |  |  | 	// 		or:
 | 
					
						
							|  |  |  | 	// 			browser.selectionPath
 | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Open first/last element...
 | 
					
						
							|  |  |  | 	// 	.open('first')
 | 
					
						
							|  |  |  | 	// 	.open('last')
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Open next/prev element...
 | 
					
						
							|  |  |  | 	// 	.open('next')
 | 
					
						
							|  |  |  | 	// 	.open('prev')
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Open active element at index...
 | 
					
						
							|  |  |  | 	// 	.open(<number>)
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Open element by absolute index...
 | 
					
						
							|  |  |  | 	// 	.open('<number>!')
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Open element by full or partial text...
 | 
					
						
							|  |  |  | 	//	.open('<text>')
 | 
					
						
							|  |  |  | 	//	.open("'<text>'")
 | 
					
						
							|  |  |  | 	//	.open('"<text>"')
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	Open first element matching a regexp...
 | 
					
						
							|  |  |  | 	//	.open(<regexp>)
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//	Open an element explicitly...
 | 
					
						
							|  |  |  | 	//	.open(<elem>)
 | 
					
						
							|  |  |  | 	// 		-> this
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// This will trigger the 'open' event on the opened element and the
 | 
					
						
							|  |  |  | 	// widget.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	// This is called when an element is selected and opened.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// By default this happens in the following situations:
 | 
					
						
							|  |  |  | 	// 	- an element is selected and Enter is pressed.
 | 
					
						
							|  |  |  | 	// 	- an element is not traversable and push (Left, click) is called.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// By default this only triggers the 'open' event on both the browser
 | 
					
						
							|  |  |  | 	// and the selected element if one exists.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-11 17:29:41 +03:00
										 |  |  | 	// This is signature compatible with .select(..) but adds support 
 | 
					
						
							|  |  |  | 	// for full paths.
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-07-11 22:26:06 +03:00
										 |  |  | 	// The .options.open(..), if defined, will always get the full path 
 | 
					
						
							|  |  |  | 	// as first argument.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	// NOTE: if nothing is selected this will do nothing...
 | 
					
						
							|  |  |  | 	// NOTE: internally this is never called directly, instead a pre-open
 | 
					
						
							|  |  |  | 	// 		stage is used to execute default behavior not directly 
 | 
					
						
							|  |  |  | 	// 		related to opening an item (see: .action()).
 | 
					
						
							|  |  |  | 	// NOTE: unlike .list(..) this can be used directly if an item is 
 | 
					
						
							|  |  |  | 	// 		selected and an actual open action is defined, either in an
 | 
					
						
							|  |  |  | 	// 		instance or in .options
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	open: function(path){  | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 		// special case: register the open handler...
 | 
					
						
							|  |  |  | 		if(typeof(path) == typeof(function(){})){ | 
					
						
							|  |  |  | 			return this.on('open', path) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 17:22:01 +03:00
										 |  |  | 		var elem = this.select('!') | 
					
						
							| 
									
										
										
										
											2015-06-22 06:01:54 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 		// get path + selection...
 | 
					
						
							|  |  |  | 		if(!path){ | 
					
						
							|  |  |  | 			// nothing selected, select first and exit...
 | 
					
						
							|  |  |  | 			if(elem.length == 0){ | 
					
						
							|  |  |  | 				//this.select()
 | 
					
						
							|  |  |  | 				return this | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// load the current path + selection...
 | 
					
						
							|  |  |  | 			path = this.path | 
					
						
							|  |  |  | 			path.push(elem.text()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// normalize and load path...
 | 
					
						
							| 
									
										
										
										
											2015-07-11 17:29:41 +03:00
										 |  |  | 		//} else {
 | 
					
						
							|  |  |  | 		} else if(path.constructor == Array || /[\\\/]/.test(path)) { | 
					
						
							| 
									
										
										
										
											2015-07-14 16:37:14 +03:00
										 |  |  | 			path = this.path2list(path) | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 			var elem = path.slice(-1)[0] | 
					
						
							|  |  |  | 			this.path = path.slice(0, -1) | 
					
						
							|  |  |  | 			elem = this.select(elem) | 
					
						
							| 
									
										
										
										
											2015-07-11 17:29:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// select-compatible -- select from current context...	
 | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 		// XXX this is semilar to the first branch, should we merge them???
 | 
					
						
							| 
									
										
										
										
											2015-07-11 17:29:41 +03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			elem = this.select(path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(elem.length == 0){ | 
					
						
							|  |  |  | 				return this | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			path = this.path | 
					
						
							|  |  |  | 			path.push(elem.text()) | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// get the options method and call it if it exists...
 | 
					
						
							|  |  |  | 		var m = this.options.open | 
					
						
							|  |  |  | 		var args = args2array(arguments) | 
					
						
							|  |  |  | 		args[0] = path | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 		var res = m ? m.apply(this, args) : this | 
					
						
							|  |  |  | 		res = res || this | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 		// XXX do we strigify the path???
 | 
					
						
							|  |  |  | 		path = '/' + path.join('/') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 		// trigger the 'open' events...
 | 
					
						
							| 
									
										
										
										
											2015-06-22 17:22:01 +03:00
										 |  |  | 		if(elem.length > 0){ | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 			// NOTE: this will bubble up to the browser root...
 | 
					
						
							|  |  |  | 			elem.trigger({ | 
					
						
							|  |  |  | 					type: 'open', | 
					
						
							|  |  |  | 					source: this, | 
					
						
							|  |  |  | 				}, path) | 
					
						
							| 
									
										
										
										
											2015-07-12 18:51:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this.trigger('open', path) | 
					
						
							| 
									
										
										
										
											2015-06-22 17:22:01 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-06-22 06:01:54 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return res | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2015-06-21 19:58:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 	// List current path level...
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// This will get passed a path and an item constructor and should 
 | 
					
						
							|  |  |  | 	// return a list.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	// NOTE: This is not intended for direct client use, rather it is 
 | 
					
						
							|  |  |  | 	// 		designed to either be overloaded by the user in an instance 
 | 
					
						
							|  |  |  | 	// 		or in the .options
 | 
					
						
							|  |  |  | 	//		To re-list/re-load the view use .update()
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 	// There are two mods of operation:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 1) interactive:
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:54:21 +03:00
										 |  |  | 	// 		.list(path, make)
 | 
					
						
							|  |  |  | 	// 			- for each item make is called with it's text
 | 
					
						
							|  |  |  | 	//			- make will return a jQuery object of the item
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// 		NOTE: selection is currently done based on .text() thus the 
 | 
					
						
							|  |  |  | 	// 			modification should not affect it's output...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 2) non-interactive:
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:54:21 +03:00
										 |  |  | 	// 		.list(path) -> list
 | 
					
						
							| 
									
										
										
										
											2015-06-22 04:00:55 +03:00
										 |  |  | 	// 			- .list(..) should return an array
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:54:21 +03:00
										 |  |  | 	// 			- make should never get called
 | 
					
						
							|  |  |  | 	// 			- the returned list will be rendered
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-21 04:15:54 +03:00
										 |  |  | 	//
 | 
					
						
							|  |  |  | 	// This can set the following classes on elements:
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	.disabled
 | 
					
						
							|  |  |  | 	// 		an element is disabled.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	.non-traversable
 | 
					
						
							|  |  |  | 	// 		an element is not traversable/listable and will trigger the
 | 
					
						
							| 
									
										
										
										
											2015-06-25 04:49:27 +03:00
										 |  |  | 	// 		.open(..) on push...
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 	// XXX need a way to constructively communicate errors up...
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 	// XXX also need a load strategy when something bad happens...
 | 
					
						
							|  |  |  | 	// 		...e.g. load up until the first error, or something like:
 | 
					
						
							|  |  |  | 	// 			while(!this.list(path, make)){
 | 
					
						
							|  |  |  | 	// 				path.pop()
 | 
					
						
							|  |  |  | 	// 			}
 | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 	list: function(path, make){ | 
					
						
							| 
									
										
										
										
											2015-05-25 20:02:47 +03:00
										 |  |  | 		path = path || this.path | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		var m = this.options.list | 
					
						
							| 
									
										
										
										
											2015-06-21 03:49:00 +03:00
										 |  |  | 		return m ? m.apply(this, arguments) : [] | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 20:37:32 +03:00
										 |  |  | 	// XXX need to get a container -- UI widget API....
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:57:47 +03:00
										 |  |  | 	// XXX paste does not work on IE yet...
 | 
					
						
							|  |  |  | 	// XXX handle copy...
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	__init__: function(parent, options){ | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 		var that = this | 
					
						
							| 
									
										
										
										
											2015-05-18 03:34:15 +03:00
										 |  |  | 		options = options || {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// merge options...
 | 
					
						
							|  |  |  | 		var opts = Object.create(this.options) | 
					
						
							|  |  |  | 		Object.keys(options).forEach(function(n){ opts[n] = options[n] }) | 
					
						
							|  |  |  | 		options = this.options = opts | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// build the dom...
 | 
					
						
							|  |  |  | 		var dom = this.dom = this.constructor.make(options) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 		// basic permanent interactions...
 | 
					
						
							|  |  |  | 		dom.find('.path') | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 			// NOTE: these are used for full-path editing and are defined
 | 
					
						
							|  |  |  | 			// 		here in contrast to other feature handlers as the
 | 
					
						
							|  |  |  | 			// 		'.path' element is long-lived and not rewritten 
 | 
					
						
							|  |  |  | 			// 		on .update(..)
 | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 			.dblclick(function(){ | 
					
						
							|  |  |  | 				that.startFullPathEdit() | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 			.keyup(function(){ | 
					
						
							|  |  |  | 				var e = $(this) | 
					
						
							| 
									
										
										
										
											2015-06-28 05:23:31 +03:00
										 |  |  | 				// clear the list on edit...
 | 
					
						
							| 
									
										
										
										
											2015-06-26 14:40:41 +03:00
										 |  |  | 				if(e.attr('contenteditable') && e.text() != dom.attr('orig-path')){ | 
					
						
							|  |  |  | 					dom.find('.list').empty() | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2015-06-28 05:23:31 +03:00
										 |  |  | 			/* XXX  | 
					
						
							|  |  |  | 			// Handle copy/paste...
 | 
					
						
							|  |  |  | 			//
 | 
					
						
							|  |  |  | 			// Make the whole widget support copy/paste of current path.
 | 
					
						
							|  |  |  | 			//
 | 
					
						
							|  |  |  | 			// NOTE: on nw.js mode this will handle this via keyboard 
 | 
					
						
							|  |  |  | 			// 		directly, skipping the events and their quirks...
 | 
					
						
							|  |  |  | 			//
 | 
					
						
							| 
									
										
										
										
											2015-06-26 15:57:47 +03:00
										 |  |  | 			// XXX does not work on IE yet...
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 			// XXX do we handle other types???
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:23:31 +03:00
										 |  |  | 			// 		...try and get the path of anything, including files, dirs, etc...
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 			// XXX seems not to work until we cycle any of the editable
 | 
					
						
							|  |  |  | 			// 		controls (filter/path), and then it still is on and 
 | 
					
						
							|  |  |  | 			// 		off...
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:23:31 +03:00
										 |  |  | 			// XXX does not work with ':not([contenteditable])' and kills
 | 
					
						
							|  |  |  | 			// 		copy/paste on editable fields without...
 | 
					
						
							|  |  |  | 			// XXX do we bother with these??
 | 
					
						
							|  |  |  | 			.on('paste', ':not([contenteditable])', function(){ | 
					
						
							| 
									
										
										
										
											2015-06-26 15:57:47 +03:00
										 |  |  | 				event.preventDefault() | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 				that.paste() | 
					
						
							| 
									
										
										
										
											2015-06-26 15:57:47 +03:00
										 |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2015-06-28 05:23:31 +03:00
										 |  |  | 			// XXX does not work...
 | 
					
						
							| 
									
										
										
										
											2015-06-27 02:34:52 +03:00
										 |  |  | 			.on('cut copy', function(){ | 
					
						
							|  |  |  | 				event.preventDefault() | 
					
						
							|  |  |  | 				that.copy() | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			*/ | 
					
						
							| 
									
										
										
										
											2015-06-26 03:07:58 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 		// add keyboard handler...
 | 
					
						
							|  |  |  | 		dom.keydown( | 
					
						
							|  |  |  | 			keyboard.makeKeyboardHandler( | 
					
						
							|  |  |  | 				this.keyboard, | 
					
						
							| 
									
										
										
										
											2015-05-18 03:34:15 +03:00
										 |  |  | 				options.logKeys, | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 				this)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// attach to parent...
 | 
					
						
							|  |  |  | 		if(parent != null){ | 
					
						
							|  |  |  | 			parent.append(dom) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// load the initial state...
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 		this.update(options.path || this.path || '/') | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 16:29:29 +03:00
										 |  |  | 		if(this.options.nonPropagatedEvents != null){ | 
					
						
							|  |  |  | 			this.on(this.options.nonPropagatedEvents.join(''),  | 
					
						
							|  |  |  | 				function(evt){ evt.stopPropagation() }) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 05:23:31 +03:00
										 |  |  | /* | 
					
						
							|  |  |  | // nw.js copy/paste handling...
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // XXX not sure if we actually need these...
 | 
					
						
							|  |  |  | if(NW){ | 
					
						
							|  |  |  | 	// override copy...
 | 
					
						
							|  |  |  | 	BrowserPrototype.keyboard.General.C = { | 
					
						
							|  |  |  | 		ctrl: 'copy!', | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	BrowserPrototype.keyboard.General.X = 'C' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// override paste...
 | 
					
						
							|  |  |  | 	BrowserPrototype.keyboard.General.V = { | 
					
						
							|  |  |  | 		ctrl: 'paste!', | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | var Browser =  | 
					
						
							| 
									
										
										
										
											2015-06-20 14:50:54 +03:00
										 |  |  | module.Browser =  | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | object.makeConstructor('Browser',  | 
					
						
							|  |  |  | 		BrowserClassPrototype,  | 
					
						
							|  |  |  | 		BrowserPrototype) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 05:45:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 18:09:37 +03:00
										 |  |  | // Flat list...
 | 
					
						
							| 
									
										
										
										
											2015-06-22 17:22:01 +03:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-06-22 18:09:37 +03:00
										 |  |  | // This expects a data option set with the following format:
 | 
					
						
							|  |  |  | // 	{
 | 
					
						
							|  |  |  | // 		<option-text>: <callback>,
 | 
					
						
							|  |  |  | // 		...
 | 
					
						
							|  |  |  | // 	}
 | 
					
						
							| 
									
										
										
										
											2015-06-24 18:21:49 +03:00
										 |  |  | //
 | 
					
						
							|  |  |  | // or:
 | 
					
						
							|  |  |  | // 	[
 | 
					
						
							|  |  |  | // 		<option-text>,
 | 
					
						
							|  |  |  | // 		...
 | 
					
						
							|  |  |  | // 	]
 | 
					
						
							| 
									
										
										
										
											2015-06-22 18:09:37 +03:00
										 |  |  | // 	
 | 
					
						
							|  |  |  | // NOTE: this essentially a different default configuration of Browser...
 | 
					
						
							|  |  |  | var ListPrototype = Object.create(BrowserPrototype) | 
					
						
							|  |  |  | ListPrototype.options = { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 02:02:37 +03:00
										 |  |  | 	fullPathEdit: false, | 
					
						
							| 
									
										
										
										
											2015-06-22 18:09:37 +03:00
										 |  |  | 	traversable: false, | 
					
						
							|  |  |  | 	flat: true, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list: function(path, make){ | 
					
						
							|  |  |  | 		var that = this | 
					
						
							| 
									
										
										
										
											2015-06-24 18:21:49 +03:00
										 |  |  | 		var data = this.options.data | 
					
						
							|  |  |  | 		var keys = data.constructor == Array ? data : Object.keys(data) | 
					
						
							|  |  |  | 		return keys | 
					
						
							| 
									
										
										
										
											2015-06-22 18:09:37 +03:00
										 |  |  | 			.map(function(k){ | 
					
						
							|  |  |  | 				var e = make(k) | 
					
						
							| 
									
										
										
										
											2015-06-24 18:21:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if(data !== keys){ | 
					
						
							|  |  |  | 					e.on('open', function(){  | 
					
						
							| 
									
										
										
										
											2015-06-22 18:09:37 +03:00
										 |  |  | 						return that.options.data[k].apply(this, arguments) | 
					
						
							|  |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2015-06-24 18:21:49 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-06-22 18:09:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				return k | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ListPrototype.options.__proto__ = BrowserPrototype.options | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var List =  | 
					
						
							|  |  |  | module.List =  | 
					
						
							|  |  |  | object.makeConstructor('List',  | 
					
						
							|  |  |  | 		BrowserClassPrototype,  | 
					
						
							|  |  |  | 		ListPrototype) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This is a shorthand for: new List(<elem>, { data: <list> })
 | 
					
						
							| 
									
										
										
										
											2015-06-22 17:22:01 +03:00
										 |  |  | var makeList =  | 
					
						
							|  |  |  | module.makeList = function(elem, list){ | 
					
						
							| 
									
										
										
										
											2015-06-22 18:09:37 +03:00
										 |  |  | 	return List(elem, { data: list }) | 
					
						
							| 
									
										
										
										
											2015-06-22 17:22:01 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // This is similar to List(..) but will parse paths in keys...
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-09-05 17:46:29 +03:00
										 |  |  | // Path grammar:
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 	PATH ::= [/]<dirs>				- simple traversable path
 | 
					
						
							|  |  |  | // 			| [/]<dirs>/<item>		- path with last item non-traversable
 | 
					
						
							|  |  |  | // 			| [/]<dirs>/*			- path to lister
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 	<dirs> ::= <item> 
 | 
					
						
							|  |  |  | // 			| <dirs>/<item>/
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 	<item> ::= <name>				- explicit path element 
 | 
					
						
							|  |  |  | // 			| <item>|<name>			- multiple path elements (a-la simlink)
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 	<name> ::= [^\|\\\/]*
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 	NOTE: <dirs> always ends with '/' or '\' and produces a set of 
 | 
					
						
							|  |  |  | // 		traversable items.
 | 
					
						
							|  |  |  | // 	NOTE: the last item is non-traversable iff:
 | 
					
						
							|  |  |  | // 		- it does not end with '/' or '\'
 | 
					
						
							|  |  |  | // 		- there is no other path defined where it is traversable
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // Format:
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | // 	{
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // 		// basic 'file' path...
 | 
					
						
							|  |  |  | // 		// NOTE: this path is non-traversable by default, but if a 
 | 
					
						
							|  |  |  | // 		//		sub-path handler is defined (e.g. 'dir/file/x') then this
 | 
					
						
							|  |  |  | // 		//		will be set traversable...
 | 
					
						
							|  |  |  | // 		'dir/file': function(evt, path){ .. },
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 		// file object at the tree root...
 | 
					
						
							|  |  |  | // 		// NOTE: the leading '/' is optional...
 | 
					
						
							|  |  |  | // 		'file': function(evt, path){ .. },
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 		// a directory handler is defined by path ending with '/', 
 | 
					
						
							|  |  |  | // 		// set traversable...
 | 
					
						
							|  |  |  | // 		'dir/dir/': function(evt, path){ .. },
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | // 		// add a file object to two dirs...
 | 
					
						
							|  |  |  | // 		'dir|other/other file': function(evt, path){ .. },
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | //		// path lister...
 | 
					
						
							|  |  |  | //		'dynamic/*': function(path, make){ .. }
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | // 	}
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // The above definition will be interpreted into the following tree:
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 	/
 | 
					
						
							|  |  |  | // 		dir/
 | 
					
						
							|  |  |  | // 			file
 | 
					
						
							|  |  |  | // 			dir/
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | // 			other file
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // 		file
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | // 		other/
 | 
					
						
							|  |  |  | // 			other file
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // 		dynamic/
 | 
					
						
							|  |  |  | // 			..
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Here the contents of the '/dynamic/' path are generated by the matching 
 | 
					
						
							|  |  |  | // lister for that pattern path...
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | // NOTE: in the A|B|C pattern, ALL of the alternatives will be created.
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // NOTE: there may be multiple matching patterns/listers or a given path
 | 
					
						
							|  |  |  | // 		the one used is the longest match.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Handler format:
 | 
					
						
							|  |  |  | // 	function(evt, path){ .. }
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // 		This function will be called on the 'open' event for the defined 
 | 
					
						
							|  |  |  | // 		item.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Lister format:
 | 
					
						
							|  |  |  | // 	function(path, make){ .. } -> list
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //		This function will get called on .update(..) of the matching path.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //		make(text, traversable) is a list item constructor.
 | 
					
						
							|  |  |  | //		for more docs see: Browser.list(..)
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:57:05 +03:00
										 |  |  | // NOTE: listers take precedence over explicit path definitions, thus 
 | 
					
						
							|  |  |  | // 		if a custom lister pattern intersects with a normal path the path
 | 
					
						
							|  |  |  | // 		will be ignored and the lister called.
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // NOTE: currently only trailing '*' are supported.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // XXX add support for '*' and '**' glob patterns...
 | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | var PathListPrototype = Object.create(BrowserPrototype) | 
					
						
							|  |  |  | PathListPrototype.options = { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 12:41:44 +03:00
										 |  |  | 	fullPathEdit: true, | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 	traversable: true, | 
					
						
							|  |  |  | 	flat: false, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list: function(path, make){ | 
					
						
							|  |  |  | 		var that = this | 
					
						
							|  |  |  | 		var data = this.options.data | 
					
						
							|  |  |  | 		var keys = data.constructor == Array ? data : Object.keys(data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var visited = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | 		// match path elements accounting for patterns...
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// Supported patterns:
 | 
					
						
							|  |  |  | 		// 	A		- matches A exactly
 | 
					
						
							|  |  |  | 		// 	A|B		- matches either A or B
 | 
					
						
							|  |  |  | 		var match = function(a, path){ | 
					
						
							| 
									
										
										
										
											2015-09-05 17:46:29 +03:00
										 |  |  | 			// NOTE: might be good to make this recursive when expanding
 | 
					
						
							|  |  |  | 			// 		pattern support...
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | 			return a | 
					
						
							|  |  |  | 					.split('|') | 
					
						
							|  |  |  | 					.filter(function(e){  | 
					
						
							|  |  |  | 						return e == path | 
					
						
							|  |  |  | 					}).length > 0 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 		// get the '*' listers...
 | 
					
						
							|  |  |  | 		var lister = keys | 
					
						
							|  |  |  | 			.filter(function(k){ return k.trim().slice(-1) == '*' }) | 
					
						
							|  |  |  | 			.filter(function(k){ | 
					
						
							| 
									
										
										
										
											2015-09-05 02:52:51 +03:00
										 |  |  | 				k = k.split(/[\\\/]+/) | 
					
						
							|  |  |  | 					// remove the trailing '*'...
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 					.slice(0, -1) | 
					
						
							| 
									
										
										
										
											2015-09-05 02:52:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// do the match...
 | 
					
						
							|  |  |  | 				return k.length <= path.length  | 
					
						
							|  |  |  | 					&& k.filter(function(e, i){  | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | 							return e != '*' && !match(e, path[i]) | 
					
						
							| 
									
										
										
										
											2015-09-05 02:52:51 +03:00
										 |  |  | 						}).length == 0 }) | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 			.sort(function(a, b){ return a.length - b.length}) | 
					
						
							|  |  |  | 			.pop() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// use the custom lister (defined by trailing '*')...
 | 
					
						
							|  |  |  | 		if(data !== keys && lister){ | 
					
						
							|  |  |  | 			return data[lister].call(this, '/' + path.join('/'), make) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// list via provided paths...
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			return keys | 
					
						
							|  |  |  | 				.map(function(k){ | 
					
						
							|  |  |  | 					var kp = k.split(/[\\\/]+/g) | 
					
						
							|  |  |  | 					kp[0] == '' && kp.shift() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// see if we have a star...
 | 
					
						
							|  |  |  | 					var star = kp.slice(-1)[0] == '*' | 
					
						
							|  |  |  | 					star && kp.pop() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// get and check current path, continue if relevant...
 | 
					
						
							|  |  |  | 					var p = kp.splice(0, path.length) | 
					
						
							|  |  |  | 					if(kp.length == 0  | 
					
						
							|  |  |  | 							|| p.length < path.length | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | 							|| p.filter(function(e, i){ return !match(e, path[i]) }).length > 0){ | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 						return false | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 					// get current path element if one exists and we did not create it already...
 | 
					
						
							|  |  |  | 					cur = kp.shift() | 
					
						
							|  |  |  | 					if(cur == undefined){ | 
					
						
							|  |  |  | 						return false | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | 					cur.split('|').forEach(function(cur){ | 
					
						
							|  |  |  | 						if(visited.indexOf(cur) >= 0){ | 
					
						
							|  |  |  | 							// set element to traversable...
 | 
					
						
							|  |  |  | 							if(kp.length > 0){ | 
					
						
							|  |  |  | 								that.filter(cur).removeClass('not-traversable') | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							return false | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | 						visited.push(cur) | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | 						// build the element....
 | 
					
						
							|  |  |  | 						var e = make(cur, star || kp.length > 0) | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-05 16:07:08 +03:00
										 |  |  | 						// setup handlers...
 | 
					
						
							|  |  |  | 						if(!star && data !== keys && kp.length == 0){ | 
					
						
							|  |  |  | 							e.on('open', function(){  | 
					
						
							|  |  |  | 								return that.options.data[k].apply(this, arguments) | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | 					return cur | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 				.filter(function(e){ return e !== false }) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-08-29 21:41:46 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | PathListPrototype.options.__proto__ = BrowserPrototype.options | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var PathList =  | 
					
						
							|  |  |  | module.PathList =  | 
					
						
							|  |  |  | object.makeConstructor('PathList',  | 
					
						
							|  |  |  | 		BrowserClassPrototype,  | 
					
						
							|  |  |  | 		PathListPrototype) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var makePathList =  | 
					
						
							|  |  |  | module.makePathList = function(elem, list){ | 
					
						
							|  |  |  | 	return PathList(elem, { data: list }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 16:45:20 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ | 
					
						
							| 
									
										
										
										
											2015-06-20 14:50:54 +03:00
										 |  |  | return module }) |