added compatibility for node.js events in actions...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-07-25 14:58:52 +04:00
parent 5c8de52214
commit d29903f024
2 changed files with 28 additions and 5 deletions

View File

@ -9,6 +9,16 @@ console.log('>>> actions')
//var DEBUG = DEBUG != null ? DEBUG : true //var DEBUG = DEBUG != null ? DEBUG : true
// can be:
// 'jQuery'
// 'node'
//
var EVT_MODE =
module.EVT_MODE =
typeof(window) != null && window.jQuery ? 'jQuery'
: typeof(global) != null && global.jQuery ? 'jQuery'
: 'node'
/*********************************************************************/ /*********************************************************************/
// //
@ -26,14 +36,27 @@ console.log('>>> actions')
// //
/*********************************************************************/ /*********************************************************************/
var fireEvent =
module.fireEvent =
function(context, name, args){
if(EVT_MODE == 'jQuery'){
var c = $(context)
.trigger(name, args)
} else {
var c = context
.emit.apply(context, [name].concat(args))
}
return c
}
// NOTE: context is dynamic. // NOTE: context is dynamic.
var Action = var Action =
module.Action = module.Action =
function Action(context, name, doc, code){ function Action(context, name, doc, code){
var action = function(){ var action = function(){
var args = args2array(arguments) var args = args2array(arguments)
var c = $(context) var c = fireEvent(context, name + '.pre', args)
.trigger(name + '.pre', args)
// run compound action content... // run compound action content...
if(code != null){ if(code != null){
@ -51,9 +74,9 @@ function Action(context, name, doc, code){
} }
} }
fireEvent(c, name, args)
fireEvent(c, name + '.post', args)
return c return c
.trigger(name, args)
.trigger(name + '.post', args)
} }
action.doc = doc == null ? name : doc action.doc = doc == null ? name : doc
return action return action

View File

@ -190,7 +190,7 @@ module.ImagesPrototype = {
}, },
// XXX // XXX
sortedImagesByFileNameSeqWithOverflow: function(gids, reverse){ sortedImagesByFileNameSeqWithOverflow: function(gids, reverse){
// XXX see ui/sort.js // XXX see ../ui/sort.js
}, },