From d29903f02468e62e5f31588d87d3a253534f3150 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 25 Jul 2014 14:58:52 +0400 Subject: [PATCH] added compatibility for node.js events in actions... Signed-off-by: Alex A. Naanou --- ui (gen4)/actions.js | 31 +++++++++++++++++++++++++++---- ui (gen4)/images.js | 2 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ui (gen4)/actions.js b/ui (gen4)/actions.js index 431568e8..f2f2157d 100755 --- a/ui (gen4)/actions.js +++ b/ui (gen4)/actions.js @@ -9,6 +9,16 @@ console.log('>>> actions') //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. var Action = module.Action = function Action(context, name, doc, code){ var action = function(){ var args = args2array(arguments) - var c = $(context) - .trigger(name + '.pre', args) + var c = fireEvent(context, name + '.pre', args) // run compound action content... if(code != null){ @@ -51,9 +74,9 @@ function Action(context, name, doc, code){ } } + fireEvent(c, name, args) + fireEvent(c, name + '.post', args) return c - .trigger(name, args) - .trigger(name + '.post', args) } action.doc = doc == null ? name : doc return action diff --git a/ui (gen4)/images.js b/ui (gen4)/images.js index 1af95b59..9bdc5844 100755 --- a/ui (gen4)/images.js +++ b/ui (gen4)/images.js @@ -190,7 +190,7 @@ module.ImagesPrototype = { }, // XXX sortedImagesByFileNameSeqWithOverflow: function(gids, reverse){ - // XXX see ui/sort.js + // XXX see ../ui/sort.js },