mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	refactoring to make cli work...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									4bfb3fc03d
								
							
						
					
					
						commit
						8480c0425c
					
				| @ -8,6 +8,8 @@ define(function(require){ var module = {} | ||||
| 
 | ||||
| //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||
| 
 | ||||
| var toggler = require('lib/toggler') | ||||
| 
 | ||||
| 
 | ||||
| /*********************************************************************/ | ||||
| 
 | ||||
| @ -36,7 +38,7 @@ module.exitFullscreen = function() { | ||||
| 
 | ||||
| 
 | ||||
| window.toggleFullscreenMode =  | ||||
| module.toggleFullscreenMode = CSSClassToggler( | ||||
| module.toggleFullscreenMode = toggler.CSSClassToggler( | ||||
| 		document.body,  | ||||
| 		'.full-screen-mode', | ||||
| 		function(action){ | ||||
|  | ||||
| @ -168,7 +168,7 @@ module.AppControl = core.ImageGridFeatures.Feature({ | ||||
| 	title: '', | ||||
| 	doc: '', | ||||
| 
 | ||||
| 	tag: 'app-control', | ||||
| 	tag: 'ui-app-control', | ||||
| 	depends: [ | ||||
| 		'ui', | ||||
| 	], | ||||
| @ -179,7 +179,7 @@ module.AppControl = core.ImageGridFeatures.Feature({ | ||||
| 	// 	- chrome app
 | ||||
| 	// 	- nw
 | ||||
| 	// 	- mobile
 | ||||
| 	isApplicable: function(){ return window.nodejs != null }, | ||||
| 	isApplicable: function(){ return this.runtime == 'nw' }, | ||||
| 
 | ||||
| 	// XXX show main window...
 | ||||
| 	handlers: [ | ||||
|  | ||||
| @ -11,6 +11,7 @@ define(function(require){ var module = {} | ||||
| 
 | ||||
| var actions = require('lib/actions') | ||||
| var features = require('lib/features') | ||||
| var toggler = require('lib/toggler') | ||||
| 
 | ||||
| var data = require('data') | ||||
| var images = require('images') | ||||
| @ -57,7 +58,7 @@ function(direction, dfl_tag){ | ||||
| var makeConfigToggler =  | ||||
| module.makeConfigToggler =  | ||||
| function(attr, states, callback){ | ||||
| 	return Toggler(null, | ||||
| 	return toggler.Toggler(null, | ||||
| 		function(_, action){ | ||||
| 			var lst = states.constructor === Array ? states : states.call(this) | ||||
| 
 | ||||
|  | ||||
| @ -13,7 +13,6 @@ var features = require('lib/features') | ||||
| 
 | ||||
| var data = require('data') | ||||
| var images = require('images') | ||||
| var ribbons = require('ribbons') | ||||
| 
 | ||||
| var core = require('features/core') | ||||
| var base = require('features/base') | ||||
| @ -44,15 +43,31 @@ module.CLI = core.ImageGridFeatures.Feature({ | ||||
| 				} | ||||
| 
 | ||||
| 				// XXX for some reason this always contains --help in nw...
 | ||||
| 				console.log('>>>>', argv) | ||||
| 				//console.log('>>>>', argv)
 | ||||
| 
 | ||||
| 
 | ||||
| 				var cli = requirejs('commander') | ||||
| 
 | ||||
| 				cli | ||||
| 					.version('0.0.1') | ||||
| 					.usage('COMMAND OPTION ..') | ||||
| 					.command('index PATH', 'build and index of path') | ||||
| 					.usage('[command] [options] ..') | ||||
| 					.option('--features', 'list loaded features') | ||||
| 					.command('index [path]', 'build and index of path') | ||||
| 					.parse(argv) | ||||
| 
 | ||||
| 
 | ||||
| 				// list features...
 | ||||
| 				// XXX make this a core action...
 | ||||
| 				if(cli.features){ | ||||
| 					this.features.excluded.length > 0  | ||||
| 						&& console.warn('Features excluded (%d):\n   ', | ||||
| 							this.features.excluded.length,  | ||||
| 							this.features.excluded.join('\n    ')) | ||||
| 					console.log('Features not applicable (%d):\n   ',  | ||||
| 						this.features.unapplicable.length,  | ||||
| 						this.features.unapplicable.join('\n    ')) | ||||
| 					console.log('Features loaded (%d):\n   ', | ||||
| 						this.features.features.length,  | ||||
| 						this.features.features.join('\n    ')) | ||||
| 				} | ||||
| 			}] | ||||
| 	], | ||||
| }) | ||||
|  | ||||
| @ -23,20 +23,20 @@ module.ImageGridFeatures = Object.create(features.FeatureSet) | ||||
| 
 | ||||
| // setup exit...
 | ||||
| if(typeof(process) != 'undefined'){ | ||||
| 	// nw.js...
 | ||||
| 	try{ | ||||
| 		// this will fail if we're not in nw.js...
 | ||||
| 		requirejs('nw.gui') | ||||
| 
 | ||||
| 		ImageGridFeatures.runtime = 'nw' | ||||
| 
 | ||||
| 	// pure node.js...
 | ||||
| 	} catch(e) { | ||||
| 		ImageGridFeatures.runtime = 'node' | ||||
| 	} | ||||
| 	// NOTE: if this passes it is async while when fails it's sync, this
 | ||||
| 	// 		is why we set .runtime to 'nw' optimistically in advance so 
 | ||||
| 	// 		as not to wait if all goes well and set it to 'node' in the 
 | ||||
| 	// 		callback that if fails will fail right away...
 | ||||
| 	ImageGridFeatures.runtime = 'nw' | ||||
| 	requirejs(['nw.gui'],  | ||||
| 		// OK: nw.js
 | ||||
| 		function(){},  | ||||
| 		// ERR: pure node.js...
 | ||||
| 		function(){ ImageGridFeatures.runtime = 'node' }) | ||||
| 
 | ||||
| // browser...
 | ||||
| } else if(typeof('window') != 'undefined'){ | ||||
| } else if(typeof(window) != 'undefined'){ | ||||
| 	ImageGridFeatures.runtime = 'browser' | ||||
| 
 | ||||
| // unknown...
 | ||||
| @ -130,9 +130,11 @@ var LifeCycleActions = actions.Actions({ | ||||
| 			} | ||||
| 
 | ||||
| 			// node...
 | ||||
| 			/* XXX there's no process.off(...) | ||||
| 			if(this.__stop_handler && this.runtime == 'node'){ | ||||
| 				process.off('exit', this.__stop_handler) | ||||
| 			} | ||||
| 			*/ | ||||
| 
 | ||||
| 			delete this.__stop_handler | ||||
| 
 | ||||
|  | ||||
| @ -10,7 +10,7 @@ define(function(require){ var module = {} | ||||
| 
 | ||||
| // XXX this should not be imported!!!
 | ||||
| // 		...something wrong with requirejs(..)
 | ||||
| if(window.nodejs != null){ | ||||
| if(typeof(process) != 'undefined'){ | ||||
| 	var fse = requirejs('fs-extra') | ||||
| 	var pathlib = requirejs('path') | ||||
| 	var glob = requirejs('glob') | ||||
| @ -314,7 +314,8 @@ module.FileSystemLoader = core.ImageGridFeatures.Feature({ | ||||
| 
 | ||||
| 	actions: FileSystemLoaderActions, | ||||
| 
 | ||||
| 	isApplicable: function(){ return window.nodejs != null }, | ||||
| 	isApplicable: function(){  | ||||
| 		return this.runtime == 'node' || this.runtime == 'nw' }, | ||||
| }) | ||||
| 
 | ||||
| 
 | ||||
| @ -746,7 +747,8 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({ | ||||
| 
 | ||||
| 	actions: FileSystemWriterActions, | ||||
| 
 | ||||
| 	isApplicable: function(){ return window.nodejs != null }, | ||||
| 	isApplicable: function(){  | ||||
| 		return this.runtime == 'node' || this.runtime == 'nw' }, | ||||
| 
 | ||||
| 	// monitor changes...
 | ||||
| 	// XXX should we use .load(..) to trigger changes instead of .loadURLs(..)???
 | ||||
|  | ||||
| @ -295,7 +295,9 @@ module.URLHistoryLocalStorage = core.ImageGridFeatures.Feature({ | ||||
| 		'url-history', | ||||
| 	], | ||||
| 
 | ||||
| 	isApplicable: function(){ return localStorage != null }, | ||||
| 	isApplicable: function(){  | ||||
| 		return typeof(localStorage) != 'undefined'  | ||||
| 			&& localStorage != null }, | ||||
| 
 | ||||
| 	actions: URLHistoryLocalStorageActions, | ||||
| 
 | ||||
|  | ||||
| @ -25,10 +25,24 @@ var core = require('features/core') | ||||
| // 		- editor			- editing capability
 | ||||
| //
 | ||||
| 
 | ||||
| core.ImageGridFeatures.Feature('viewer-testing', [ | ||||
| core.ImageGridFeatures.Feature('viewer-commandline', [ | ||||
| 	'lifecycle', | ||||
| 	'base-full', | ||||
| 	'commandline', | ||||
| 
 | ||||
| 	'image-marks', | ||||
| 	'image-bookmarks', | ||||
| 
 | ||||
| 	'fs-loader', | ||||
| 	'fs-writer', | ||||
| ]) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| core.ImageGridFeatures.Feature('viewer-testing', [ | ||||
| 	'viewer-commandline', | ||||
| 
 | ||||
| 	'ui', | ||||
| 
 | ||||
| 	'ui-ribbons-placement', | ||||
| @ -58,15 +72,11 @@ core.ImageGridFeatures.Feature('viewer-testing', [ | ||||
| 	'ui-single-image-view-local-storage', | ||||
| 
 | ||||
| 
 | ||||
| 	'fs-loader', | ||||
| 		'ui-fs-loader', | ||||
| 		'fs-url-history', | ||||
| 		'ui-fs-url-history', | ||||
| 
 | ||||
| 	'fs-writer', | ||||
| 		'ui-fs-writer', | ||||
| 
 | ||||
| 	'app-control', | ||||
| 	// fs...
 | ||||
| 	'ui-fs-loader', | ||||
| 	'fs-url-history', | ||||
| 	'ui-fs-url-history', | ||||
| 	'ui-fs-writer', | ||||
| 
 | ||||
| 	// chrome...
 | ||||
| 	'ui-animation', | ||||
| @ -97,6 +107,7 @@ core.ImageGridFeatures.Feature('viewer-testing', [ | ||||
| 	//'auto-single-image',
 | ||||
| 	//'auto-ribbon',
 | ||||
| 	 | ||||
| 	'ui-app-control', | ||||
| 
 | ||||
| 	// XXX not yet fully tested...
 | ||||
| 	'system-journal', | ||||
|  | ||||
| @ -8,12 +8,12 @@ define(function(require){ var module = {} | ||||
| 
 | ||||
| //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||
| 
 | ||||
| var toggler = require('lib/toggler') | ||||
| var actions = require('lib/actions') | ||||
| var features = require('lib/features') | ||||
| 
 | ||||
| var data = require('data') | ||||
| var images = require('images') | ||||
| var ribbons = require('ribbons') | ||||
| 
 | ||||
| var core = require('features/core') | ||||
| var base = require('features/base') | ||||
| @ -32,7 +32,7 @@ var base = require('features/base') | ||||
| // 		Array
 | ||||
| //
 | ||||
| function makeTagTogglerAction(tag){ | ||||
| 	var toggler = function(target, action){ | ||||
| 	var t = function(target, action){ | ||||
| 		if(target == '?' || target == 'on' || target == 'off'){ | ||||
| 			var x = action | ||||
| 			action = target | ||||
| @ -86,16 +86,16 @@ function makeTagTogglerAction(tag){ | ||||
| 	} | ||||
| 
 | ||||
| 	// cheating a bit...
 | ||||
| 	toggler.__proto__ = Toggler.prototype | ||||
| 	toggler.constructor = Toggler | ||||
| 	t.__proto__ = toggler.Toggler.prototype | ||||
| 	t.constructor = toggler.Toggler | ||||
| 
 | ||||
| 	return toggler | ||||
| 	return t | ||||
| } | ||||
| /* XXX this toggler is not fully compatible with the Toggler interface | ||||
|  * 		thus, we either need to update the Toggler to suppor multiple  | ||||
|  * 		values or keep this... | ||||
| function makeTagTogglerAction(tag){ | ||||
| 	return Toggler(null, | ||||
| 	return toggler.Toggler(null, | ||||
| 		function(target, action){ | ||||
| 			// get the target...
 | ||||
| 			target = target || 'current' | ||||
|  | ||||
| @ -8,6 +8,7 @@ define(function(require){ var module = {} | ||||
| 
 | ||||
| //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||
| 
 | ||||
| var toggler = require('lib/toggler') | ||||
| var actions = require('lib/actions') | ||||
| var features = require('lib/features') | ||||
| 
 | ||||
| @ -288,7 +289,7 @@ actions.Actions({ | ||||
| 	// General UI stuff...
 | ||||
| 	// NOTE: this is applicable to all uses...
 | ||||
| 	toggleTheme: ['Interface/Toggle viewer theme',  | ||||
| 		CSSClassToggler( | ||||
| 		toggler.CSSClassToggler( | ||||
| 			function(){ return this.ribbons.viewer },  | ||||
| 			function(){ return this.config.themes }, | ||||
| 			function(state){ this.config.theme = state }) ], | ||||
| @ -1132,7 +1133,7 @@ var ConfigLocalStorageActions = actions.Actions({ | ||||
| 		}], | ||||
| 
 | ||||
| 	toggleAutoStoreConfig: ['File/Store configuration', | ||||
| 		Toggler(null, function(_, state){  | ||||
| 		toggler.Toggler(null, function(_, state){  | ||||
| 				if(state == null){ | ||||
| 					return this.__auto_save_config_timer || 'none' | ||||
| 
 | ||||
| @ -1188,7 +1189,9 @@ module.ConfigLocalStorage = core.ImageGridFeatures.Feature({ | ||||
| 		'ui', | ||||
| 	], | ||||
| 
 | ||||
| 	isApplicable: function(){ return localStorage != null }, | ||||
| 	isApplicable: function(){  | ||||
| 		return typeof(localStorage) != 'undefined'  | ||||
| 			&& localStorage != null }, | ||||
| 
 | ||||
| 	actions: ConfigLocalStorageActions, | ||||
| 
 | ||||
| @ -1623,7 +1626,7 @@ var SingleImageActions = actions.Actions({ | ||||
| 
 | ||||
| 	toggleSingleImage: ['Interface/Toggle single image view',  | ||||
| 		// XXX this is wrong!!!
 | ||||
| 		CSSClassToggler( | ||||
| 		toggler.CSSClassToggler( | ||||
| 			function(){ return this.ribbons.viewer },  | ||||
| 			'single-image-mode') ], | ||||
| }) | ||||
| @ -2463,7 +2466,7 @@ module.PassiveBaseRibbonIndicator = core.ImageGridFeatures.Feature({ | ||||
| 
 | ||||
| 	actions: actions.Actions({ | ||||
| 		togglePassiveBaseRibbonIndicator: ['Interface/Toggle passive base ribbon indicator', | ||||
| 			CSSClassToggler( | ||||
| 			toggler.CSSClassToggler( | ||||
| 				function(){ return this.ribbons.viewer },  | ||||
| 				'show-passive-base-ribbon-indicator', | ||||
| 				function(state){  | ||||
| @ -2639,7 +2642,7 @@ module.RibbonsPlacement = core.ImageGridFeatures.Feature({ | ||||
| 
 | ||||
| 	actions: actions.Actions({ | ||||
| 		toggleRibbonsPlacementMode: ['- Interface/', | ||||
| 			Toggler(null, function(_, state){  | ||||
| 			toggler.Toggler(null, function(_, state){  | ||||
| 					if(state == null){ | ||||
| 						return this.config['ui-ribbons-placement-mode'] | ||||
| 					} | ||||
| @ -2809,7 +2812,7 @@ module.IndirectControl = core.ImageGridFeatures.Feature({ | ||||
| 
 | ||||
| 	actions: actions.Actions({ | ||||
| 		toggleSwipeHandling:['Interface/Toggle indirect control swipe handling', | ||||
| 			Toggler(null, | ||||
| 			toggler.Toggler(null, | ||||
| 				function(_, state){ | ||||
| 
 | ||||
| 					if(state == null){ | ||||
|  | ||||
| @ -1,3 +1,4 @@ | ||||
| #!/usr/bin/env node
 | ||||
| /********************************************************************** | ||||
| *  | ||||
| * | ||||
| @ -6,9 +7,6 @@ | ||||
| 
 | ||||
| //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||
| 
 | ||||
| 
 | ||||
| //var ui = require('./ui')
 | ||||
| 
 | ||||
| var requirejs = require('requirejs') | ||||
| requirejs.config({ | ||||
| 	nodeRequire: require, | ||||
| @ -18,24 +16,72 @@ requirejs.config({ | ||||
| 	//urlArgs: 'bust='+Date.now(),
 | ||||
| }) | ||||
| 
 | ||||
| // XXX load only the actualy used here modules...
 | ||||
| var actions = requirejs('lib/actions') | ||||
| var data = requirejs('data') | ||||
| var ribbons = requirejs('ribbons') | ||||
| var _require = require | ||||
| require = requirejs | ||||
| 
 | ||||
| 
 | ||||
| // XXX 
 | ||||
| var testing = requirejs('testing') | ||||
| var core = require('features/core') | ||||
| var base = require('features/base') | ||||
| var location = require('features/location') | ||||
| var history = require('features/history') | ||||
| var app = require('features/app') | ||||
| var marks = require('features/ui-marks') | ||||
| var filesystem = require('features/filesystem') | ||||
| var cli = require('features/cli') | ||||
| var experimental = require('features/experimental') | ||||
| 
 | ||||
| var meta = require('features/meta') | ||||
| 
 | ||||
| 
 | ||||
| var client = requirejs('client') | ||||
| 
 | ||||
| var viewer = requirejs('viewer') | ||||
| //---------------------------------------------------------------------
 | ||||
| 
 | ||||
| // NOTE: this is here to simplify importing...
 | ||||
| var ImageGridFeatures = | ||||
| module.ImageGridFeatures =  | ||||
| 	core.ImageGridFeatures | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*********************************************************************/ | ||||
| 
 | ||||
| // XXX stub action set -- this needs to be auto-generated...
 | ||||
| var a = actions.Actions() | ||||
| 
 | ||||
| // used switch experimental actions on (set to true) or off (unset or false)...
 | ||||
| //a.experimental = true
 | ||||
| 
 | ||||
| //a.logger = a.logger || {emit: function(e, v){ console.log('    ', e, v) }}
 | ||||
| 
 | ||||
| // setup actions...
 | ||||
| // XXX this will fail because we did not load ui...
 | ||||
| ImageGridFeatures | ||||
| 	.setup(a, [ | ||||
| 		'viewer-commandline', | ||||
| 
 | ||||
| 		// XXX this is not for production...
 | ||||
| 		'experiments', | ||||
| 	]) | ||||
| 	.start() | ||||
| 
 | ||||
| 
 | ||||
| /* | ||||
| // report stuff...
 | ||||
| // XXX we also have .conflicts and .missing
 | ||||
| a.features.excluded.length > 0  | ||||
| 	&& console.warn('Features excluded (%d):', | ||||
| 		a.features.excluded.length,  | ||||
| 		a.features.excluded) | ||||
| console.log('Features not applicable (%d):',  | ||||
| 	a.features.unapplicable.length,  | ||||
| 	a.features.unapplicable) | ||||
| console.log('Features loaded (%d):', | ||||
| 	a.features.features.length,  | ||||
| 	a.features.features) | ||||
| 
 | ||||
| */ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -197,7 +197,6 @@ typeof(require) != 'undefined' && require('nw.gui').Window.get().showDevTools() | ||||
| 
 | ||||
| 
 | ||||
| <script src="lib/jli.js"></script> | ||||
| <script src="lib/toggler.js"></script> | ||||
| 
 | ||||
| <script data-main="ui" src="ext-lib/require.js"></script> | ||||
| 
 | ||||
|  | ||||
| @ -8,6 +8,8 @@ | ||||
| 
 | ||||
| define(function(require){ var module = {} | ||||
| 
 | ||||
| var args2array = require('lib/util').args2array | ||||
| var toggler = require('lib/toggler') | ||||
| var object = require('lib/object') | ||||
| 
 | ||||
| 
 | ||||
| @ -127,14 +129,6 @@ var object = require('lib/object') | ||||
| /*********************************************************************/ | ||||
| // helpers...
 | ||||
| 
 | ||||
| // XXX
 | ||||
| if(typeof(args2array) != 'function'){ | ||||
| 	function args2array(args){ | ||||
| 		return [].slice.call(args) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*********************************************************************/ | ||||
| 
 | ||||
| @ -440,7 +434,7 @@ module.MetaActions = { | ||||
| 				|| MetaActions.getHandlers) | ||||
| 			.call(this, name) | ||||
| 
 | ||||
| 		if(handlers.slice(-1)[0] instanceof Toggler){ | ||||
| 		if(handlers.slice(-1)[0] instanceof toggler.Toggler){ | ||||
| 			return true | ||||
| 		} | ||||
| 
 | ||||
|  | ||||
| @ -8,6 +8,7 @@ define(function(require){ var module = {} | ||||
| 
 | ||||
| //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||
| 
 | ||||
| args2array = require('lib/util').args2array | ||||
| actions = require('lib/actions') | ||||
| 
 | ||||
| 
 | ||||
| @ -328,11 +329,12 @@ module.FeatureSet = { | ||||
| 					var e = that[n] | ||||
| 
 | ||||
| 					if(!e){ | ||||
| 						console.warn('%s: feature is not loaded.', n) | ||||
| 					} | ||||
| 						//console.warn('%s: feature is not loaded.', n)
 | ||||
| 						// XXX should we break here???
 | ||||
| 						throw (n + ': feature is not loaded.') | ||||
| 
 | ||||
| 					// no dependencies...
 | ||||
| 					if(e.depends == null || e.depends.length == 0){ | ||||
| 					} else if(e.depends == null || e.depends.length == 0){ | ||||
| 						res.push(n) | ||||
| 
 | ||||
| 					} else { | ||||
| @ -349,7 +351,6 @@ module.FeatureSet = { | ||||
| 						res = res.concat(deps) | ||||
| 						res.push(n) | ||||
| 					} | ||||
| 
 | ||||
| 				}) | ||||
| 				lst = res | ||||
| 				depth -= 1 | ||||
|  | ||||
| @ -1029,80 +1029,6 @@ function sign(x){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| String.prototype.capitalize = function(){ | ||||
| 	return this[0].toUpperCase() + this.slice(1) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // XXX not sure if this has to be a utility or a method...
 | ||||
| Object.get = function(obj, name, dfl){ | ||||
| 	var val = obj[name] | ||||
| 	if(val === undefined && dfl != null){ | ||||
| 		return dfl | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Compact a sparse array...
 | ||||
| //
 | ||||
| // NOTE: this will not compact in-place.
 | ||||
| Array.prototype.compact = function(){ | ||||
| 	return this.filter(function(){ return true }) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // return an array with duplicate elements removed...
 | ||||
| //
 | ||||
| Array.prototype.unique = function(){ | ||||
| 	return this.filter(function(e, i, a){ return a.indexOf(e) == i }) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Compare two arrays...
 | ||||
| //
 | ||||
| Array.prototype.cmp = function(other){ | ||||
| 	if(this === other){ | ||||
| 		return true | ||||
| 	} | ||||
| 	if(this.length != other.length){ | ||||
| 		return false | ||||
| 	} | ||||
| 	for(var i=0; i<this.length; i++){ | ||||
| 		if(this[i] != other[i]){ | ||||
| 			return false | ||||
| 		} | ||||
| 	} | ||||
| 	return true | ||||
| } | ||||
| 
 | ||||
| // Compare two Arrays as sets...
 | ||||
| //
 | ||||
| // This will ignore order
 | ||||
| Array.prototype.setCmp = function(other){ | ||||
| 	return this === other  | ||||
| 		|| this.unique().sort().cmp(other.unique().sort()) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // like .length but for sparse arrays will return the element count...
 | ||||
| // XXX make this a prop...
 | ||||
| /* | ||||
| Array.prototype.len = function(){ | ||||
| 	//return this.compact().length
 | ||||
| 	return Object.keys(this).length | ||||
| } | ||||
| */ | ||||
| 
 | ||||
| Object.defineProperty(Array.prototype, 'len', { | ||||
| 	get : function () { | ||||
| 		return Object.keys(this).length | ||||
| 	}, | ||||
| 	set : function(val){}, | ||||
| }); | ||||
| 
 | ||||
| 
 | ||||
| // convert JS arguments to Array...
 | ||||
| function args2array(args){ | ||||
| 	//return Array.apply(null, args)
 | ||||
|  | ||||
| @ -1,7 +1,11 @@ | ||||
| /********************************************************************** | ||||
| * | ||||
| * | ||||
| * | ||||
| **********************************************************************/ | ||||
| 
 | ||||
| define(function(require){ var module = {} | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*********************************************************************/ | ||||
| @ -124,7 +128,9 @@ | ||||
| // 		later is enough, but as strict mode is not stable enough (sometimes
 | ||||
| // 		works and sometimes does not), we can not reliably pass the element
 | ||||
| // 		via 'this'.
 | ||||
| function Toggler(elem, state_accessor, states, callback_a, callback_b){ | ||||
| var Toggler = | ||||
| module.Toggler = | ||||
| function(elem, state_accessor, states, callback_a, callback_b){ | ||||
| 	// normalize states...
 | ||||
| 	var states_getter = states | ||||
| 	var state_set = typeof(states) == typeof('str') ? ['none', states] : states | ||||
| @ -321,6 +327,8 @@ Toggler.prototype.__proto__ = Function.prototype | ||||
| 
 | ||||
| // XXX this should be drop-in compatible with createCSSClassToggler(..)
 | ||||
| // 		test and replace...
 | ||||
| var CSSClassToggler = | ||||
| module.CSSClassToggler = | ||||
| function CSSClassToggler(elem, classes, callback_a, callback_b){ | ||||
| 	var classes_getter = classes | ||||
| 	var classes_set = classes | ||||
| @ -400,3 +408,4 @@ CSSClassToggler.prototype.__proto__ = Toggler.prototype | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * vim:set ts=4 sw=4 :                                                */ | ||||
| return module }) | ||||
|  | ||||
| @ -11,6 +11,81 @@ define(function(require){ var module = {} | ||||
| 
 | ||||
| /*********************************************************************/ | ||||
| 
 | ||||
| String.prototype.capitalize = function(){ | ||||
| 	return this[0].toUpperCase() + this.slice(1) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // XXX not sure if this has to be a utility or a method...
 | ||||
| Object.get = function(obj, name, dfl){ | ||||
| 	var val = obj[name] | ||||
| 	if(val === undefined && dfl != null){ | ||||
| 		return dfl | ||||
| 	} | ||||
| 	return val | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Compact a sparse array...
 | ||||
| //
 | ||||
| // NOTE: this will not compact in-place.
 | ||||
| Array.prototype.compact = function(){ | ||||
| 	return this.filter(function(){ return true }) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // return an array with duplicate elements removed...
 | ||||
| //
 | ||||
| Array.prototype.unique = function(){ | ||||
| 	return this.filter(function(e, i, a){ return a.indexOf(e) == i }) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Compare two arrays...
 | ||||
| //
 | ||||
| Array.prototype.cmp = function(other){ | ||||
| 	if(this === other){ | ||||
| 		return true | ||||
| 	} | ||||
| 	if(this.length != other.length){ | ||||
| 		return false | ||||
| 	} | ||||
| 	for(var i=0; i<this.length; i++){ | ||||
| 		if(this[i] != other[i]){ | ||||
| 			return false | ||||
| 		} | ||||
| 	} | ||||
| 	return true | ||||
| } | ||||
| 
 | ||||
| // Compare two Arrays as sets...
 | ||||
| //
 | ||||
| // This will ignore order
 | ||||
| Array.prototype.setCmp = function(other){ | ||||
| 	return this === other  | ||||
| 		|| this.unique().sort().cmp(other.unique().sort()) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // like .length but for sparse arrays will return the element count...
 | ||||
| // XXX make this a prop...
 | ||||
| /* | ||||
| Array.prototype.len = function(){ | ||||
| 	//return this.compact().length
 | ||||
| 	return Object.keys(this).length | ||||
| } | ||||
| */ | ||||
| 
 | ||||
| Object.defineProperty(Array.prototype, 'len', { | ||||
| 	get : function () { | ||||
| 		return Object.keys(this).length | ||||
| 	}, | ||||
| 	set : function(val){}, | ||||
| }); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // convert JS arguments to Array...
 | ||||
| var args2array = | ||||
| module.args2array = | ||||
| @ -78,47 +153,48 @@ function(path){ | ||||
| /*********************************************************************/ | ||||
| 
 | ||||
| // XXX experiment
 | ||||
| jQuery.fn._drag = function(){ | ||||
| 	var dragging = false | ||||
| 	var s,  | ||||
| 		px, py | ||||
| if(typeof(jQuery) != typeof(undefined)){ | ||||
| 	jQuery.fn._drag = function(){ | ||||
| 		var dragging = false | ||||
| 		var s,  | ||||
| 			px, py | ||||
| 
 | ||||
| 	var elem = $(this) | ||||
| 		.on('mousedown touchstart', function(evt){ | ||||
| 			dragging = true | ||||
| 			px = evt.clientX | ||||
| 			px = evt.clientY | ||||
| 		var elem = $(this) | ||||
| 			.on('mousedown touchstart', function(evt){ | ||||
| 				dragging = true | ||||
| 				px = evt.clientX | ||||
| 				px = evt.clientY | ||||
| 
 | ||||
| 			s = elem.rscale() | ||||
| 		}) | ||||
| 		.on('mousemove touchmove', function(evt){ | ||||
| 			if(!dragging){ | ||||
| 				return | ||||
| 			} | ||||
| 				s = elem.rscale() | ||||
| 			}) | ||||
| 			.on('mousemove touchmove', function(evt){ | ||||
| 				if(!dragging){ | ||||
| 					return | ||||
| 				} | ||||
| 
 | ||||
| 			var x = evt.clientX  | ||||
| 			var dx = px - x | ||||
| 			px = x | ||||
| 				var x = evt.clientX  | ||||
| 				var dx = px - x | ||||
| 				px = x | ||||
| 
 | ||||
| 			var y = evt.clientY  | ||||
| 			var dy = py - y | ||||
| 			py = y | ||||
| 				var y = evt.clientY  | ||||
| 				var dy = py - y | ||||
| 				py = y | ||||
| 
 | ||||
| 			elem | ||||
| 				.velocity('stop') | ||||
| 				.velocity({ | ||||
| 					translateX: '-=' + (dx / s), | ||||
| 					translateY: '-=' + (dy / s), | ||||
| 				}, 0) | ||||
| 		}) | ||||
| 		.on('mouseup touchend', function(evt){ | ||||
| 			dragging = false | ||||
| 			elem.velocity('stop') | ||||
| 		}) | ||||
| 				elem | ||||
| 					.velocity('stop') | ||||
| 					.velocity({ | ||||
| 						translateX: '-=' + (dx / s), | ||||
| 						translateY: '-=' + (dy / s), | ||||
| 					}, 0) | ||||
| 			}) | ||||
| 			.on('mouseup touchend', function(evt){ | ||||
| 				dragging = false | ||||
| 				elem.velocity('stop') | ||||
| 			}) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * vim:set ts=4 sw=4 :                                                */ | ||||
| return module }) | ||||
|  | ||||
| @ -20,8 +20,9 @@ define(function(require){ var module = {} | ||||
| 
 | ||||
| //var promise = require('promise')
 | ||||
| 
 | ||||
| var keyboard = require('../keyboard') | ||||
| var object = require('../object') | ||||
| var toggler = require('lib/toggler') | ||||
| var keyboard = require('lib/keyboard') | ||||
| var object = require('lib/object') | ||||
| var widget = require('./widget') | ||||
| 
 | ||||
| 
 | ||||
| @ -1229,7 +1230,7 @@ var BrowserPrototype = { | ||||
| 	// 		on filter field)...
 | ||||
| 	// NOTE: this uses .filter(..) for actual filtering...
 | ||||
| 	// NOTE: on state change this will return this...
 | ||||
| 	toggleFilter: CSSClassToggler( | ||||
| 	toggleFilter: toggler.CSSClassToggler( | ||||
| 		function(){ return this.dom },  | ||||
| 		'filtering', | ||||
| 		// do not enter filter mode if filtering is disabled...
 | ||||
|  | ||||
| @ -10,10 +10,11 @@ var gui = require('nw.gui') | ||||
| 
 | ||||
| define(function(require){ var module = {} | ||||
| 
 | ||||
| var toggler = require('lib/toggler') | ||||
| 
 | ||||
| var browser = require('browser') | ||||
| //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||
| 
 | ||||
| 
 | ||||
| var walk = require('lib/widget/browse-walk') | ||||
| 
 | ||||
| 
 | ||||
| @ -24,7 +25,7 @@ var walk = require('lib/widget/browse-walk') | ||||
| window.listDirBrowser = walk.listDirBrowser | ||||
| 
 | ||||
| window.toggleFullscreenMode =  | ||||
| module.toggleFullscreenMode = CSSClassToggler( | ||||
| module.toggleFullscreenMode = toggler.CSSClassToggler( | ||||
| 		document.body,  | ||||
| 		'.full-screen-mode', | ||||
| 		function(action){ | ||||
|  | ||||
| @ -1,30 +1,34 @@ | ||||
| { | ||||
|   "name": "ImageGrid.Viewer.g4", | ||||
|   "main": "index.html", | ||||
|   "version": "0.0.1", | ||||
|   "window": { | ||||
|     "title": "ImageGrid.Viewer (gen4)", | ||||
|     "position": "center", | ||||
|     "width": 900, | ||||
|     "height": 700, | ||||
|     "min_width": 400, | ||||
|     "min_height": 400, | ||||
|     "frame": true, | ||||
|     "toolbar": false, | ||||
|     "show": false | ||||
|   }, | ||||
|   "webkit": { | ||||
|     "page-cache": true | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "commander": "^2.9.0", | ||||
|     "flickrapi": "^0.3.28", | ||||
|     "fs-extra": "*", | ||||
|     "fs-walk": "0.0.1", | ||||
|     "glob": "^4.0.6", | ||||
|     "guarantee-events": "^1.0.0", | ||||
|     "promise": "^6.0.1", | ||||
|     "requirejs": "*", | ||||
|     "sharp": "^0.12.0" | ||||
|   } | ||||
| 	"name": "ImageGrid.Viewer.g4", | ||||
| 	"main": "index.html", | ||||
| 	"version": "0.0.1", | ||||
| 	"window": { | ||||
| 		"title": "ImageGrid.Viewer (gen4)", | ||||
| 		"position": "center", | ||||
| 		"width": 900, | ||||
| 		"height": 700, | ||||
| 		"min_width": 400, | ||||
| 		"min_height": 400, | ||||
| 		"frame": true, | ||||
| 		"toolbar": false, | ||||
| 		"show": false | ||||
| 	}, | ||||
| 	"webkit": { | ||||
| 		"page-cache": true | ||||
| 	}, | ||||
| 	"dependencies": { | ||||
| 		"commander": "^2.9.0", | ||||
| 		"flickrapi": "^0.3.28", | ||||
| 		"fs-extra": "*", | ||||
| 		"fs-walk": "0.0.1", | ||||
| 		"glob": "^4.0.6", | ||||
| 		"guarantee-events": "^1.0.0", | ||||
| 		"promise": "^6.0.1", | ||||
| 		"requirejs": "*", | ||||
| 		"sharp": "^0.12.0" | ||||
| 	}, | ||||
| 	"preferGlobal": true, | ||||
| 	"bin": { | ||||
| 		"ig": "ig.js" | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -19,6 +19,7 @@ var object = require('lib/object') | ||||
| var data = require('data') | ||||
| var images = require('images') | ||||
| 
 | ||||
| 
 | ||||
| var IMAGE = '.image:not(.clone)' | ||||
| var RIBBON = '.ribbon:not(.clone)' | ||||
| 
 | ||||
|  | ||||
| @ -46,9 +46,6 @@ var ribbons = require('ribbons') | ||||
| // XXX 
 | ||||
| var testing = require('testing') | ||||
| 
 | ||||
| 
 | ||||
| var client = require('client') | ||||
| 
 | ||||
| var viewer = require('viewer') | ||||
| 
 | ||||
| //var promise = require('promise')
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user