| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-08-21 02:19:24 +03:00
										 |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) | 
					
						
							|  |  |  | (function(require){ var module={} // make module AMD/node compatible...
 | 
					
						
							| 
									
										
										
										
											2016-08-20 22:49:36 +03:00
										 |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var actions = require('lib/actions') | 
					
						
							|  |  |  | var features = require('lib/features') | 
					
						
							| 
									
										
										
										
											2016-11-28 02:25:39 +03:00
										 |  |  | var toggler = require('lib/toggler') | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var core = require('features/core') | 
					
						
							| 
									
										
										
										
											2016-04-30 03:38:52 +03:00
										 |  |  | var widgets = require('features/ui-widgets') | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var overlay = require('lib/widget/overlay') | 
					
						
							|  |  |  | var browse = require('lib/widget/browse') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | // url history...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var URLHistoryActions = actions.Actions({ | 
					
						
							|  |  |  | 	config: { | 
					
						
							|  |  |  | 		'url-history-push-up-on-open': false, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// values:
 | 
					
						
							|  |  |  | 		// 	-1		- no limit.
 | 
					
						
							|  |  |  | 		// 	0		- disabled
 | 
					
						
							|  |  |  | 		// 	1+		- length of history
 | 
					
						
							| 
									
										
										
										
											2017-10-17 03:24:08 +03:00
										 |  |  | 		//
 | 
					
						
							|  |  |  | 		// NOTE: this does not account for pinned items.
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		'url-history-length': 100, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	__url_history: null, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Format:
 | 
					
						
							|  |  |  | 	// 	{
 | 
					
						
							|  |  |  | 	// 		url: {
 | 
					
						
							|  |  |  | 	// 			open: <action-name> | <function>,
 | 
					
						
							|  |  |  | 	// 			check: <action-name> | <function>,
 | 
					
						
							|  |  |  | 	// 		},
 | 
					
						
							|  |  |  | 	// 		...
 | 
					
						
							|  |  |  | 	// 	}
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 	// NOTE: last opened url is last in object, i.e. the keys are in 
 | 
					
						
							|  |  |  | 	// 		reverse order...
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	// NOTE: though functions are supported they are not recommended as
 | 
					
						
							|  |  |  | 	// 		we can not stringify them to JSON...
 | 
					
						
							|  |  |  | 	get url_history(){ | 
					
						
							| 
									
										
										
										
											2017-01-02 01:23:33 +03:00
										 |  |  | 		return this.hasOwnProperty('__url_history') ? this.__url_history : undefined }, | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	set url_history(value){ | 
					
						
							| 
									
										
										
										
											2017-01-02 01:23:33 +03:00
										 |  |  | 		this.__url_history = value }, | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-01 18:09:29 +03:00
										 |  |  | 	// NOTE: this is created on the fly as a convenience, editing this 
 | 
					
						
							|  |  |  | 	// 		will have no effect...
 | 
					
						
							|  |  |  | 	get url_history_pinned(){ | 
					
						
							|  |  |  | 		var url_history = this.url_history | 
					
						
							|  |  |  | 		return Object.keys(url_history) | 
					
						
							|  |  |  | 			.reduce(function(res, k){  | 
					
						
							|  |  |  | 				if(url_history[k].pinned){ | 
					
						
							|  |  |  | 					res[k] = url_history[k] | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return res  | 
					
						
							|  |  |  | 			}, {}) }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	clone: [function(full){ | 
					
						
							|  |  |  | 		return function(res){ | 
					
						
							|  |  |  | 			res.url_history = null | 
					
						
							|  |  |  | 			if(full && this.url_history){ | 
					
						
							|  |  |  | 				res.url_history = JSON.parse(JSON.stringify(this.url_history)) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 	// NOTE: this updates .url_history in-place...
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	setTopURLHistory: ['- History/', | 
					
						
							|  |  |  | 		function(url){ | 
					
						
							|  |  |  | 			var data = this.url_history[url] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(data == null){ | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			delete this.url_history[url] | 
					
						
							|  |  |  | 			this.url_history[url] = data | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 	// NOTE: this will overwrite .url_history object...
 | 
					
						
							|  |  |  | 	// XXX should this be in-place or overwrite by default???
 | 
					
						
							|  |  |  | 	sortURLHistory: ['- History/', | 
					
						
							|  |  |  | 		function(order, in_place){ | 
					
						
							|  |  |  | 			var that = this | 
					
						
							|  |  |  | 			var data = this.url_history | 
					
						
							|  |  |  | 			var ordered = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(in_place){ | 
					
						
							|  |  |  | 				order | 
					
						
							|  |  |  | 					.unique() | 
					
						
							|  |  |  | 					.reverse() | 
					
						
							|  |  |  | 					.forEach(function(url){ | 
					
						
							|  |  |  | 						that.setTopURLHistory(url) }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				order | 
					
						
							|  |  |  | 					.concat( | 
					
						
							|  |  |  | 						Object.keys(data) | 
					
						
							|  |  |  | 							.reverse()) | 
					
						
							|  |  |  | 					.unique() | 
					
						
							|  |  |  | 					.reverse() | 
					
						
							|  |  |  | 					.forEach(function(url){ | 
					
						
							|  |  |  | 						url in data | 
					
						
							|  |  |  | 							&& (ordered[url] = data[url]) }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// sanity check...
 | 
					
						
							|  |  |  | 				if(Object.keys(data).length != Object.keys(ordered).length){ | 
					
						
							|  |  |  | 					console.error('Something went wrong with sort:', ordered) | 
					
						
							|  |  |  | 					return | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				this.url_history = ordered | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-11-26 20:42:47 +03:00
										 |  |  | 	// NOTE: if clear is not true then this will update a history item 
 | 
					
						
							|  |  |  | 	// 		rather than fully rewriting it...
 | 
					
						
							| 
									
										
										
										
											2017-10-17 03:24:08 +03:00
										 |  |  | 	// NOTE: this will not auto-remove pinned items if the length of 
 | 
					
						
							|  |  |  | 	// 		history is more than allowed...
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	pushURLToHistory: ['- History/', | 
					
						
							| 
									
										
										
										
											2016-11-26 20:42:47 +03:00
										 |  |  | 		function(url, open, check, clear){ | 
					
						
							| 
									
										
										
										
											2018-09-19 15:54:21 +03:00
										 |  |  | 			var that = this | 
					
						
							| 
									
										
										
										
											2016-12-11 04:54:28 +03:00
										 |  |  | 			url = url || this.location.path | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 			var l = this.config['url-history-length'] || -1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-21 16:42:49 +03:00
										 |  |  | 			var logger = this.logger  | 
					
						
							|  |  |  | 				&& this.logger.push('History') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 			if(l == 0){ | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			this.url_history = this.url_history || {} | 
					
						
							| 
									
										
										
										
											2016-11-26 20:42:47 +03:00
										 |  |  | 			var item = !clear ? (this.url_history[url] || {}) : {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			open = item.open = open || this.location.method | 
					
						
							| 
									
										
										
										
											2018-01-20 03:55:28 +03:00
										 |  |  | 			check = item.check = check || this.location.check || 'checkPath' | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// remove the old value...
 | 
					
						
							|  |  |  | 			if(url in this.url_history && this.config['url-history-push-up-on-open']){ | 
					
						
							|  |  |  | 				delete this.url_history[url] | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// push url to history...
 | 
					
						
							| 
									
										
										
										
											2016-11-26 20:42:47 +03:00
										 |  |  | 			this.url_history[url] = item | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// update history length...
 | 
					
						
							| 
									
										
										
										
											2018-09-19 15:54:21 +03:00
										 |  |  | 			var to_remove = Object.keys(this.url_history) | 
					
						
							|  |  |  | 				// we will not remove pinned items...
 | 
					
						
							|  |  |  | 				.filter(function(e){ | 
					
						
							| 
									
										
										
										
											2018-09-20 05:25:15 +03:00
										 |  |  | 					// NOTE: .pinned can be 0 so we can't just use 
 | 
					
						
							|  |  |  | 					// 		that.url_history[e].pinned as a test...
 | 
					
						
							| 
									
										
										
										
											2018-09-19 15:54:21 +03:00
										 |  |  | 					return that.url_history[e].pinned == null }) | 
					
						
							|  |  |  | 			// we clear the head of the list -- first/oldest urls added...
 | 
					
						
							|  |  |  | 			to_remove.reverse() | 
					
						
							|  |  |  | 			// do the actual removal...
 | 
					
						
							|  |  |  | 			to_remove | 
					
						
							|  |  |  | 				.slice(l) | 
					
						
							|  |  |  | 				.forEach(function(e){ | 
					
						
							| 
									
										
										
										
											2018-09-22 20:59:52 +03:00
										 |  |  | 					// XXX not sure if this is needed here...
 | 
					
						
							| 
									
										
										
										
											2018-09-21 16:42:49 +03:00
										 |  |  | 					logger | 
					
						
							| 
									
										
										
										
											2018-09-22 20:59:52 +03:00
										 |  |  | 						&& logger.emit(`Auto-removing URL from history: "${e}"`) | 
					
						
							| 
									
										
										
										
											2018-09-19 15:54:21 +03:00
										 |  |  | 					that.dropURLFromHistory(e) }) | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		}], | 
					
						
							|  |  |  | 	// NOTE: url can be an index, 0 being the last url added to history;
 | 
					
						
							|  |  |  | 	// 		negative values are also supported.
 | 
					
						
							|  |  |  | 	dropURLFromHistory: ['- History/',  | 
					
						
							|  |  |  | 		function(url){ | 
					
						
							|  |  |  | 			this.url_history = this.url_history || {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			url = typeof(url) == typeof(123) ?  | 
					
						
							|  |  |  | 				Object.keys(this.url_history).reverse().slice(url)[0] | 
					
						
							|  |  |  | 				: url | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(url){ | 
					
						
							|  |  |  | 				delete this.url_history[url] | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 	checkURLFromHistory: ['- History/', | 
					
						
							|  |  |  | 		function(url){ | 
					
						
							|  |  |  | 			this.url_history = this.url_history || {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			url = typeof(url) == typeof(123) ?  | 
					
						
							|  |  |  | 				Object.keys(this.url_history).reverse().slice(url)[0] | 
					
						
							|  |  |  | 				: url | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// if we have a check action then use it...
 | 
					
						
							|  |  |  | 			if(url && this.url_history[url] && this.url_history[url].check){ | 
					
						
							|  |  |  | 				var check = this.url_history[url].check | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 03:55:28 +03:00
										 |  |  | 				if(check === true || check === false){ | 
					
						
							|  |  |  | 					return check | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				} else if(typeof(check) == typeof('str')){ | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 					return this[check](url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					return check(url) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// no way to check so we do not know...
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2016-02-17 20:10:31 +03:00
										 |  |  | 				return null | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 	pinnedURLOrder: ['- History/', | 
					
						
							|  |  |  | 		core.doc`Get/set history pin order
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Get pin order... | 
					
						
							| 
									
										
										
										
											2017-10-17 03:24:08 +03:00
										 |  |  | 			.pinnnedURLOrder(<url>) | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				-> order | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Set pin order... | 
					
						
							| 
									
										
										
										
											2017-10-17 03:24:08 +03:00
										 |  |  | 			.pinnnedURLOrder(<url>, <order>) | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				-> this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Set pin order to 'auto'... | 
					
						
							| 
									
										
										
										
											2017-10-17 03:24:08 +03:00
										 |  |  | 			.pinnnedURLOrder(<url>, 'auto') | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				-> this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Auto-ordered pins are sorted in the same order as .url_history | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		NOTE: this will not reset the pin, use .toggleURLPinned(..) for that | 
					
						
							|  |  |  | 		`,
 | 
					
						
							|  |  |  | 		function(url, order){ | 
					
						
							|  |  |  | 			var e = this.url_history[url] | 
					
						
							|  |  |  | 			// get...
 | 
					
						
							|  |  |  | 			if(order == null){ | 
					
						
							|  |  |  | 				return e.pinned === true ? 'auto' | 
					
						
							|  |  |  | 					: 'pinned' in e ? e.pinned | 
					
						
							|  |  |  | 					: null | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// set...
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				e.pinned = order == 'auto' ? true : order | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-11-28 02:25:39 +03:00
										 |  |  | 	toggleURLPinned: ['History/', | 
					
						
							|  |  |  | 		toggler.Toggler( | 
					
						
							|  |  |  | 			function(){ return this.location.path }, | 
					
						
							|  |  |  | 			function(url, action){ | 
					
						
							|  |  |  | 				var e = this.url_history[url] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// get state...
 | 
					
						
							|  |  |  | 				if(action == null){ | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 					return (e && e.pinned != null) ? 'on' : 'off' | 
					
						
							| 
									
										
										
										
											2016-11-28 02:25:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// change state -> 'on'...
 | 
					
						
							|  |  |  | 				} else if(action == 'on'){ | 
					
						
							|  |  |  | 					e.pinned = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// change state -> 'off'...
 | 
					
						
							|  |  |  | 				} else if(action == 'off'){ | 
					
						
							|  |  |  | 					delete e.pinned | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			},  | 
					
						
							|  |  |  | 			['off', 'on'])], | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	openURLFromHistory: ['- History/', | 
					
						
							|  |  |  | 		function(url, open){ | 
					
						
							|  |  |  | 			this.url_history = this.url_history || {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			url = typeof(url) == typeof(123) ?  | 
					
						
							|  |  |  | 				Object.keys(this.url_history).reverse().slice(url)[0] | 
					
						
							|  |  |  | 				: url | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(url && !open && this.url_history[url] && this.url_history[url].open){ | 
					
						
							|  |  |  | 				open = this.url_history[url].open | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(url && open){ | 
					
						
							|  |  |  | 				if(open instanceof Function){ | 
					
						
							|  |  |  | 					return open(url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					return this[open](url) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2018-11-29 13:27:59 +03:00
										 |  |  | 	openPreviousLoadedURL: ['History/Load previously loaded url', | 
					
						
							|  |  |  | 		core.doc`
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			NOTE: this will only work if .config['url-history-last-loaded'] is  | 
					
						
							|  |  |  | 				present in .url_history, otherwise this is a no-op. | 
					
						
							|  |  |  | 			`,
 | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			var last = this.config['url-history-last-loaded'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			last in this.url_history | 
					
						
							|  |  |  | 				&& this.openURLFromHistory(last) | 
					
						
							|  |  |  | 		}],	 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	clearURLHistory: ['History/',  | 
					
						
							|  |  |  | 		function(){ this.url_history = null }], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var URLHistory =  | 
					
						
							|  |  |  | module.URLHistory = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'url-history', | 
					
						
							|  |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'location', | 
					
						
							|  |  |  | 	], | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 	suggested: [ | 
					
						
							|  |  |  | 		'ui-url-history', | 
					
						
							|  |  |  | 		'url-history-local-storage', | 
					
						
							|  |  |  | 		'url-history-fs-writer', | 
					
						
							|  |  |  | 	], | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	actions: URLHistoryActions, | 
					
						
							| 
									
										
										
										
											2018-11-29 13:27:59 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		// maintain .config['url-history-last-loaded']
 | 
					
						
							|  |  |  | 		['load.pre', | 
					
						
							|  |  |  | 			function(){ | 
					
						
							|  |  |  | 				var prev = (this.location && this.location.path) ? | 
					
						
							|  |  |  | 					this.location.path  | 
					
						
							|  |  |  | 					: null | 
					
						
							|  |  |  | 				return prev  | 
					
						
							|  |  |  | 					&& function(){ | 
					
						
							|  |  |  | 						prev != this.config['url-history-last-loaded']  | 
					
						
							| 
									
										
										
										
											2018-12-05 14:47:06 +03:00
										 |  |  | 							&& prev != this.location.path | 
					
						
							| 
									
										
										
										
											2018-11-29 13:27:59 +03:00
										 |  |  | 							&& (this.config['url-history-last-loaded'] = prev) } | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 	], | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX should this be responsible for saving and loading of .location???
 | 
					
						
							|  |  |  | // 		...on one hand it's part of the history, on the other it's part 
 | 
					
						
							|  |  |  | // 		of file loader...
 | 
					
						
							|  |  |  | var URLHistoryLocalStorageActions = actions.Actions({ | 
					
						
							|  |  |  | 	config: { | 
					
						
							|  |  |  | 		'url-history-local-storage-key': 'url-history', | 
					
						
							|  |  |  | 		'url-history-loaded-local-storage-key': 'url-history-loaded', | 
					
						
							| 
									
										
										
										
											2015-12-29 01:02:57 +03:00
										 |  |  | 		'url-history-load-current': true, | 
					
						
							| 
									
										
										
										
											2018-11-29 13:27:59 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		'url-history-last-loaded': null, | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	__url_history: null, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// load url history...
 | 
					
						
							|  |  |  | 	get url_history(){ | 
					
						
							|  |  |  | 		// get the attr value...
 | 
					
						
							|  |  |  | 		if(this.hasOwnProperty('__url_history') && this.__url_history){ | 
					
						
							|  |  |  | 			return this.__url_history | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var key = this.config['url-history-local-storage-key'] | 
					
						
							|  |  |  | 		if(key){ | 
					
						
							|  |  |  | 			// get the storage value...
 | 
					
						
							|  |  |  | 			// if not local __url_history and we are configured, load from storage...
 | 
					
						
							|  |  |  | 			if(this.config && key){ | 
					
						
							|  |  |  | 				var history = localStorage[key] | 
					
						
							|  |  |  | 				if(history){ | 
					
						
							|  |  |  | 					try{ | 
					
						
							|  |  |  | 						this.__url_history = JSON.parse(history) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					} catch(e) { | 
					
						
							|  |  |  | 						delete localStorage[key] | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return this.hasOwnProperty('__url_history') ? this.__url_history : null | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set url_history(value){ | 
					
						
							|  |  |  | 		this.__url_history = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var key = this.config['url-history-local-storage-key'] | 
					
						
							|  |  |  | 		if(key){ | 
					
						
							|  |  |  | 			localStorage[key] = JSON.stringify(value)  | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Disable localStorage in child...
 | 
					
						
							|  |  |  | 	clone: [function(){ | 
					
						
							|  |  |  | 		return function(res){ | 
					
						
							|  |  |  | 			res.config['url-history-local-storage-key'] = null | 
					
						
							|  |  |  | 			res.config['url-history-loaded-local-storage-key'] = null | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-25 03:33:28 +03:00
										 |  |  | 	storeURLHistory: ['History/', | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		function(){ | 
					
						
							|  |  |  | 			var history = this.config['url-history-local-storage-key'] | 
					
						
							|  |  |  | 			if(history != null){ | 
					
						
							|  |  |  | 				localStorage[history] =  | 
					
						
							|  |  |  | 					JSON.stringify(this.url_history)  | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-25 03:33:28 +03:00
										 |  |  | 			this.storeLocation() | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2017-04-25 03:33:28 +03:00
										 |  |  | 	storeLocation: ['History/', | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		function(){ | 
					
						
							|  |  |  | 			var loaded = this.config['url-history-loaded-local-storage-key'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(loaded != null){ | 
					
						
							|  |  |  | 				localStorage[loaded] = JSON.stringify(this.location || {}) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 	loadLastSavedBasePath: ['- History/', | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			var loaded = this.config['url-history-loaded-local-storage-key'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(loaded && localStorage[loaded]){ | 
					
						
							|  |  |  | 				var l = JSON.parse(localStorage[loaded]) | 
					
						
							| 
									
										
										
										
											2015-12-29 01:02:57 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if(l.current != null && this.config['url-history-load-current']){ | 
					
						
							|  |  |  | 					this.one('load', function(){ | 
					
						
							|  |  |  | 						this.current = l.current | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 				this.openURLFromHistory(l.path, l.method) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				this.openURLFromHistory(0) | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-11-29 13:27:59 +03:00
										 |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var URLHistoryLocalStorage =  | 
					
						
							|  |  |  | module.URLHistoryLocalStorage = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'url-history-local-storage', | 
					
						
							|  |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'ui', | 
					
						
							|  |  |  | 		'url-history', | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 10:37:21 +03:00
										 |  |  | 	isApplicable: function(){  | 
					
						
							|  |  |  | 		return typeof(localStorage) != 'undefined'  | 
					
						
							|  |  |  | 			&& localStorage != null }, | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	actions: URLHistoryLocalStorageActions, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// NOTE: loading is done by the .url_history prop...
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							| 
									
										
										
										
											2017-01-26 07:01:20 +03:00
										 |  |  | 		['ready', | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 			function(){ this.loadLastSavedBasePath() }],  | 
					
						
							| 
									
										
										
										
											2017-01-26 07:01:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		['stop.pre', | 
					
						
							| 
									
										
										
										
											2017-04-25 03:33:28 +03:00
										 |  |  | 			function(){ this.storeURLHistory() }],  | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// save base_path...
 | 
					
						
							| 
									
										
										
										
											2015-12-29 01:02:57 +03:00
										 |  |  | 		['load',  | 
					
						
							| 
									
										
										
										
											2017-04-25 03:33:28 +03:00
										 |  |  | 			function(){ this.location && this.location.path && this.storeLocation() }], | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// save...
 | 
					
						
							|  |  |  | 		['pushURLToHistory dropURLFromHistory setTopURLHistory',  | 
					
						
							|  |  |  | 			function(){  | 
					
						
							| 
									
										
										
										
											2017-04-25 03:33:28 +03:00
										 |  |  | 				this.storeURLHistory() | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 			}], | 
					
						
							|  |  |  | 		// clear...
 | 
					
						
							|  |  |  | 		['clearURLHistory.pre', | 
					
						
							|  |  |  | 			function(){ | 
					
						
							|  |  |  | 				delete this.__url_history | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var history = this.config['url-history-local-storage-key'] | 
					
						
							|  |  |  | 				if(history){ | 
					
						
							|  |  |  | 					delete localStorage[history] | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var loaded = this.config['url-history-loaded-local-storage-key'] | 
					
						
							|  |  |  | 				if(loaded){ | 
					
						
							|  |  |  | 					delete localStorage[loaded] | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 18:43:29 +03:00
										 |  |  | // XXX
 | 
					
						
							|  |  |  | var URLHistoryFSWriter =  | 
					
						
							|  |  |  | module.URLHistoryFSWriter = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'url-history-fs-writer', | 
					
						
							|  |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'fs-writer', | 
					
						
							|  |  |  | 		'url-history-local-storage', | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config: { | 
					
						
							| 
									
										
										
										
											2016-03-12 02:16:32 +03:00
										 |  |  | 		// XXX should we add a toggler action to toggle this?
 | 
					
						
							| 
									
										
										
										
											2016-03-08 18:43:29 +03:00
										 |  |  | 		'url-history-push-to-top-on-save': false, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		['saveIndex', | 
					
						
							| 
									
										
										
										
											2016-06-04 20:50:37 +03:00
										 |  |  | 			function(res){  | 
					
						
							|  |  |  | 				var that = this | 
					
						
							|  |  |  | 				res.then(function(l){ | 
					
						
							|  |  |  | 					// push saved to top...
 | 
					
						
							|  |  |  | 					if(that.config['url-history-push-to-top-on-save']){ | 
					
						
							|  |  |  | 						that.pushURLToHistory(l.path, l.method) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// update...
 | 
					
						
							| 
									
										
										
										
											2016-03-08 18:43:29 +03:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2016-06-04 20:50:37 +03:00
										 |  |  | 						var e = that.url_history[l.path] | 
					
						
							|  |  |  | 						if(e != null){ | 
					
						
							|  |  |  | 							e.open = l.method | 
					
						
							| 
									
										
										
										
											2017-04-25 03:33:28 +03:00
										 |  |  | 							that.storeURLHistory() | 
					
						
							| 
									
										
										
										
											2016-06-04 20:50:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							that.pushURLToHistory(l.path, l.method) | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2016-03-08 18:43:29 +03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-06-04 20:50:37 +03:00
										 |  |  | 				}) | 
					
						
							| 
									
										
										
										
											2016-03-08 18:43:29 +03:00
										 |  |  | 			}],  | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var URLHistoryUIActions = actions.Actions({ | 
					
						
							|  |  |  | 	config: { | 
					
						
							| 
									
										
										
										
											2017-01-04 05:15:56 +03:00
										 |  |  | 		// If true pushing the pin item button will also focus the item
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// NOTE: Both settings have their pluses and minuses:
 | 
					
						
							|  |  |  | 		// 		enabled (true)
 | 
					
						
							|  |  |  | 		// 			+ will keep the item on screen
 | 
					
						
							|  |  |  | 		// 			- will lose context
 | 
					
						
							|  |  |  | 		// 		disabled (false)
 | 
					
						
							|  |  |  | 		// 			+ will keep context
 | 
					
						
							|  |  |  | 		// 			- will lose the item from view if list is long
 | 
					
						
							|  |  |  | 		'url-history-focus-on-pin': false, | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-01-04 16:25:00 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 	// XXX add option to force full update on dialog.update() (???)
 | 
					
						
							|  |  |  | 	listURLHistory: ['History|File/Location history...', | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 		widgets.makeUIDialog(function(){ | 
					
						
							|  |  |  | 			var that = this | 
					
						
							|  |  |  | 			var data | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 			var orig_pins | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 			var cur = this.location.path | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 			// NOTE: if doing intermediate/live saves this would need to
 | 
					
						
							|  |  |  | 			//		be set to false on state update...
 | 
					
						
							|  |  |  | 			var state_saved = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:59:16 +03:00
										 |  |  | 			var to_sort = [] | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 			var to_remove = [] | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 			// cached fs state...
 | 
					
						
							|  |  |  | 			var fs_state = {} | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 			// NOTE: this would require the dialog to be updated if it's
 | 
					
						
							|  |  |  | 			// 		not closed...
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 			var save = function(){ | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				if(state_saved){ | 
					
						
							|  |  |  | 					return | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				state_saved = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var pins = data.pins | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// remove items...
 | 
					
						
							|  |  |  | 				to_remove.forEach(function(e){ | 
					
						
							|  |  |  | 					that.dropURLFromHistory(e) | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 					// pins...
 | 
					
						
							|  |  |  | 					var i = pins.indexOf(e) | 
					
						
							|  |  |  | 					i >= 0 | 
					
						
							|  |  |  | 						&& pins.splice(i, 1) | 
					
						
							| 
									
										
										
										
											2017-02-08 23:03:00 +03:00
										 |  |  | 					// urls to be sorted...
 | 
					
						
							|  |  |  | 					i = to_sort.indexOf(e) | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 					i >= 0 | 
					
						
							| 
									
										
										
										
											2017-02-08 23:03:00 +03:00
										 |  |  | 						&& to_sort.splice(i, 1) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 				}) | 
					
						
							|  |  |  | 				to_remove = [] | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// sort history...
 | 
					
						
							| 
									
										
										
										
											2017-02-09 02:11:28 +03:00
										 |  |  | 				that.sortURLHistory(to_sort, true) | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				// toggle pins...
 | 
					
						
							|  |  |  | 				pins | 
					
						
							|  |  |  | 					.concat(orig_pins || []) | 
					
						
							|  |  |  | 					.unique() | 
					
						
							|  |  |  | 					.forEach(function(p){ | 
					
						
							|  |  |  | 						pins.indexOf(p) < 0 		 | 
					
						
							|  |  |  | 							&& that.toggleURLPinned(p, 'off') | 
					
						
							|  |  |  | 						orig_pins.indexOf(p) < 0 		 | 
					
						
							|  |  |  | 							&& that.toggleURLPinned(p, 'on') | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				// sort pins...
 | 
					
						
							|  |  |  | 				pins | 
					
						
							|  |  |  | 					.forEach(function(p, i){ | 
					
						
							|  |  |  | 						that.pinnedURLOrder(p, i) }) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			var makeHistoryList = function(fs_state){ | 
					
						
							|  |  |  | 				fs_state = fs_state || {} | 
					
						
							|  |  |  | 				var history = Object.keys(that.url_history).reverse() | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				var pinned_auto = [] | 
					
						
							|  |  |  | 				var pinned_sorted = [] | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				var list = history  | 
					
						
							|  |  |  | 					// NOTE: this might get a little slow for 
 | 
					
						
							|  |  |  | 					// 		very large sets...
 | 
					
						
							|  |  |  | 					.map(function(p){ | 
					
						
							|  |  |  | 						// pinned items...
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 						var pin = that.pinnedURLOrder(p) | 
					
						
							|  |  |  | 						pin == 'auto' ? pinned_auto.push(p) | 
					
						
							|  |  |  | 							// prepare for sort...
 | 
					
						
							|  |  |  | 							: pin != null ? pinned_sorted.push([p, pin]) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 							: null | 
					
						
							|  |  |  | 						return p | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				// sort pins...
 | 
					
						
							|  |  |  | 				pinned_sorted = pinned_sorted | 
					
						
							|  |  |  | 					.sort(function(a, b){ return a[1] - b[1] }) | 
					
						
							|  |  |  | 					.map(function(e){ return e[0] }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 				return { | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 					urls: list, | 
					
						
							|  |  |  | 					pins: pinned_sorted.concat(pinned_auto), | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			var makeDisabledChecker = function(fs_state){ | 
					
						
							|  |  |  | 				return function(url){ | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 					// see of we need a full refresh or use the last fs_state...
 | 
					
						
							|  |  |  | 					return url in fs_state ? | 
					
						
							|  |  |  | 						fs_state[url] | 
					
						
							|  |  |  | 						: (fs_state[url] = !that.checkURLFromHistory(url)) } } | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			var dialog = browse.makeLister(null, function(path, make){ | 
					
						
							|  |  |  | 				// live update...
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				// XXX add option to force full update???
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 				data = data == null ? makeHistoryList(fs_state) : data | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				orig_pins = orig_pins == null ? data.pins.slice() : orig_pins | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				// special case: empty list...
 | 
					
						
							|  |  |  | 				if(data.urls.length == 0){ | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 					make.Action('No history...', {disabled: true}) | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 					return | 
					
						
							|  |  |  | 				}  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				make.EditablePinnedList(data.urls, data.pins, {  | 
					
						
							|  |  |  | 					list_id: 'history', | 
					
						
							|  |  |  | 					new_item: false, | 
					
						
							|  |  |  | 					pins_sortable: true, | 
					
						
							|  |  |  | 					isItemDisabled: makeDisabledChecker(fs_state), | 
					
						
							|  |  |  | 					to_remove: to_remove, | 
					
						
							|  |  |  | 					buttons: [ | 
					
						
							|  |  |  | 						// open...
 | 
					
						
							|  |  |  | 						['<span class="show-on-hover">↗</span>',  | 
					
						
							|  |  |  | 							function(p){ dialog.browsePath(p) }], | 
					
						
							|  |  |  | 						['♦', 'TO_TOP'], | 
					
						
							|  |  |  | 						'PIN', | 
					
						
							|  |  |  | 						'REMOVE', | 
					
						
							|  |  |  | 					], | 
					
						
							|  |  |  | 				}) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 				make | 
					
						
							|  |  |  | 					.done() | 
					
						
							|  |  |  | 					// highlight the current item...
 | 
					
						
							|  |  |  | 					.then(function(){ | 
					
						
							|  |  |  | 						dialog | 
					
						
							|  |  |  | 							.filter(`"${cur}"`) | 
					
						
							|  |  |  | 							.addClass('highlighted') }) | 
					
						
							|  |  |  | 			},  | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-07-02 04:36:39 +03:00
										 |  |  | 				cls: 'location-history', | 
					
						
							| 
									
										
										
										
											2017-02-08 22:08:04 +03:00
										 |  |  | 				// NOTE: we are not using path: here because it will parse
 | 
					
						
							|  |  |  | 				// 		the current element as a path, and we need it as-is... 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 				selected: cur, | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			.open(function(evt, path){  | 
					
						
							|  |  |  | 				dialog.close()  | 
					
						
							|  |  |  | 				that.openURLFromHistory(path) | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2017-02-11 03:34:41 +03:00
										 |  |  | 			.on('close', save) | 
					
						
							| 
									
										
										
										
											2017-02-09 02:11:28 +03:00
										 |  |  | 			.on('pin_button', function(evt, p, e){ | 
					
						
							| 
									
										
										
										
											2017-02-11 03:34:41 +03:00
										 |  |  | 				dialog.select(that.config['url-history-focus-on-pin'] ? p : '!') }) | 
					
						
							| 
									
										
										
										
											2017-02-08 22:59:16 +03:00
										 |  |  | 			.on('to_top_button', function(evt, p, e){ | 
					
						
							| 
									
										
										
										
											2017-02-11 03:34:41 +03:00
										 |  |  | 				to_sort.splice(0, 0, p) }) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-06 06:27:46 +03:00
										 |  |  | 			// handle 'O' button to browse path...
 | 
					
						
							|  |  |  | 			dialog.browsePath = function(p){ | 
					
						
							|  |  |  | 				this.selected  | 
					
						
							|  |  |  | 					&& that.browsePath(p || this.selected) | 
					
						
							|  |  |  | 						.close(function(evt, reason){ | 
					
						
							|  |  |  | 							reason != 'reject' | 
					
						
							|  |  |  | 								&& dialog.close(reason) | 
					
						
							|  |  |  | 						}) } | 
					
						
							|  |  |  | 			dialog.keyboard.handler('General', 'O', 'browsePath') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:22:39 +03:00
										 |  |  | 			return dialog | 
					
						
							|  |  |  | 		})], | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var URLHistoryUI =  | 
					
						
							|  |  |  | module.URLHistoryUI = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'ui-url-history', | 
					
						
							|  |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'ui', | 
					
						
							|  |  |  | 		'url-history', | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 	actions: URLHistoryUIActions, | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2016-08-20 22:49:36 +03:00
										 |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |