Ox.Element: make onMessage alias of bindMessage, reserve other message methods, update docs

This commit is contained in:
rolux 2013-12-07 15:49:41 +01:00
parent 348d6d3aff
commit 70bd7afd67

View file

@ -300,7 +300,7 @@ Ox.Element = function(options, self) {
(event, callback) -> <o> This element
Adds a handler for a single event
({event: callback, ...}) -> <o> This element
Adds handlers for multiple events
Adds handlers for one or more events
callback <f> Callback function
data <o> event data (key/value pairs)
event <s> Event name
@ -318,7 +318,7 @@ Ox.Element = function(options, self) {
(event, callback) -> <o> This element
Adds a handler for a single event
({event: callback, ...}) -> <o> This element
Adds handlers for multiple events
Adds handlers for one or more events
callback <f> Callback function
data <o> event data (key/value pairs)
event <s> Event name
@ -329,6 +329,45 @@ Ox.Element = function(options, self) {
return that;
};
/*@
bindMessage <f> Adds message handlers (if the element is an iframe)
(callback) -> <o> This element
Adds a catch-all handler
(event, callback) -> <o> This element
Adds a handler for a single event
({event: callback, ...}) -> <o> This element
Adds handlers for on or more events
callback <f> Callback function
data <o> event data (key/value pairs)
event <s> Event name
@*/
that.bindMessage = that.onMessage = function() {
var callback;
if (self.options.element == '<iframe>') {
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.bindMessageOnce = function() {
};
/*@
bindKeyboard <f> bind keyboard
() -> <o> object
@ -400,42 +439,6 @@ Ox.Element = function(options, self) {
return that.nextAll().filter(Ox.UI.isOxElement).map(Ox.UI.getOxElement);
};
/*@
onMessage <f> Adds message handlers (if the element is an iframe)
(callback) -> <o> This element
Adds a catch-all handler
(event, callback) -> <o> This element
Adds a handler for a single event
({event: callback, ...}) -> <o> This element
Adds handlers for multiple events
callback <f> Callback function
data <o> event data (key/value pairs)
event <s> Event name
@*/
that.onMessage = function() {
// FIXME: Implement catch-all handler
var callback;
if (self.options.element == '<iframe>') {
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;
};
/*@
options <f> Gets or sets the options of an element object
() -> <o> All options
@ -444,7 +447,7 @@ Ox.Element = function(options, self) {
Sets options[key] to value and calls update(key, value)
if the key/value pair was added or modified
({key: value, ...}) -> <o> This element
Sets multiple options and calls update(key, value)
Sets one or more options and calls update(key, value)
for every key/value pair that was added or modified
key <s> The name of the option
value <*> The value of the option
@ -549,7 +552,7 @@ Ox.Element = function(options, self) {
(event, data) -> <o> This element object
Triggers an event with data
({event: data, ...}) -> <o> This element object
Triggers multiple events with data
Triggers one or more events with data
event <string> Event name
data <object> Event data (key/value pairs)
@*/
@ -558,6 +561,10 @@ Ox.Element = function(options, self) {
return that;
};
that.triggerMessage = function() {
};
/*@
unbindEvent <f> Removes event handler(s)
() -> <o> This element
@ -570,7 +577,7 @@ Ox.Element = function(options, self) {
(event, callback) -> <o> This element
Removes a specific handler for a single event
({event: callback}, ...) -> <o> This element
Removes specific handlers for multiple events
Removes specific handlers for one or more events
event <string> Event name
@*/
that.unbindEvent = function() {
@ -578,6 +585,10 @@ Ox.Element = function(options, self) {
return that;
};
that.unbindMessage = function() {
};
/*@
unbindKeyboard <f> unbind keyboard
() -> <o> object