Merging resourceloader branch into trunk. Full documentation is at http://www.mediawi...
[lhc/web/wiklou.git] / resources / jquery.ui / jquery.ui.core.js
1 /*!
2 * jQuery UI 1.8.2
3 *
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.
7 *
8 * http://docs.jquery.com/UI
9 */
10
11 (function($) {
12
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
16 $.ui = $.ui || {};
17 if ($.ui.version) {
18 return;
19 }
20
21 //Helper functions and ui object
22 $.extend($.ui, {
23 version: "1.8.2",
24
25 // $.ui.plugin is deprecated. Use the proxy pattern instead.
26 plugin: {
27 add: function(module, option, set) {
28 var proto = $.ui[module].prototype;
29 for(var i in set) {
30 proto.plugins[i] = proto.plugins[i] || [];
31 proto.plugins[i].push([option, set[i]]);
32 }
33 },
34 call: function(instance, name, args) {
35 var set = instance.plugins[name];
36 if(!set || !instance.element[0].parentNode) { return; }
37
38 for (var i = 0; i < set.length; i++) {
39 if (instance.options[set[i][0]]) {
40 set[i][1].apply(instance.element, args);
41 }
42 }
43 }
44 },
45
46 contains: function(a, b) {
47 return document.compareDocumentPosition
48 ? a.compareDocumentPosition(b) & 16
49 : a !== b && a.contains(b);
50 },
51
52 hasScroll: function(el, a) {
53
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; }
56
57 var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
58 has = false;
59
60 if (el[scroll] > 0) { return true; }
61
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
64 // set the scroll
65 el[scroll] = 1;
66 has = (el[scroll] > 0);
67 el[scroll] = 0;
68 return has;
69 },
70
71 isOverAxis: function(x, reference, size) {
72 //Determines when x coordinate is over "b" element axis
73 return (x > reference) && (x < (reference + size));
74 },
75
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);
79 },
80
81 keyCode: {
82 ALT: 18,
83 BACKSPACE: 8,
84 CAPS_LOCK: 20,
85 COMMA: 188,
86 COMMAND: 91,
87 COMMAND_LEFT: 91, // COMMAND
88 COMMAND_RIGHT: 93,
89 CONTROL: 17,
90 DELETE: 46,
91 DOWN: 40,
92 END: 35,
93 ENTER: 13,
94 ESCAPE: 27,
95 HOME: 36,
96 INSERT: 45,
97 LEFT: 37,
98 MENU: 93, // COMMAND_RIGHT
99 NUMPAD_ADD: 107,
100 NUMPAD_DECIMAL: 110,
101 NUMPAD_DIVIDE: 111,
102 NUMPAD_ENTER: 108,
103 NUMPAD_MULTIPLY: 106,
104 NUMPAD_SUBTRACT: 109,
105 PAGE_DOWN: 34,
106 PAGE_UP: 33,
107 PERIOD: 190,
108 RIGHT: 39,
109 SHIFT: 16,
110 SPACE: 32,
111 TAB: 9,
112 UP: 38,
113 WINDOWS: 91 // COMMAND
114 }
115 });
116
117 //jQuery plugins
118 $.fn.extend({
119 _focus: $.fn.focus,
120 focus: function(delay, fn) {
121 return typeof delay === 'number'
122 ? this.each(function() {
123 var elem = this;
124 setTimeout(function() {
125 $(elem).focus();
126 (fn && fn.call(elem));
127 }, delay);
128 })
129 : this._focus.apply(this, arguments);
130 },
131
132 enableSelection: function() {
133 return this
134 .attr('unselectable', 'off')
135 .css('MozUserSelect', '');
136 },
137
138 disableSelection: function() {
139 return this
140 .attr('unselectable', 'on')
141 .css('MozUserSelect', 'none');
142 },
143
144 scrollParent: function() {
145 var scrollParent;
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));
149 }).eq(0);
150 } else {
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));
153 }).eq(0);
154 }
155
156 return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
157 },
158
159 zIndex: function(zIndex) {
160 if (zIndex !== undefined) {
161 return this.css('zIndex', zIndex);
162 }
163
164 if (this.length) {
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')
172 {
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) {
179 return value;
180 }
181 }
182 elem = elem.parent();
183 }
184 }
185
186 return 0;
187 }
188 });
189
190
191 //Additional selectors
192 $.extend($.expr[':'], {
193 data: function(elem, i, match) {
194 return !!$.data(elem, match[3]);
195 },
196
197 focusable: function(element) {
198 var nodeName = element.nodeName.toLowerCase(),
199 tabIndex = $.attr(element, 'tabindex');
200 return (/input|select|textarea|button|object/.test(nodeName)
201 ? !element.disabled
202 : 'a' == nodeName || 'area' == nodeName
203 ? element.href || !isNaN(tabIndex)
204 : !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;
208 },
209
210 tabbable: function(element) {
211 var tabIndex = $.attr(element, 'tabindex');
212 return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
213 }
214 });
215
216 })(jQuery);