Add tomcat ROOT apps for VMs
[jabaws.git] / VMrootpage / 2.0 / ROOT / js / ui.core.js
1 /*
2  * jQuery UI @VERSION
3  *
4  * Copyright (c) 2008 Paul Bakaus (ui.jquery.com)
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 ;(function($) {
11
12 /** jQuery core modifications and additions **/
13 $.keyCode = {
14         BACKSPACE: 8,
15         CAPS_LOCK: 20,
16         COMMA: 188,
17         CONTROL: 17,
18         DELETE: 46,
19         DOWN: 40,
20         END: 35,
21         ENTER: 13,
22         ESCAPE: 27,
23         HOME: 36,
24         INSERT: 45,
25         LEFT: 37,
26         NUMPAD_ADD: 107,
27         NUMPAD_DECIMAL: 110,
28         NUMPAD_DIVIDE: 111,
29         NUMPAD_ENTER: 108,
30         NUMPAD_MULTIPLY: 106,
31         NUMPAD_SUBTRACT: 109,
32         PAGE_DOWN: 34,
33         PAGE_UP: 33,
34         PERIOD: 190,
35         RIGHT: 39,
36         SHIFT: 16,
37         SPACE: 32,
38         TAB: 9,
39         UP: 38
40 };
41
42 //Temporary mappings
43 var _remove = $.fn.remove;
44 var isFF2 = $.browser.mozilla && (parseFloat($.browser.version) < 1.9);
45
46
47 //Helper functions and ui object
48 $.ui = {
49         
50         version: "@VERSION",
51         
52         // $.ui.plugin is deprecated.  Use the proxy pattern instead.
53         plugin: {
54                 add: function(module, option, set) {
55                         var proto = $.ui[module].prototype;
56                         for(var i in set) {
57                                 proto.plugins[i] = proto.plugins[i] || [];
58                                 proto.plugins[i].push([option, set[i]]);
59                         }
60                 },
61                 call: function(instance, name, args) {
62                         var set = instance.plugins[name];
63                         if(!set) { return; }
64                         
65                         for (var i = 0; i < set.length; i++) {
66                                 if (instance.options[set[i][0]]) {
67                                         set[i][1].apply(instance.element, args);
68                                 }
69                         }
70                 }       
71         },
72         
73         cssCache: {},
74         css: function(name) {
75                 if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
76                 var tmp = $('<div class="ui-gen">').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
77                 
78                 //if (!$.browser.safari)
79                         //tmp.appendTo('body');
80                 
81                 //Opera and Safari set width and height to 0px instead of auto
82                 //Safari returns rgba(0,0,0,0) when bgcolor is not set
83                 $.ui.cssCache[name] = !!(
84                         (!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) || 
85                         !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
86                 );
87                 try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){}
88                 return $.ui.cssCache[name];
89         },
90
91         hasScroll: function(e, a) {
92                 
93                 //If overflow is hidden, the element might have extra content, but the user wants to hide it
94                 if ($(e).css('overflow') == 'hidden') { return false; }
95                 
96                 var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
97                         has = false;
98                 
99                 if (e[scroll] > 0) { return true; }
100                 
101                 // TODO: determine which cases actually cause this to happen
102                 // if the element doesn't have the scroll set, see if it's possible to
103                 // set the scroll
104                 e[scroll] = 1;
105                 has = (e[scroll] > 0);
106                 e[scroll] = 0;
107                 return has;
108         }
109 };
110
111
112 //jQuery plugins
113 $.fn.extend({
114         
115         remove: function() {
116                 // Safari has a native remove event which actually removes DOM elements,
117                 // so we have to use triggerHandler instead of trigger (#3037).
118                 $("*", this).add(this).each(function() {
119                         $(this).triggerHandler("remove");
120                 });
121                 return _remove.apply(this, arguments );
122         },
123         
124         enableSelection: function() {
125                 return this
126                         .attr('unselectable', 'off')
127                         .css('MozUserSelect', '')
128                         .unbind('selectstart.ui');
129         },
130         
131         disableSelection: function() {
132                 return this
133                         .attr('unselectable', 'on')
134                         .css('MozUserSelect', 'none')
135                         .bind('selectstart.ui', function() { return false; });
136         },
137         
138         // WAI-ARIA Semantics
139         ariaRole: function(role) {
140                 return (role !== undefined
141                         
142                         // setter
143                         ? this.attr("role", isFF2 ? "wairole:" + role : role)
144                         
145                         // getter
146                         : (this.attr("role") || "").replace(/^wairole:/, ""));
147         },
148         
149         ariaState: function(state, value) {
150                 return (value !== undefined
151                         
152                         // setter
153                         ? this.each(function(i, el) {
154                                 (isFF2
155                                         ? el.setAttributeNS("http://www.w3.org/2005/07/aaa",
156                                                 "aaa:" + state, value)
157                                         : $(el).attr("aria-" + state, value));
158                         })
159                         
160                         // getter
161                         : this.attr(isFF2 ? "aaa:" + state : "aria-" + state));
162         }
163         
164 });
165
166
167 //Additional selectors
168 $.extend($.expr[':'], {
169         
170         data: function(a, i, m) {
171                 return $.data(a, m[3]);
172         },
173         
174         // TODO: add support for object, area
175         tabbable: function(a, i, m) {
176
177                 var nodeName = a.nodeName.toLowerCase();
178                 var isVisible = function(element) {
179                         function checkStyles(element) {
180                                 var style = element.style;
181                                 return (style.display != 'none' && style.visibility != 'hidden');
182                         }
183                         
184                         var visible = checkStyles(element);
185                         
186                         (visible && $.each($.dir(element, 'parentNode'), function() {
187                                 return (visible = checkStyles(this));
188                         }));
189                         
190                         return visible;
191                 };
192                 
193                 return (
194                         // in tab order
195                         a.tabIndex >= 0 &&
196                         
197                         ( // filter node types that participate in the tab order
198                                 
199                                 // anchor tag
200                                 ('a' == nodeName && a.href) ||
201                                 
202                                 // enabled form element
203                                 (/input|select|textarea|button/.test(nodeName) &&
204                                         'hidden' != a.type && !a.disabled)
205                         ) &&
206                         
207                         // visible on page
208                         isVisible(a)
209                 );
210                 
211         }
212         
213 });
214
215
216 // $.widget is a factory to create jQuery plugins
217 // taking some boilerplate code out of the plugin code
218 // created by Scott González and Jörn Zaefferer
219 function getter(namespace, plugin, method, args) {
220         function getMethods(type) {
221                 var methods = $[namespace][plugin][type] || [];
222                 return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
223         }
224         
225         var methods = getMethods('getter');
226         if (args.length == 1 && typeof args[0] == 'string') {
227                 methods = methods.concat(getMethods('getterSetter'));
228         }
229         return ($.inArray(method, methods) != -1);
230 }
231
232 $.widget = function(name, prototype) {
233         var namespace = name.split(".")[0];
234         name = name.split(".")[1];
235         
236         // create plugin method
237         $.fn[name] = function(options) {
238                 var isMethodCall = (typeof options == 'string'),
239                         args = Array.prototype.slice.call(arguments, 1);
240                 
241                 // prevent calls to internal methods
242                 if (isMethodCall && options.substring(0, 1) == '_') {
243                         return this;
244                 }
245                 
246                 // handle getter methods
247                 if (isMethodCall && getter(namespace, name, options, args)) {
248                         var instance = $.data(this[0], name);
249                         return (instance ? instance[options].apply(instance, args)
250                                 : undefined);
251                 }
252                 
253                 // handle initialization and non-getter methods
254                 return this.each(function() {
255                         var instance = $.data(this, name);
256                         
257                         // constructor
258                         (!instance && !isMethodCall &&
259                                 $.data(this, name, new $[namespace][name](this, options)));
260                         
261                         // method call
262                         (instance && isMethodCall && $.isFunction(instance[options]) &&
263                                 instance[options].apply(instance, args));
264                 });
265         };
266         
267         // create widget constructor
268         $[namespace] = $[namespace] || {};
269         $[namespace][name] = function(element, options) {
270                 var self = this;
271                 
272                 this.widgetName = name;
273                 this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
274                 this.widgetBaseClass = namespace + '-' + name;
275                 
276                 this.options = $.extend({},
277                         $.widget.defaults,
278                         $[namespace][name].defaults,
279                         $.metadata && $.metadata.get(element)[name],
280                         options);
281                 
282                 this.element = $(element)
283                         .bind('setData.' + name, function(e, key, value) {
284                                 return self._setData(key, value);
285                         })
286                         .bind('getData.' + name, function(e, key) {
287                                 return self._getData(key);
288                         })
289                         .bind('remove', function() {
290                                 return self.destroy();
291                         });
292                 
293                 this._init();
294         };
295         
296         // add widget prototype
297         $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
298         
299         // TODO: merge getter and getterSetter properties from widget prototype
300         // and plugin prototype
301         $[namespace][name].getterSetter = 'option';
302 };
303
304 $.widget.prototype = {
305         _init: function() {},
306         destroy: function() {
307                 this.element.removeData(this.widgetName);
308         },
309         
310         option: function(key, value) {
311                 var options = key,
312                         self = this;
313                 
314                 if (typeof key == "string") {
315                         if (value === undefined) {
316                                 return this._getData(key);
317                         }
318                         options = {};
319                         options[key] = value;
320                 }
321                 
322                 $.each(options, function(key, value) {
323                         self._setData(key, value);
324                 });
325         },
326         _getData: function(key) {
327                 return this.options[key];
328         },
329         _setData: function(key, value) {
330                 this.options[key] = value;
331                 
332                 if (key == 'disabled') {
333                         this.element[value ? 'addClass' : 'removeClass'](
334                                 this.widgetBaseClass + '-disabled');
335                 }
336         },
337         
338         enable: function() {
339                 this._setData('disabled', false);
340         },
341         disable: function() {
342                 this._setData('disabled', true);
343         },
344         
345         _trigger: function(type, e, data) {
346                 var eventName = (type == this.widgetEventPrefix
347                         ? type : this.widgetEventPrefix + type);
348                 e = e  || $.event.fix({ type: eventName, target: this.element[0] });
349                 return this.element.triggerHandler(eventName, [e, data], this.options[type]);
350         }
351 };
352
353 $.widget.defaults = {
354         disabled: false
355 };
356
357
358 /** Mouse Interaction Plugin **/
359
360 $.ui.mouse = {
361         _mouseInit: function() {
362                 var self = this;
363         
364                 this.element
365                         .bind('mousedown.'+this.widgetName, function(e) {
366                                 return self._mouseDown(e);
367                         })
368                         .bind('click.'+this.widgetName, function(e) {
369                                 if(self._preventClickEvent) {
370                                         self._preventClickEvent = false;
371                                         return false;
372                                 }
373                         });
374                 
375                 // Prevent text selection in IE
376                 if ($.browser.msie) {
377                         this._mouseUnselectable = this.element.attr('unselectable');
378                         this.element.attr('unselectable', 'on');
379                 }
380                 
381                 this.started = false;
382         },
383         
384         // TODO: make sure destroying one instance of mouse doesn't mess with
385         // other instances of mouse
386         _mouseDestroy: function() {
387                 this.element.unbind('.'+this.widgetName);
388                 
389                 // Restore text selection in IE
390                 ($.browser.msie
391                         && this.element.attr('unselectable', this._mouseUnselectable));
392         },
393         
394         _mouseDown: function(e) {
395                 // we may have missed mouseup (out of window)
396                 (this._mouseStarted && this._mouseUp(e));
397                 
398                 this._mouseDownEvent = e;
399                 
400                 var self = this,
401                         btnIsLeft = (e.which == 1),
402                         elIsCancel = (typeof this.options.cancel == "string" ? $(e.target).parents().add(e.target).filter(this.options.cancel).length : false);
403                 if (!btnIsLeft || elIsCancel || !this._mouseCapture(e)) {
404                         return true;
405                 }
406                 
407                 this.mouseDelayMet = !this.options.delay;
408                 if (!this.mouseDelayMet) {
409                         this._mouseDelayTimer = setTimeout(function() {
410                                 self.mouseDelayMet = true;
411                         }, this.options.delay);
412                 }
413                 
414                 if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
415                         this._mouseStarted = (this._mouseStart(e) !== false);
416                         if (!this._mouseStarted) {
417                                 e.preventDefault();
418                                 return true;
419                         }
420                 }
421                 
422                 // these delegates are required to keep context
423                 this._mouseMoveDelegate = function(e) {
424                         return self._mouseMove(e);
425                 };
426                 this._mouseUpDelegate = function(e) {
427                         return self._mouseUp(e);
428                 };
429                 $(document)
430                         .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
431                         .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
432                 
433                 return false;
434         },
435         
436         _mouseMove: function(e) {
437                 // IE mouseup check - mouseup happened when mouse was out of window
438                 if ($.browser.msie && !e.button) {
439                         return this._mouseUp(e);
440                 }
441                 
442                 if (this._mouseStarted) {
443                         this._mouseDrag(e);
444                         return false;
445                 }
446                 
447                 if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
448                         this._mouseStarted =
449                                 (this._mouseStart(this._mouseDownEvent, e) !== false);
450                         (this._mouseStarted ? this._mouseDrag(e) : this._mouseUp(e));
451                 }
452                 
453                 return !this._mouseStarted;
454         },
455         
456         _mouseUp: function(e) {
457                 $(document)
458                         .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
459                         .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
460                 
461                 if (this._mouseStarted) {
462                         this._mouseStarted = false;
463                         this._preventClickEvent = true;
464                         this._mouseStop(e);
465                 }
466                 
467                 return false;
468         },
469         
470         _mouseDistanceMet: function(e) {
471                 return (Math.max(
472                                 Math.abs(this._mouseDownEvent.pageX - e.pageX),
473                                 Math.abs(this._mouseDownEvent.pageY - e.pageY)
474                         ) >= this.options.distance
475                 );
476         },
477         
478         _mouseDelayMet: function(e) {
479                 return this.mouseDelayMet;
480         },
481         
482         // These are placeholder methods, to be overriden by extending plugin
483         _mouseStart: function(e) {},
484         _mouseDrag: function(e) {},
485         _mouseStop: function(e) {},
486         _mouseCapture: function(e) { return true; }
487 };
488
489 $.ui.mouse.defaults = {
490         cancel: null,
491         distance: 1,
492         delay: 0
493 };
494
495 })(jQuery);