added action handler tags (siplifies removal) + minor tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-10-13 17:32:19 +04:00
parent b1221f6c8f
commit 9317ea0566
5 changed files with 91 additions and 45 deletions

View File

@ -33,9 +33,9 @@
height: auto; height: auto;
background: black; background: black;
-webkit-transition: all 0.2s ease-in; -webkit-transition: all 0.1s ease-in;
-moz-transition: all 0.2s ease-in; -moz-transition: all 0.1s ease-in;
transition: all 0.2s ease-in; transition: all 0.1s ease-in;
} }
.image.moving { .image.moving {
visibility: hidden; visibility: hidden;

View File

@ -334,12 +334,12 @@ module.MetaActions = {
// Register an action callback... // Register an action callback...
// //
// Register a post action callback // Register a post action callback
// .on('action', <function>) // .on('action', [<tag>, ]<function>)
// .on('action.post', <function>) // .on('action.post', [<tag>, ]<function>)
// -> <action-set> // -> <action-set>
// //
// Register a pre action callback // Register a pre action callback
// .on('action.pre', <function>) // .on('action.pre', [<tag>, ]<function>)
// -> <action-set> // -> <action-set>
// //
// Modes: // Modes:
@ -350,8 +350,17 @@ module.MetaActions = {
// 'post' - the handler is fired after the action is finished. // 'post' - the handler is fired after the action is finished.
// this is the default. // this is the default.
// //
// The optional tag marks the handler to enable group removal via
// .off(..)
//
// NOTE: 'post' mode is the default. // NOTE: 'post' mode is the default.
on: function(action, handler){ //
// XXX add something like text tags to events (extra arg) to enable
// simple and fast handler removal...
on: function(action, b, c){
var handler = typeof(c) == 'function' ? c : b
var tag = typeof(c) == 'function' ? b : c
// prepare the handler... // prepare the handler...
var mode = action.split('.') var mode = action.split('.')
action = mode[0] action = mode[0]
@ -367,9 +376,12 @@ module.MetaActions = {
// mot pre mode... // mot pre mode...
} else if(mode != 'pre') { } else if(mode != 'pre') {
// XXX
throw 'Unknown action mode: '+action+'.'+mode throw 'Unknown action mode: '+action+'.'+mode
} }
handler.tag = tag
// register handlers locally only... // register handlers locally only...
if(!this.hasOwnProperty('_action_handlers')){ if(!this.hasOwnProperty('_action_handlers')){
this._action_handlers = {} this._action_handlers = {}
@ -387,34 +399,53 @@ module.MetaActions = {
// Remove an action callback... // Remove an action callback...
// //
// XXX this will not work for explicit <action>.post... // XXX needs more testing...
off: function(action, handler){ off: function(action, handler){
if(this.hasOwnProperty('_action_handlers')){ if(this.hasOwnProperty('_action_handlers')){
var mode = action.split('.') if(action == '*'){
action = mode[0] var actions = Object.keys(this._action_handlers)
mode = mode[1] } else {
var actions = [action]
}
var that = this
actions.forEach(function(action){
var mode = action.split('.')
action = mode[0]
mode = mode[1]
// get the handlers... // get the handlers...
var h = this._action_handlers[action] var h = that._action_handlers[action]
var i = -1 // remove explicit handler...
if(mode == null || mode == 'post'){ if(typeof(handler) == 'function'){
// XXX find via e.orig_handler == handler && e.mode == 'post' var i = -1
h.forEach(function(e, j){ if(mode == null || mode == 'post'){
// NOTE: we will only get the first match... // XXX find via e.orig_handler == handler && e.mode == 'post'
if(e.orig_handler == handler && i == -1){ h.forEach(function(e, j){
i = j // NOTE: we will only get the first match...
if(e.orig_handler === handler && i == -1){
i = j
}
})
} else if(mode == 'pre'){
i = h.indexOf(handler)
} }
})
} else if(mode == 'pre'){ // NOTE: unknown modes are skipped...
i = h.indexOf(handler) if(i >= 0){
} h.splice(i, 1)
}
// NOTE: unknown modes are skipped... // remove handlers by tag...
if(i >= 0){ } else {
h.splice(i, 1) // filter out everything that mathches a tag in-place...
} h.splice.apply(h,
[0, h.length]
.concat(h.filter(function(e){
return e.tag != handler })))
}
})
} }
return this return this
}, },

View File

@ -278,6 +278,8 @@ module.RibbonsPrototype = {
return this return this
}, },
// XXX make this work for multiple targets...
// XXX avoid ardcoded delays...
makeShadow: function(target, animate){ makeShadow: function(target, animate){
var img = this.getImage(target) var img = this.getImage(target)
var gid = this.getElemGID(img) var gid = this.getElemGID(img)

View File

@ -163,7 +163,7 @@ $(function(){
window.a = testing.setupActions() window.a = testing.setupActions()
viewer.setupAnimation(a) viewer.Animation.setup(a)
}) })

View File

@ -549,25 +549,38 @@ actions.Actions(Client, {
var setupAnimation = /*********************************************************************/
module.setupAnimation = // XXX do a simple feature framework...
function setupAnimation(actions){ // ...need something like:
var animate = function(target){ // Features(['feature_a', 'feature_b'], action).setup()
var s = this.ribbons.makeShadow(target, true)
return function(){ s() } var Animation =
} module.Animation = {
var noanimate = function(target){ tag: 'animation_handler',
var s = this.ribbons.makeShadow(target)
return function(){ s() } setup: function(actions){
} var animate = function(target){
return actions var s = this.ribbons.makeShadow(target, true)
.on('shiftImageUp.pre', animate) return function(){ s() }
.on('shiftImageDown.pre', animate) }
.on('shiftImageLeft.pre', noanimate) var noanimate = function(target){
.on('shiftImageRight.pre', noanimate) var s = this.ribbons.makeShadow(target)
return function(){ s() }
}
var tag = this.tag
return actions
.on('shiftImageUp.pre', tag, animate)
.on('shiftImageDown.pre', tag, animate)
.on('shiftImageLeft.pre', tag, noanimate)
.on('shiftImageRight.pre', tag, noanimate)
},
remove: function(actions){
return actions.off('*', this.tag)
}
} }
/********************************************************************** /**********************************************************************
* vim:set ts=4 sw=4 : */ * vim:set ts=4 sw=4 : */
return module }) return module })