not actions .on(..) / .off(..) support multiple space-seporated events in a singe call (a-la jQuery .on(..) )...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-10-25 03:06:05 +04:00
parent 79a555aba6
commit df43ed4ea3

View File

@ -359,10 +359,12 @@ module.MetaActions = {
// //
// XXX add something like text tags to events (extra arg) to enable // XXX add something like text tags to events (extra arg) to enable
// simple and fast handler removal... // simple and fast handler removal...
on: function(action, b, c){ on: function(actions, b, c){
var handler = typeof(c) == 'function' ? c : b var handler = typeof(c) == 'function' ? c : b
var tag = typeof(c) == 'function' ? b : c var tag = typeof(c) == 'function' ? b : c
var that = this
actions.split(' ').forEach(function(action){
// prepare the handler... // prepare the handler...
var mode = action.split('.') var mode = action.split('.')
action = mode[0] action = mode[0]
@ -385,17 +387,19 @@ module.MetaActions = {
handler.tag = tag handler.tag = tag
// register handlers locally only... // register handlers locally only...
if(!this.hasOwnProperty('_action_handlers')){ if(!that.hasOwnProperty('_action_handlers')){
this._action_handlers = {} that._action_handlers = {}
} }
if(!(action in this._action_handlers)){ if(!(action in that._action_handlers)){
this._action_handlers[action] = [] that._action_handlers[action] = []
} }
// register a handler only once... // register a handler only once...
if(this._action_handlers[action].indexOf(handler) < 0){ if(that._action_handlers[action].indexOf(handler) < 0){
// NOTE: last registered is first... // NOTE: last registered is first...
this._action_handlers[action].splice(0, 0, handler) that._action_handlers[action].splice(0, 0, handler)
} }
})
return this return this
}, },
@ -407,7 +411,7 @@ module.MetaActions = {
if(action == '*'){ if(action == '*'){
var actions = Object.keys(this._action_handlers) var actions = Object.keys(this._action_handlers)
} else { } else {
var actions = [action] var actions = action.split(' ')
} }
var that = this var that = this
actions.forEach(function(action){ actions.forEach(function(action){