4 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
8 * http://docs.jquery.com/UI
13 // prevent duplicate loading
14 // this is only a problem because we proxy existing functions
15 // and we don't want to double proxy them
21 //Helper functions and ui object
25 // $.ui.plugin is deprecated. Use the proxy pattern instead.
27 add: function(module
, option
, set) {
28 var proto
= $.ui
[module
].prototype;
30 proto
.plugins
[i
] = proto
.plugins
[i
] || [];
31 proto
.plugins
[i
].push([option
, set[i
]]);
34 call: function(instance
, name
, args
) {
35 var set = instance
.plugins
[name
];
36 if(!set || !instance
.element
[0].parentNode
) { return; }
38 for (var i
= 0; i
< set.length
; i
++) {
39 if (instance
.options
[set[i
][0]]) {
40 set[i
][1].apply(instance
.element
, args
);
46 contains: function(a
, b
) {
47 return document
.compareDocumentPosition
48 ? a
.compareDocumentPosition(b
) & 16
49 : a
!== b
&& a
.contains(b
);
52 hasScroll: function(el
, a
) {
54 //If overflow is hidden, the element might have extra content, but the user wants to hide it
55 if ($(el
).css('overflow') == 'hidden') { return false; }
57 var scroll
= (a
&& a
== 'left') ? 'scrollLeft' : 'scrollTop',
60 if (el
[scroll
] > 0) { return true; }
62 // TODO: determine which cases actually cause this to happen
63 // if the element doesn't have the scroll set, see if it's possible to
66 has
= (el
[scroll
] > 0);
71 isOverAxis: function(x
, reference
, size
) {
72 //Determines when x coordinate is over "b" element axis
73 return (x
> reference
) && (x
< (reference
+ size
));
76 isOver: function(y
, x
, top
, left
, height
, width
) {
77 //Determines when x, y coordinates is over "b" element
78 return $.ui
.isOverAxis(y
, top
, height
) && $.ui
.isOverAxis(x
, left
, width
);
87 COMMAND_LEFT
: 91, // COMMAND
98 MENU
: 93, // COMMAND_RIGHT
103 NUMPAD_MULTIPLY
: 106,
104 NUMPAD_SUBTRACT
: 109,
113 WINDOWS
: 91 // COMMAND
120 focus: function(delay
, fn
) {
121 return typeof delay
=== 'number'
122 ? this.each(function() {
124 setTimeout(function() {
126 (fn
&& fn
.call(elem
));
129 : this._focus
.apply(this, arguments
);
132 enableSelection: function() {
134 .attr('unselectable', 'off')
135 .css('MozUserSelect', '');
138 disableSelection: function() {
140 .attr('unselectable', 'on')
141 .css('MozUserSelect', 'none');
144 scrollParent: function() {
146 if(($.browser
.msie
&& (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
147 scrollParent
= this.parents().filter(function() {
148 return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
151 scrollParent
= this.parents().filter(function() {
152 return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
156 return (/fixed/).test(this.css('position')) || !scrollParent
.length
? $(document
) : scrollParent
;
159 zIndex: function(zIndex
) {
160 if (zIndex
!== undefined) {
161 return this.css('zIndex', zIndex
);
165 var elem
= $(this[0]), position
, value
;
166 while (elem
.length
&& elem
[0] !== document
) {
167 // Ignore z-index if position is set to a value where z-index is ignored by the browser
168 // This makes behavior of this function consistent across browsers
169 // WebKit always returns auto if the element is positioned
170 position
= elem
.css('position');
171 if (position
== 'absolute' || position
== 'relative' || position
== 'fixed')
173 // IE returns 0 when zIndex is not specified
174 // other browsers return a string
175 // we ignore the case of nested elements with an explicit value of 0
176 // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
177 value
= parseInt(elem
.css('zIndex'));
178 if (!isNaN(value
) && value
!= 0) {
182 elem
= elem
.parent();
191 //Additional selectors
192 $.extend($.expr
[':'], {
193 data: function(elem
, i
, match
) {
194 return !!$.data(elem
, match
[3]);
197 focusable: function(element
) {
198 var nodeName
= element
.nodeName
.toLowerCase(),
199 tabIndex
= $.attr(element
, 'tabindex');
200 return (/input|select|textarea|button|object/.test(nodeName
)
202 : 'a' == nodeName
|| 'area' == nodeName
203 ? element
.href
|| !isNaN(tabIndex
)
205 // the element and all of its ancestors must be visible
206 // the browser may report that the area is hidden
207 && !$(element
)['area' == nodeName
? 'parents' : 'closest'](':hidden').length
;
210 tabbable: function(element
) {
211 var tabIndex
= $.attr(element
, 'tabindex');
212 return (isNaN(tabIndex
) || tabIndex
>= 0) && $(element
).is(':focusable');