~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to lib/jquery/jquery.ui-1.6rc2/ui/ui.core.js

  • Committer: V. Keith Hughitt
  • Date: 2009-03-26 19:20:57 UTC
  • Revision ID: hughitt1@kore-20090326192057-u0x8rf8sf5lmmnwh
nightly build 03-26-2009: Using alpha-channel JPEG 2000 dataset

Show diffs side-by-side

added added

removed removed

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