diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 6ce9c686..0f43660f 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -21,6 +21,30 @@ var ImageGridFeatures = 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' + } + +// browser... +} else if(typeof('window') != 'undefined'){ + ImageGridFeatures.runtime = 'browser' + +// unknown... +} else { + ImageGridFeatures.runtime = 'unknown' +} + + /*********************************************************************/ @@ -42,60 +66,52 @@ var LifeCycleActions = actions.Actions({ return } - // setup exit... - if(typeof(process) != 'undefined'){ - // nw.js... - try{ - this.runtime = 'nw' + // set the runtime... + var runtime = this.runtime = ImageGridFeatures.runtime - // this will fail if we're not in nw.js... - var gui = requirejs('nw.gui') - - // this handles both reload and close... - $(window).on('beforeunload', stop) - - // NOTE: we are using both events as some of them do not - // get triggered in specific conditions and some do, - // for example, this gets triggered when the window's - // 'X' is clicked while does not on reload... - this.__nw_stop_handler = function(){ - var w = this - try{ - that - // wait till ALL the handlers finish before - // exiting... - .on('stop.post', function(){ - w.close(true) - }) - .stop() - - // in case something breaks exit... - // XXX not sure if this is correct... - } catch(e){ - this.close(true) - } - } - gui.Window.get().on('close', this.__nw_stop_handler) - - - // pure node.js... - } catch(e) { - this.runtime = 'node' - - process.on('exit', stop) - } - - // browser... - } else if(typeof('window') != 'undefined'){ - this.runtime = 'browser' + // nw.js... + if(runtime == 'nw'){ + var gui = requirejs('nw.gui') + // this handles both reload and close... $(window).on('beforeunload', stop) - // unknown... - } else { - this.runtime = 'unknown' - } + // NOTE: we are using both events as some of them do not + // get triggered in specific conditions and some do, + // for example, this gets triggered when the window's + // 'X' is clicked while does not on reload... + this.__nw_stop_handler = function(){ + var w = this + try{ + that + // wait till ALL the handlers finish before + // exiting... + .on('stop.post', function(){ + w.close(true) + }) + .stop() + // in case something breaks exit... + // XXX not sure if this is correct... + } catch(e){ + this.close(true) + } + } + gui.Window.get().on('close', this.__nw_stop_handler) + + + // node.js... + } else if(runtime == 'node'){ + process.on('exit', stop) + + // browser... + } else if(runtime == 'browser'){ + $(window).on('beforeunload', stop) + + // other... + } else { + // XXX + } }], // unbind events... stop: ['- System/', diff --git a/ui (gen4)/features/ui.js b/ui (gen4)/features/ui.js index 03b33803..03ef5436 100755 --- a/ui (gen4)/features/ui.js +++ b/ui (gen4)/features/ui.js @@ -2781,7 +2781,6 @@ module.DirectControlGSAP = core.ImageGridFeatures.Feature({ - //--------------------------------------------------------------------- // XXX make this browser specific... (???) @@ -2793,7 +2792,7 @@ module.URLHash = core.ImageGridFeatures.Feature({ tag: 'ui-url-hash', depends: ['ui'], - //isApplicable: function(){}, + isApplicable: function(){ return this.runtime == 'browser' }, handlers: [ ['focusImage', diff --git a/ui (gen4)/lib/features.js b/ui (gen4)/lib/features.js index 7affeeaa..34d01e66 100755 --- a/ui (gen4)/lib/features.js +++ b/ui (gen4)/lib/features.js @@ -432,6 +432,7 @@ module.FeatureSet = { // clasify features... var unapplicable = [] var conflicts = {} + var that = this lst = lst.filter(function(n, i){ var e = that[n] if(e == null){ @@ -439,7 +440,7 @@ module.FeatureSet = { } // check applicability... - if(!e.isApplicable(obj)){ + if(!e.isApplicable.call(that, obj)){ unapplicable.push(n) return false }