From e6bc3dcdbb015e397397a95d3455c96869c1bb19 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 24 Feb 2013 16:27:37 +0530 Subject: [PATCH] update Message code --- source/Ox.UI/Ox.UI.js | 2 +- source/Ox.UI/js/Core/Element.js | 75 ++++++++++++++++++++++----------- source/Ox.UI/js/Core/Message.js | 34 ++++++++------- 3 files changed, 70 insertions(+), 41 deletions(-) diff --git a/source/Ox.UI/Ox.UI.js b/source/Ox.UI/Ox.UI.js index ba7f79bc..a82e2b06 100644 --- a/source/Ox.UI/Ox.UI.js +++ b/source/Ox.UI/Ox.UI.js @@ -289,7 +289,7 @@ Ox.load.UI = function(options, callback) { Ox.$window = Ox.UI.$window = $(window); Ox.$parent = { postMessage: function(event, message) { - Ox.Message.post(event, message); + Ox.Message.post(Ox.$parent, event, message); return this; }, onMessage: function() { diff --git a/source/Ox.UI/js/Core/Element.js b/source/Ox.UI/js/Core/Element.js index 1f67588e..9676ef65 100644 --- a/source/Ox.UI/js/Core/Element.js +++ b/source/Ox.UI/js/Core/Element.js @@ -93,32 +93,8 @@ Ox.Element = function(options, self) { that.on('load', function() { Ox.Message.post(that, 'init', {id: that.oxid}); }); - that.onMessage = function() { - var callback; - if (Ox.isObject(arguments[0])) { - Ox.forEach(arguments[0], function(callback, event) { - Ox.Message.bind(arguments[0], function(event_, data, oxid) { - if (event_ == event && oxid == that.oxid) { - callback(data); - } - }); - }); - } else { - callback = arguments[0]; - Ox.Message.bind(function(event, data, oxid) { - if (that.oxid == oxid) { - callback(event, data); - } - }); - } - return that; - }; - that.postMessage = function(event, data) { - Ox.Message.post(that, event, data); - return that; - }; - } + setTooltip(); function mousedown(e) { @@ -368,6 +344,42 @@ Ox.Element = function(options, self) { return that; }; + /*@ + onMessage Adds message handlers (if the element is an iframe) + (callback) -> This element + Adds a catch-all handler + (event, callback) -> This element + Adds a handler for a single event + ({event: callback, ...}) -> This element + Adds handlers for multiple events + callback Callback function + data event data (key/value pairs) + event Event name + @*/ + that.onMessage = function() { + // FIXME: Implement catch-all handler + var callback; + if (self.options.element == '