From 1b99ab0fc99cce024fb4075d1cc2fb9448c0a9ff Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 28 May 2012 11:30:51 +0200 Subject: [PATCH] cleanup and simplify Ox.JQueryElement --- source/Ox.UI/js/Core/Ox.JQueryElement.js | 36 +++++++++++------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/source/Ox.UI/js/Core/Ox.JQueryElement.js b/source/Ox.UI/js/Core/Ox.JQueryElement.js index cac0ccbe..6d0e8088 100644 --- a/source/Ox.UI/js/Core/Ox.JQueryElement.js +++ b/source/Ox.UI/js/Core/Ox.JQueryElement.js @@ -6,32 +6,30 @@ Ox.JQueryElement Wrapper for jQuery $element jQuery DOM Element @*/ Ox.JQueryElement = function($element) { - var that = this; //@ id Unique id - that.oxid = Ox.uid(); + this.oxid = Ox.uid(); //@ $element The jQuery-wrapped DOM element - that.$element = $element.data({ - oxid: that.oxid + this.$element = $element.data({ + oxid: this.oxid }); - //@ 0 The DOM element - that[0] = that.$element[0]; + //@ 0 The DOM element (for compatibility with jQuery) + this[0] = this.$element[0]; //@ length 1 (for compatibility with jQuery) - that.length = 1; - Ox.UI.elements[that.oxid] = that; - return that; + this.length = 1; + Ox.UI.elements[this.oxid] = this; + return this; }; -// add all jQuery functions to the prototype of Ox.JQueryElement +// add all jQuery methods to the prototype of Ox.JQueryElement Ox.methods($('
'), true).forEach(function(method) { Ox.JQueryElement.prototype[method] = function() { - var args = arguments, oxid, ret, that = this; - ret = that.$element[method].apply(that.$element, args); - // if exactly one $element of an ox object was returned - // then return the ox object instead - // so that we can do oxObj.jqFn().oxFn() - return ret && ret.jquery - && ret.length == 1 - && Ox.UI.elements[oxid = ret.data('oxid')] - ? Ox.UI.elements[oxid] : ret; + var $element = this.$element[method].apply(this.$element, arguments), + oxid; + // if exactly one $element of an Ox object was returned, then return the + // Ox object instead, so that we can do oxObj.jqFn().oxFn() + return $element && $element.jquery + && $element.length == 1 + && Ox.UI.elements[oxid = $element.data('oxid')] + ? Ox.UI.elements[oxid] : $element; }; });