From 6f7e0a562e7dac5dfd5e6bbc0012e6a91586d1fc Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 14 Jun 2012 14:17:19 +0200 Subject: [PATCH] [ADD] Added Event Bus bzr revid: fme@openerp.com-20120614121719-tri5zx5gjjqj3ea6 --- addons/web/static/src/js/coresetup.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 4defde54a3c..2ab5e71ca0b 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -400,6 +400,29 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess } }); +/** + * Event Bus used to bind events scoped in the current instance + */ +instance.web.bus = new (instance.web.Class.extend(instance.web.EventDispatcherMixin, { + init: function() { + instance.web.EventDispatcherMixin.init.call(this, parent); + var self = this; + // TODO fme: allow user to bind keys for some global actions. + // check gtk bindings + // http://unixpapa.com/js/key.html + _.each('click,dblclick,keydown,keypress,keyup'.split(','), function(evtype) { + $('html').on(evtype, self, function(ev) { + self.trigger(evtype, ev, evtype); + }); + }); + _.each('resize,scroll'.split(','), function(evtype) { + $(window).on(evtype, self, function(ev) { + self.trigger(evtype, ev, evtype); + }); + }); + } +}))(); + /** OpenERP Translations */ instance.web.TranslationDataBase = instance.web.Class.extend(/** @lends instance.web.TranslationDataBase# */{ /**