oxjs/source/Ox.UI/js/Core/JQueryElement.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2011-05-05 18:02:56 +00:00
/*@
2012-05-22 13:14:40 +00:00
Ox.JQueryElement <f> Wrapper for jQuery
2012-06-02 09:48:47 +00:00
($element) -> <o> Wrapped jQuery DOM element
$element <o> jQuery DOM Element
2011-05-05 18:02:56 +00:00
@*/
2011-04-22 22:03:10 +00:00
Ox.JQueryElement = function($element) {
2012-06-02 12:10:47 +00:00
//@ id <n> Unique id
2012-05-28 09:30:51 +00:00
this.oxid = Ox.uid();
2012-06-02 12:10:47 +00:00
//@ $element <o> The jQuery-wrapped DOM element
2012-05-28 19:35:41 +00:00
this.$element = $element.data({oxid: this.oxid});
2012-06-02 12:10:47 +00:00
//@ 0 <h> The DOM element (for compatibility with jQuery)
2012-05-28 09:30:51 +00:00
this[0] = this.$element[0];
2012-06-02 12:10:47 +00:00
//@ length <n> 1 (for compatibility with jQuery)
2012-05-28 09:30:51 +00:00
this.length = 1;
Ox.UI.elements[this.oxid] = this;
return this;
2011-04-22 22:03:10 +00:00
};
2011-04-25 09:12:02 +00:00
2012-05-28 09:30:51 +00:00
// add all jQuery methods to the prototype of Ox.JQueryElement
2012-05-21 20:07:40 +00:00
Ox.methods($('<div>'), true).forEach(function(method) {
Ox.JQueryElement.prototype[method] = function() {
2012-05-28 09:30:51 +00:00
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()
2012-05-28 14:04:50 +00:00
return $element && $element.jquery && $element.length == 1
2012-05-28 09:30:51 +00:00
&& Ox.UI.elements[oxid = $element.data('oxid')]
? Ox.UI.elements[oxid] : $element;
2012-05-21 20:07:40 +00:00
};
2012-05-22 13:14:40 +00:00
});