From 1cf1dea2f52ec40ac567b8f889351d64abd6164f Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Wed, 24 Sep 2014 13:03:33 +0200 Subject: [PATCH] Ox.Element: more paranoid findElement; more documentation; catch a bug in removeElements that occurs when browsing items in oxjs documentation panel --- source/Ox.UI/js/Core/Element.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/source/Ox.UI/js/Core/Element.js b/source/Ox.UI/js/Core/Element.js index f33d9b14..9889f77c 100644 --- a/source/Ox.UI/js/Core/Element.js +++ b/source/Ox.UI/js/Core/Element.js @@ -374,6 +374,7 @@ data event data (key/value pairs) event Event name Event names can be namespaced, like `'click.foo'` + callback Callback function @*/ Ox.Element.prototype.bindEvent = function bindEvent() { Ox.Event.bind.apply(this, [this.self(_)].concat(Ox.slice(arguments))); @@ -392,6 +393,7 @@ data event data (key/value pairs) event Event name Event names can be namespaced, like `'click.foo'` + callback Callback function @*/ Ox.Element.prototype.bindEventOnce = function bindEventOnce() { Ox.Event.bindOnce.apply( @@ -408,9 +410,11 @@ Adds a handler for a single message ({message: callback, ...}) -> This element object Adds handlers for one or more messages + message Message name callback Callback function data Message data (key/value pairs) - message Message name + event Event name + element Element object @*/ Ox.Element.prototype.bindMessage = Ox.Element.prototype.onMessage = function bindMessage() { var self = this.self(_); @@ -428,9 +432,11 @@ Adds a handler for a single message ({message: callback, ...}) -> This element object Adds handlers for one or more messages + event Message name callback Callback function data Message data (key/value pairs) - event Message name + event Event name + element Element object @*/ Ox.Element.prototype.bindMessageOnce = Ox.Element.prototype.onMessageOnce = function bindMessageOnce() { var self = this.self(_); @@ -486,7 +492,9 @@ () -> <[o]> Array of element objects @*/ 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) { if (includeChildren !== false) { this.findElements().forEach(function($element) { + if (!$element) { + Ox.print( + '*** Found undefined descendant element,' + + ' this should never happen. ***' + ); + return; + } $element.removeElement(false); }); } @@ -692,7 +707,7 @@ }; /*@ - triggerEvent Triggers one or more events + triggerEvent Triggers all handlers for one or more events (event) -> This element object Triggers an event (event, data) -> This element object @@ -710,7 +725,7 @@ }; /*@ - triggerMessage Triggers one or more messages + triggerMessage Triggers all handlers for one or more messages (message) -> This element object Triggers an event (message, data) -> This element object @@ -741,7 +756,8 @@ Removes a specific handler for a single event ({event: callback}, ...) -> This element object Removes specific handlers for one or more events - event Event name + event Event name + callback Event handler @*/ Ox.Element.prototype.unbindEvent = function unbindEvent() { Ox.Event.unbind.apply(this, [this.self(_)].concat(Ox.slice(arguments))); @@ -761,7 +777,8 @@ Removes a specific handler for a single event ({message: callback}, ...) -> This element object Removes specific handlers for one or more messages - message Message name + message Message name + callback Message handler @*/ Ox.Element.prototype.unbindMessage = function unbindMessage() { var self = this.self(_);