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

35 lines
1.2 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
2011-05-05 18:02:56 +00:00
($element) -> <object> Wrapped jQuery DOM element
$element <object> jQuery DOM Element
@*/
2011-04-22 22:03:10 +00:00
Ox.JQueryElement = function($element) {
2011-05-07 17:52:33 +00:00
//@ id <number> Unique id
2012-05-28 09:30:51 +00:00
this.oxid = Ox.uid();
2011-08-23 21:31:08 +00:00
//@ $element <object> The jQuery-wrapped DOM element
2012-05-28 09:30:51 +00:00
this.$element = $element.data({
oxid: this.oxid
2011-04-22 22:03:10 +00:00
});
2012-05-28 09:30:51 +00:00
//@ 0 <element> The DOM element (for compatibility with jQuery)
this[0] = this.$element[0];
2011-08-23 21:31:08 +00:00
//@ length <number> 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
});