Ox.Element: more paranoid findElement; more documentation; catch a bug in removeElements that occurs when browsing items in oxjs documentation panel

This commit is contained in:
rlx 2014-09-24 13:03:33 +02:00
parent 8018ba499f
commit 1cf1dea2f5

View file

@ -374,6 +374,7 @@
data <o> event data (key/value pairs) data <o> event data (key/value pairs)
event <s> Event name event <s> Event name
Event names can be namespaced, like `'click.foo'` Event names can be namespaced, like `'click.foo'`
callback <f> Callback function
@*/ @*/
Ox.Element.prototype.bindEvent = function bindEvent() { Ox.Element.prototype.bindEvent = function bindEvent() {
Ox.Event.bind.apply(this, [this.self(_)].concat(Ox.slice(arguments))); Ox.Event.bind.apply(this, [this.self(_)].concat(Ox.slice(arguments)));
@ -392,6 +393,7 @@
data <o> event data (key/value pairs) data <o> event data (key/value pairs)
event <s> Event name event <s> Event name
Event names can be namespaced, like `'click.foo'` Event names can be namespaced, like `'click.foo'`
callback <f> Callback function
@*/ @*/
Ox.Element.prototype.bindEventOnce = function bindEventOnce() { Ox.Element.prototype.bindEventOnce = function bindEventOnce() {
Ox.Event.bindOnce.apply( Ox.Event.bindOnce.apply(
@ -408,9 +410,11 @@
Adds a handler for a single message Adds a handler for a single message
({message: callback, ...}) -> <o> This element object ({message: callback, ...}) -> <o> This element object
Adds handlers for one or more messages Adds handlers for one or more messages
message <s> Message name
callback <f> Callback function callback <f> Callback function
data <o> Message data (key/value pairs) data <o> Message data (key/value pairs)
message <s> Message name event <s> Event name
element <o> Element object
@*/ @*/
Ox.Element.prototype.bindMessage = Ox.Element.prototype.onMessage = function bindMessage() { Ox.Element.prototype.bindMessage = Ox.Element.prototype.onMessage = function bindMessage() {
var self = this.self(_); var self = this.self(_);
@ -428,9 +432,11 @@
Adds a handler for a single message Adds a handler for a single message
({message: callback, ...}) -> <o> This element object ({message: callback, ...}) -> <o> This element object
Adds handlers for one or more messages Adds handlers for one or more messages
event <s> Message name
callback <f> Callback function callback <f> Callback function
data <o> Message data (key/value pairs) data <o> Message data (key/value pairs)
event <s> Message name event <s> Event name
element <o> Element object
@*/ @*/
Ox.Element.prototype.bindMessageOnce = Ox.Element.prototype.onMessageOnce = function bindMessageOnce() { Ox.Element.prototype.bindMessageOnce = Ox.Element.prototype.onMessageOnce = function bindMessageOnce() {
var self = this.self(_); var self = this.self(_);
@ -486,7 +492,9 @@
() -> <[o]> Array of element objects () -> <[o]> Array of element objects
@*/ @*/
Ox.Element.prototype.findElements = function findElements() { Ox.Element.prototype.findElements = function findElements() {
return Ox.slice(this.find('.OxElement')).map(Ox.getOxElement); return Ox.slice(this.find('.OxElement'))
.filter(Ox.isOxElement)
.map(Ox.getOxElement);
}; };
/*@ /*@
@ -619,6 +627,13 @@
Ox.Element.prototype.removeElement = function removeElement(includeChildren) { Ox.Element.prototype.removeElement = function removeElement(includeChildren) {
if (includeChildren !== false) { if (includeChildren !== false) {
this.findElements().forEach(function($element) { this.findElements().forEach(function($element) {
if (!$element) {
Ox.print(
'*** Found undefined descendant element,'
+ ' this should never happen. ***'
);
return;
}
$element.removeElement(false); $element.removeElement(false);
}); });
} }
@ -692,7 +707,7 @@
}; };
/*@ /*@
triggerEvent <f> Triggers one or more events triggerEvent <f> Triggers all handlers for one or more events
(event) -> <o> This element object (event) -> <o> This element object
Triggers an event Triggers an event
(event, data) -> <o> This element object (event, data) -> <o> This element object
@ -710,7 +725,7 @@
}; };
/*@ /*@
triggerMessage <f> Triggers one or more messages triggerMessage <f> Triggers all handlers for one or more messages
(message) -> <o> This element object (message) -> <o> This element object
Triggers an event Triggers an event
(message, data) -> <o> This element object (message, data) -> <o> This element object
@ -741,7 +756,8 @@
Removes a specific handler for a single event Removes a specific handler for a single event
({event: callback}, ...) -> <o> This element object ({event: callback}, ...) -> <o> This element object
Removes specific handlers for one or more events Removes specific handlers for one or more events
event <string> Event name event <s> Event name
callback <f> Event handler
@*/ @*/
Ox.Element.prototype.unbindEvent = function unbindEvent() { Ox.Element.prototype.unbindEvent = function unbindEvent() {
Ox.Event.unbind.apply(this, [this.self(_)].concat(Ox.slice(arguments))); Ox.Event.unbind.apply(this, [this.self(_)].concat(Ox.slice(arguments)));
@ -761,7 +777,8 @@
Removes a specific handler for a single event Removes a specific handler for a single event
({message: callback}, ...) -> <o> This element object ({message: callback}, ...) -> <o> This element object
Removes specific handlers for one or more messages Removes specific handlers for one or more messages
message <string> Message name message <s> Message name
callback <f> Message handler
@*/ @*/
Ox.Element.prototype.unbindMessage = function unbindMessage() { Ox.Element.prototype.unbindMessage = function unbindMessage() {
var self = this.self(_); var self = this.self(_);