move Ox. into Message.js so it can be used standalone without Ox.UI

This commit is contained in:
j 2013-02-28 15:42:06 +00:00
parent cce6c954ba
commit 82aeddccfe
2 changed files with 29 additions and 27 deletions

View file

@ -287,32 +287,6 @@ Ox.load.UI = function(options, callback) {
Ox.$document = Ox.UI.$document = $(document);
Ox.$head = Ox.UI.$head = $('head');
Ox.$window = Ox.UI.$window = $(window);
Ox.$parent = {
postMessage: function(event, message) {
Ox.Message.post(Ox.$parent, event, message);
return this;
},
onMessage: function() {
var callback;
if (Ox.isObject(arguments[0])) {
Ox.forEach(arguments[0], function(callback, event) {
Ox.Message.bind(function(event_, data, oxid) {
if (event_ == event && Ox.isUndefined(oxid)) {
callback(data || {});
}
});
});
} else {
callback = arguments[0];
Ox.Message.bind(function(event, data, oxid) {
if (Ox.isUndefined(oxid)) {
callback(event, data || {});
}
});
}
return this;
}
};
// fixme: is this the right place to do this?
$.browser.mozilla && Ox.$document.on('dragstart', function() {
return false;

View file

@ -24,6 +24,34 @@ Ox.Message = (function() {
}
});
// Defined here so one can just load Message.js in addtion to Ox.js
Ox.$parent = {
postMessage: function(event, message) {
Ox.Message.post(Ox.$parent, event, message);
return this;
},
onMessage: function() {
var callback;
if (Ox.isObject(arguments[0])) {
Ox.forEach(arguments[0], function(callback, event) {
Ox.Message.bind(function(event_, data, oxid) {
if (event_ == event && Ox.isUndefined(oxid)) {
callback(data || {});
}
});
});
} else {
callback = arguments[0];
Ox.Message.bind(function(event, data, oxid) {
if (Ox.isUndefined(oxid)) {
callback(event, data || {});
}
});
}
return this;
}
};
/*@
.bind <f> Adds message handler
(callback) -> <o> Ox.Message
@ -45,7 +73,7 @@ Ox.Message = (function() {
that.post = function(target, event, data) {
target = target == Ox.$parent ? window.parent
: Ox.isElement(target[0]) ? target[0].contentWindow
: $('#' + target)[0].contentWindow;
: Ox.$('#' + target)[0].contentWindow;
target.postMessage(JSON.stringify({
event: event,
data: data,