From 27d8a6682ee486b50902ad86299b603e16985a6d Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 6 Dec 2013 20:51:59 +0100 Subject: [PATCH] Ox.Element: add methods childrenElements, findElements, nextElement, nextElements, parentElement, parentElements, prevElement, prevElements --- source/Ox.UI/js/Core/Element.js | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/source/Ox.UI/js/Core/Element.js b/source/Ox.UI/js/Core/Element.js index 0a6008f3..dace5d0a 100644 --- a/source/Ox.UI/js/Core/Element.js +++ b/source/Ox.UI/js/Core/Element.js @@ -340,6 +340,10 @@ Ox.Element = function(options, self) { return that; }; + that.childrenElements = function() { + return that.children().filter(Ox.UI.isOxElement).map(Ox.UI.getOxElement); + }; + /*@ defaults Gets or sets the default options for an element object ({key: value, ...}) -> This element object @@ -360,6 +364,10 @@ Ox.Element = function(options, self) { return ret; }; + that.findElements = function() { + return Ox.map(that.find('.OxElement'), Ox.UI.getOxElement); + }; + /*@ gainFocus Makes an element object gain focus () -> This element object @@ -386,6 +394,14 @@ Ox.Element = function(options, self) { return that; }; + that.nextElement = function() { + return that.nextElements()[0]; + }; + + that.nextElements = function() { + return that.nextAll().filter(Ox.UI.isOxElement).map(Ox.UI.getOxElement); + }; + /*@ onMessage Adds message handlers (if the element is an iframe) (callback) -> This element @@ -439,6 +455,14 @@ Ox.Element = function(options, self) { return Ox.getset(self.options, arguments, update, that); }; + that.parentElement = function() { + return Ox.last(that.parentElements()); + }; + + that.parentElements = function() { + return that.parents().filter(Ox.UI.isOxElement).map(Ox.UI.getOxElement); + }; + /*@ postMessage Sends a message (if the element is an iframe) (event, data) -> This element @@ -452,8 +476,16 @@ Ox.Element = function(options, self) { return that; }; + that.prevElement = function() { + return Ox.last(that.prevElements()); + }; + + that.prevElements = function() { + return that.prevAll().filter(Ox.UI.isOxElement).map(Ox.UI.getOxElement); + }; + /*@ - removeElement Removes an element object and its event handler + remove Removes an element object and its event handler () -> This element @*/ that.remove = function(remove) { @@ -469,6 +501,24 @@ Ox.Element = function(options, self) { return that; }; + /* + that.remove = function() { + [that].concat(that.find('.OxElement')) + .map(Ox.UI.getOxElement).forEach(function($element) { + $element.removeElement(); + }); + that[0].parentNode.removeChild(this[0]); + return that; + } + + that.removeElement = function() { + delete Ox.$elements[that.oxid]; + Ox.Focus.remove(that); + self.unbindKeyboard(); + return that; + }; + */ + /*@ setElement set $element ($element) -> This element