From 26c9b8db2f55fa01841ac1605584d57634c5427e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 29 Oct 2014 18:50:04 +0300 Subject: [PATCH] adde .one(..) to actions + minor tweaks and changes... Signed-off-by: Alex A. Naanou --- ui (gen4)/lib/actions.js | 55 +++++++++++++++++++++++++++++++++++++--- ui (gen4)/viewer.js | 43 ++++++++++++++++++++++++++++--- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/ui (gen4)/lib/actions.js b/ui (gen4)/lib/actions.js index 5c035091..3abaf6ad 100755 --- a/ui (gen4)/lib/actions.js +++ b/ui (gen4)/lib/actions.js @@ -357,7 +357,7 @@ module.MetaActions = { // // NOTE: 'post' mode is the default. // - // XXX document tags... + // XXX should we have multiple tags per handler??? on: function(actions, b, c){ var handler = typeof(c) == 'function' ? c : b var tag = typeof(c) == 'function' ? b : c @@ -377,7 +377,7 @@ module.MetaActions = { handler = function(){ return old_handler } // NOTE: this is set so as to identify the handler for removal // via. .off(..) - handler.orig_handler = old_handler + handler.orig_handler = old_handler.orig_handler || old_handler // mot pre mode... } else if(mode != 'pre') { @@ -406,12 +406,27 @@ module.MetaActions = { // Remove an action callback... // - // XXX document tags... + // Remove all handlers from action: + // .off('action') + // .off('action', '*') + // .off('action', 'all') + // -> + // + // Remove specific handler from action: + // .off('action', ) + // -> + // + // Remove handlers from action by tag: + // .off('action', ) + // -> + // + // NOTE: the handler passed to .off(..) for removal must be the same + // as the handler passed to .on(..) / .one(..) off: function(actions, handler){ if(this.hasOwnProperty('_action_handlers')){ actions = actions == '*' ? Object.keys(this._action_handlers) - : typeof(actions) == 'string' ? action.split(' ') + : typeof(actions) == 'string' ? actions.split(' ') : actions var that = this @@ -444,6 +459,10 @@ module.MetaActions = { h.splice(i, 1) } + // remove all handlers... + } else if(handler == null || handler == 'all' || handler == '*'){ + h.splice(0, h.length) + // remove handlers by tag... } else { // filter out everything that mathches a tag in-place... @@ -454,6 +473,30 @@ module.MetaActions = { } }) } + + return this + }, + + // Register an action callback that will only fire once per event... + // + // This is signature compatible with .on(..) + one: function(actions, b, c){ + var handler = typeof(c) == 'function' ? c : b + var tag = typeof(c) == 'function' ? b : c + + actions = typeof(actions) == 'string' ? actions.split(' ') : actions + + var that = this + actions.forEach(function(action){ + var _handler = function(){ + // remove handler... + that.off(action, handler) + return handler.apply(this, arguments) + } + _handler.orig_handler = handler + that.on(action, tag, _handler) + }) + return this }, @@ -487,6 +530,7 @@ module.MetaActions = { // Mixin a set of local actions into an object... // + // XXX test mixinTo: function(to, all, all_attr_types){ return this.mixin.call(to, this, all, all_attr_types) }, @@ -527,6 +571,7 @@ module.MetaActions = { // Remove a set of local mixed in actions from object... // + // XXX test mixoutFrom: function(to, all, all_attr_types){ return this.mixout.call(to, this, all, all_attr_types) }, @@ -569,6 +614,8 @@ module.MetaActions = { // NOTE: if is not given, MetaActions will be used as default. // // For more documentation see: Action(..). +// +// XXX add doc, ldoc, tags and save them to each action... var Actions = module.Actions = function Actions(a, b){ diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index 5c76a885..ee3c9bdd 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -450,6 +450,14 @@ var Viewer = module.Viewer = actions.Actions(Client, { + get screenwidth(){ + return this.ribbons != null ? this.ribbons.getScreenWidthImages() : null + }, + set screenwidth(n){ + this.fitImage(n) + }, + + ready: [ function(){ // XXX setup empty state... @@ -479,10 +487,12 @@ actions.Actions(Client, { function(){ this.ribbons.preventTransitions() - this.ribbons.updateData(this.data) - this.focusImage() + return function(){ + this.ribbons.updateData(this.data) + this.focusImage() - this.ribbons.restoreTransitions() + this.ribbons.restoreTransitions() + } }], clear: [ // XXX do we need to delete the ribbons??? @@ -642,6 +652,10 @@ actions.Actions(Client, { }], /* // XXX an ideologically different version of .focusImage(..) + // This version aligns the ribbons internally while the above + // version does not align at all, and all alignment is handled + // by a feature. + // // The main question here is: // should we split out aligning to a feature? // The differences/trade-off's in this version: @@ -824,6 +838,29 @@ actions.Actions(Client, { crop: [ reloadAfter() ], uncrop: [ reloadAfter() ], + + // XXX experimental: not sure if this is the right way to go... + // XXX make this play nice with crops... + toggleRibbonList: ['Toggle ribbons as images view', + function(){ + if(this._full_data == null){ + // XXX do a better name here... + this._full_data = this.data + + // generate the view... + this.data = this.data.cropRibbons() + + this.reload() + } else { + var data = this._full_data + delete this._full_data + + // restore... + this.data = data.mergeRibbonCrop(this.data) + + this.reload() + } + }], })