source: web/old/jquery-ui-personalized-1.6rc6.js @ 30beeab

debianmacno-cupsweb
Last change on this file since 30beeab was 30beeab, checked in by Jessica B. Hamrick <jhamrick@…>, 14 years ago

Remove "gutenbach-" from directory names and rename "gutenbach" to "gutenbach-server"

  • Property mode set to 100644
File size: 26.8 KB
Line 
1/*
2 * jQuery UI 1.6rc6
3 *
4 * Copyright (c) 2009 AUTHORS.txt (http://ui.jquery.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;(function($) {
11
12var _remove = $.fn.remove,
13        isFF2 = $.browser.mozilla && (parseFloat($.browser.version) < 1.9);
14
15//Helper functions and ui object
16$.ui = {
17        version: "1.6rc6",
18
19        // $.ui.plugin is deprecated.  Use the proxy pattern instead.
20        plugin: {
21                add: function(module, option, set) {
22                        var proto = $.ui[module].prototype;
23                        for(var i in set) {
24                                proto.plugins[i] = proto.plugins[i] || [];
25                                proto.plugins[i].push([option, set[i]]);
26                        }
27                },
28                call: function(instance, name, args) {
29                        var set = instance.plugins[name];
30                        if(!set) { return; }
31
32                        for (var i = 0; i < set.length; i++) {
33                                if (instance.options[set[i][0]]) {
34                                        set[i][1].apply(instance.element, args);
35                                }
36                        }
37                }
38        },
39
40        contains: function(a, b) {
41                return document.compareDocumentPosition
42                        ? a.compareDocumentPosition(b) & 16
43                        : a !== b && a.contains(b);
44        },
45
46        cssCache: {},
47        css: function(name) {
48                if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
49                var tmp = $('<div class="ui-gen"></div>').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
50
51                //if (!$.browser.safari)
52                        //tmp.appendTo('body');
53
54                //Opera and Safari set width and height to 0px instead of auto
55                //Safari returns rgba(0,0,0,0) when bgcolor is not set
56                $.ui.cssCache[name] = !!(
57                        (!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) ||
58                        !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
59                );
60                try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){}
61                return $.ui.cssCache[name];
62        },
63
64        hasScroll: function(el, a) {
65
66                //If overflow is hidden, the element might have extra content, but the user wants to hide it
67                if ($(el).css('overflow') == 'hidden') { return false; }
68
69                var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
70                        has = false;
71
72                if (el[scroll] > 0) { return true; }
73
74                // TODO: determine which cases actually cause this to happen
75                // if the element doesn't have the scroll set, see if it's possible to
76                // set the scroll
77                el[scroll] = 1;
78                has = (el[scroll] > 0);
79                el[scroll] = 0;
80                return has;
81        },
82
83        isOverAxis: function(x, reference, size) {
84                //Determines when x coordinate is over "b" element axis
85                return (x > reference) && (x < (reference + size));
86        },
87
88        isOver: function(y, x, top, left, height, width) {
89                //Determines when x, y coordinates is over "b" element
90                return $.ui.isOverAxis(y, top, height) && $.ui.isOverAxis(x, left, width);
91        },
92
93        keyCode: {
94                BACKSPACE: 8,
95                CAPS_LOCK: 20,
96                COMMA: 188,
97                CONTROL: 17,
98                DELETE: 46,
99                DOWN: 40,
100                END: 35,
101                ENTER: 13,
102                ESCAPE: 27,
103                HOME: 36,
104                INSERT: 45,
105                LEFT: 37,
106                NUMPAD_ADD: 107,
107                NUMPAD_DECIMAL: 110,
108                NUMPAD_DIVIDE: 111,
109                NUMPAD_ENTER: 108,
110                NUMPAD_MULTIPLY: 106,
111                NUMPAD_SUBTRACT: 109,
112                PAGE_DOWN: 34,
113                PAGE_UP: 33,
114                PERIOD: 190,
115                RIGHT: 39,
116                SHIFT: 16,
117                SPACE: 32,
118                TAB: 9,
119                UP: 38
120        }
121};
122
123// WAI-ARIA normalization
124if (isFF2) {
125        var attr = $.attr,
126                removeAttr = $.fn.removeAttr,
127                ariaNS = "http://www.w3.org/2005/07/aaa",
128                ariaState = /^aria-/,
129                ariaRole = /^wairole:/;
130
131        $.attr = function(elem, name, value) {
132                var set = value !== undefined;
133
134                return (name == 'role'
135                        ? (set
136                                ? attr.call(this, elem, name, "wairole:" + value)
137                                : (attr.apply(this, arguments) || "").replace(ariaRole, ""))
138                        : (ariaState.test(name)
139                                ? (set
140                                        ? elem.setAttributeNS(ariaNS,
141                                                name.replace(ariaState, "aaa:"), value)
142                                        : attr.call(this, elem, name.replace(ariaState, "aaa:")))
143                                : attr.apply(this, arguments)));
144        };
145
146        $.fn.removeAttr = function(name) {
147                return (ariaState.test(name)
148                        ? this.each(function() {
149                                this.removeAttributeNS(ariaNS, name.replace(ariaState, ""));
150                        }) : removeAttr.call(this, name));
151        };
152}
153
154//jQuery plugins
155$.fn.extend({
156        remove: function() {
157                // Safari has a native remove event which actually removes DOM elements,
158                // so we have to use triggerHandler instead of trigger (#3037).
159                $("*", this).add(this).each(function() {
160                        $(this).triggerHandler("remove");
161                });
162                return _remove.apply(this, arguments );
163        },
164
165        enableSelection: function() {
166                return this
167                        .attr('unselectable', 'off')
168                        .css('MozUserSelect', '')
169                        .unbind('selectstart.ui');
170        },
171
172        disableSelection: function() {
173                return this
174                        .attr('unselectable', 'on')
175                        .css('MozUserSelect', 'none')
176                        .bind('selectstart.ui', function() { return false; });
177        },
178
179        scrollParent: function() {
180                var scrollParent;
181                if(($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
182                        scrollParent = this.parents().filter(function() {
183                                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));
184                        }).eq(0);
185                } else {
186                        scrollParent = this.parents().filter(function() {
187                                return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
188                        }).eq(0);
189                }
190
191                return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
192        }
193});
194
195
196//Additional selectors
197$.extend($.expr[':'], {
198        data: function(elem, i, match) {
199                return !!$.data(elem, match[3]);
200        },
201
202        focusable: function(element) {
203                var nodeName = element.nodeName.toLowerCase(),
204                        tabIndex = $.attr(element, 'tabindex');
205                return (/input|select|textarea|button|object/.test(nodeName)
206                        ? !element.disabled
207                        : 'a' == nodeName || 'area' == nodeName
208                                ? element.href || !isNaN(tabIndex)
209                                : !isNaN(tabIndex))
210                        // the element and all of its ancestors must be visible
211                        // the browser may report that the area is hidden
212                        && !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
213        },
214
215        tabbable: function(element) {
216                var tabIndex = $.attr(element, 'tabindex');
217                return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
218        }
219});
220
221
222// $.widget is a factory to create jQuery plugins
223// taking some boilerplate code out of the plugin code
224function getter(namespace, plugin, method, args) {
225        function getMethods(type) {
226                var methods = $[namespace][plugin][type] || [];
227                return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
228        }
229
230        var methods = getMethods('getter');
231        if (args.length == 1 && typeof args[0] == 'string') {
232                methods = methods.concat(getMethods('getterSetter'));
233        }
234        return ($.inArray(method, methods) != -1);
235}
236
237$.widget = function(name, prototype) {
238        var namespace = name.split(".")[0];
239        name = name.split(".")[1];
240
241        // create plugin method
242        $.fn[name] = function(options) {
243                var isMethodCall = (typeof options == 'string'),
244                        args = Array.prototype.slice.call(arguments, 1);
245
246                // prevent calls to internal methods
247                if (isMethodCall && options.substring(0, 1) == '_') {
248                        return this;
249                }
250
251                // handle getter methods
252                if (isMethodCall && getter(namespace, name, options, args)) {
253                        var instance = $.data(this[0], name);
254                        return (instance ? instance[options].apply(instance, args)
255                                : undefined);
256                }
257
258                // handle initialization and non-getter methods
259                return this.each(function() {
260                        var instance = $.data(this, name);
261
262                        // constructor
263                        (!instance && !isMethodCall &&
264                                $.data(this, name, new $[namespace][name](this, options))._init());
265
266                        // method call
267                        (instance && isMethodCall && $.isFunction(instance[options]) &&
268                                instance[options].apply(instance, args));
269                });
270        };
271
272        // create widget constructor
273        $[namespace] = $[namespace] || {};
274        $[namespace][name] = function(element, options) {
275                var self = this;
276
277                this.namespace = namespace;
278                this.widgetName = name;
279                this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
280                this.widgetBaseClass = namespace + '-' + name;
281
282                this.options = $.extend({},
283                        $.widget.defaults,
284                        $[namespace][name].defaults,
285                        $.metadata && $.metadata.get(element)[name],
286                        options);
287
288                this.element = $(element)
289                        .bind('setData.' + name, function(event, key, value) {
290                                if (event.target == element) {
291                                        return self._setData(key, value);
292                                }
293                        })
294                        .bind('getData.' + name, function(event, key) {
295                                if (event.target == element) {
296                                        return self._getData(key);
297                                }
298                        })
299                        .bind('remove', function() {
300                                return self.destroy();
301                        });
302        };
303
304        // add widget prototype
305        $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
306
307        // TODO: merge getter and getterSetter properties from widget prototype
308        // and plugin prototype
309        $[namespace][name].getterSetter = 'option';
310};
311
312$.widget.prototype = {
313        _init: function() {},
314        destroy: function() {
315                this.element.removeData(this.widgetName)
316                        .removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled')
317                        .removeAttr('aria-disabled');
318        },
319
320        option: function(key, value) {
321                var options = key,
322                        self = this;
323
324                if (typeof key == "string") {
325                        if (value === undefined) {
326                                return this._getData(key);
327                        }
328                        options = {};
329                        options[key] = value;
330                }
331
332                $.each(options, function(key, value) {
333                        self._setData(key, value);
334                });
335        },
336        _getData: function(key) {
337                return this.options[key];
338        },
339        _setData: function(key, value) {
340                this.options[key] = value;
341
342                if (key == 'disabled') {
343                        this.element
344                                [value ? 'addClass' : 'removeClass'](
345                                        this.widgetBaseClass + '-disabled' + ' ' +
346                                        this.namespace + '-state-disabled')
347                                .attr("aria-disabled", value);
348                }
349        },
350
351        enable: function() {
352                this._setData('disabled', false);
353        },
354        disable: function() {
355                this._setData('disabled', true);
356        },
357
358        _trigger: function(type, event, data) {
359                var callback = this.options[type],
360                        eventName = (type == this.widgetEventPrefix
361                                ? type : this.widgetEventPrefix + type);
362
363                event = $.Event(event);
364                event.type = eventName;
365
366                // copy original event properties over to the new event
367                // this would happen if we could call $.event.fix instead of $.Event
368                // but we don't have a way to force an event to be fixed multiple times
369                if (event.originalEvent) {
370                        for (var i = $.event.props.length, prop; i;) {
371                                prop = $.event.props[--i];
372                                event[prop] = event.originalEvent[prop];
373                        }
374                }
375
376                this.element.trigger(event, data);
377
378                return !($.isFunction(callback) && callback.call(this.element[0], event, data) === false
379                        || event.isDefaultPrevented());
380        }
381};
382
383$.widget.defaults = {
384        disabled: false
385};
386
387
388/** Mouse Interaction Plugin **/
389
390$.ui.mouse = {
391        _mouseInit: function() {
392                var self = this;
393
394                this.element
395                        .bind('mousedown.'+this.widgetName, function(event) {
396                                return self._mouseDown(event);
397                        })
398                        .bind('click.'+this.widgetName, function(event) {
399                                if(self._preventClickEvent) {
400                                        self._preventClickEvent = false;
401                                        return false;
402                                }
403                        });
404
405                // Prevent text selection in IE
406                if ($.browser.msie) {
407                        this._mouseUnselectable = this.element.attr('unselectable');
408                        this.element.attr('unselectable', 'on');
409                }
410
411                this.started = false;
412        },
413
414        // TODO: make sure destroying one instance of mouse doesn't mess with
415        // other instances of mouse
416        _mouseDestroy: function() {
417                this.element.unbind('.'+this.widgetName);
418
419                // Restore text selection in IE
420                ($.browser.msie
421                        && this.element.attr('unselectable', this._mouseUnselectable));
422        },
423
424        _mouseDown: function(event) {
425                // don't let more than one widget handle mouseStart
426                if (event.originalEvent.mouseHandled) { return; }
427
428                // we may have missed mouseup (out of window)
429                (this._mouseStarted && this._mouseUp(event));
430
431                this._mouseDownEvent = event;
432
433                var self = this,
434                        btnIsLeft = (event.which == 1),
435                        elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
436                if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
437                        return true;
438                }
439
440                this.mouseDelayMet = !this.options.delay;
441                if (!this.mouseDelayMet) {
442                        this._mouseDelayTimer = setTimeout(function() {
443                                self.mouseDelayMet = true;
444                        }, this.options.delay);
445                }
446
447                if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
448                        this._mouseStarted = (this._mouseStart(event) !== false);
449                        if (!this._mouseStarted) {
450                                event.preventDefault();
451                                return true;
452                        }
453                }
454
455                // these delegates are required to keep context
456                this._mouseMoveDelegate = function(event) {
457                        return self._mouseMove(event);
458                };
459                this._mouseUpDelegate = function(event) {
460                        return self._mouseUp(event);
461                };
462                $(document)
463                        .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
464                        .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
465
466                // preventDefault() is used to prevent the selection of text here -
467                // however, in Safari, this causes select boxes not to be selectable
468                // anymore, so this fix is needed
469                ($.browser.safari || event.preventDefault());
470
471                event.originalEvent.mouseHandled = true;
472                return true;
473        },
474
475        _mouseMove: function(event) {
476                // IE mouseup check - mouseup happened when mouse was out of window
477                if ($.browser.msie && !event.button) {
478                        return this._mouseUp(event);
479                }
480
481                if (this._mouseStarted) {
482                        this._mouseDrag(event);
483                        return event.preventDefault();
484                }
485
486                if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
487                        this._mouseStarted =
488                                (this._mouseStart(this._mouseDownEvent, event) !== false);
489                        (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
490                }
491
492                return !this._mouseStarted;
493        },
494
495        _mouseUp: function(event) {
496                $(document)
497                        .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
498                        .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
499
500                if (this._mouseStarted) {
501                        this._mouseStarted = false;
502                        this._preventClickEvent = true;
503                        this._mouseStop(event);
504                }
505
506                return false;
507        },
508
509        _mouseDistanceMet: function(event) {
510                return (Math.max(
511                                Math.abs(this._mouseDownEvent.pageX - event.pageX),
512                                Math.abs(this._mouseDownEvent.pageY - event.pageY)
513                        ) >= this.options.distance
514                );
515        },
516
517        _mouseDelayMet: function(event) {
518                return this.mouseDelayMet;
519        },
520
521        // These are placeholder methods, to be overriden by extending plugin
522        _mouseStart: function(event) {},
523        _mouseDrag: function(event) {},
524        _mouseStop: function(event) {},
525        _mouseCapture: function(event) { return true; }
526};
527
528$.ui.mouse.defaults = {
529        cancel: null,
530        distance: 1,
531        delay: 0
532};
533
534})(jQuery);
535/*
536 * jQuery UI Slider 1.6rc6
537 *
538 * Copyright (c) 2009 AUTHORS.txt (http://ui.jquery.com/about)
539 * Dual licensed under the MIT (MIT-LICENSE.txt)
540 * and GPL (GPL-LICENSE.txt) licenses.
541 *
542 * http://docs.jquery.com/UI/Slider
543 *
544 * Depends:
545 *      ui.core.js
546 */
547
548(function($) {
549
550$.widget("ui.slider", $.extend({}, $.ui.mouse, {
551
552        _init: function() {
553
554                var self = this, o = this.options;
555                this._keySliding = false;
556                this._handleIndex = null;
557                this._detectOrientation();
558                this._mouseInit();
559
560                this.element
561                        .addClass("ui-slider"
562                                + " ui-slider-" + this.orientation
563                                + " ui-widget"
564                                + " ui-widget-content"
565                                + " ui-corner-all");
566
567                this.range = $([]);
568
569                if (o.range) {
570
571                        if (o.range === true) {
572                                this.range = $('<div></div>');
573                                if (!o.values) o.values = [this._valueMin(), this._valueMin()];
574                                if (o.values.length && o.values.length != 2) {
575                                        o.values = [o.values[0], o.values[0]];
576                                }
577                        } else {
578                                this.range = $('<div></div>');
579                        }
580
581                        this.range
582                                .appendTo(this.element)
583                                .addClass("ui-slider-range"
584                                        + " ui-widget-header");
585
586                        (o.range == "min") && (this.orientation == "horizontal") && this.range.css({ left : 0 });
587                        (o.range == "max") && (this.orientation == "horizontal") && this.range.css({ right : 0 });
588                        (o.range == "min") && (this.orientation == "vertical") && this.range.css({ bottom : 0 });
589                        (o.range == "max") && (this.orientation == "vertical") && this.range.css({ top : 0 });
590
591                }
592
593                if ($(".ui-slider-handle", this.element).length == 0)
594                        $('<a href="#"></a>')
595                                .appendTo(this.element)
596                                .addClass("ui-slider-handle");
597
598                if (o.values && o.values.length) {
599                        while ($(".ui-slider-handle", this.element).length < o.values.length)
600                                $('<a href="#"></a>')
601                                        .appendTo(this.element)
602                                        .addClass("ui-slider-handle");
603                }
604
605                this.handles = $(".ui-slider-handle", this.element)
606                        .addClass("ui-state-default"
607                                + " ui-corner-all");
608
609                this.handle = this.handles.eq(0);
610
611                this.handles.add(this.range).filter("a")
612                        .click(function(event) { event.preventDefault(); })
613                        .hover(function() { $(this).addClass('ui-state-hover'); }, function() { $(this).removeClass('ui-state-hover'); })
614                        .focus(function() { self.handles.removeClass('ui-state-focus'); $(this).addClass('ui-state-focus'); })
615                        .blur(function() { $(this).removeClass('ui-state-focus'); });
616
617                this.handles.each(function(i) {
618                        $(this).data("index.ui-slider-handle", i);
619                });
620
621                this.handles.keydown(function(event) {
622
623                        var index = $(this).data("index.ui-slider-handle");
624
625                        if (self.options.disabled)
626                                return;
627
628                        switch (event.keyCode) {
629                                case $.ui.keyCode.HOME:
630                                case $.ui.keyCode.END:
631                                case $.ui.keyCode.UP:
632                                case $.ui.keyCode.RIGHT:
633                                case $.ui.keyCode.DOWN:
634                                case $.ui.keyCode.LEFT:
635                                        if (!self._keySliding) {
636                                                self._keySliding = true;
637                                                $(this).addClass("ui-state-active");
638                                                self._start(event);
639                                        }
640                                        break;
641                        }
642
643                        var curVal, newVal, step = self._step();
644                        if (self.options.values && self.options.values.length) {
645                                curVal = newVal = self.values(index);
646                        } else {
647                                curVal = newVal = self.value();
648                        }
649
650                        switch (event.keyCode) {
651                                case $.ui.keyCode.HOME:
652                                        newVal = self._valueMin();
653                                        break;
654                                case $.ui.keyCode.END:
655                                        newVal = self._valueMax();
656                                        break;
657                                case $.ui.keyCode.UP:
658                                case $.ui.keyCode.RIGHT:
659                                        if(curVal == self._valueMax()) return;
660                                        newVal = curVal + step;
661                                        break;
662                                case $.ui.keyCode.DOWN:
663                                case $.ui.keyCode.LEFT:
664                                        if(curVal == self._valueMin()) return;
665                                        newVal = curVal - step;
666                                        break;
667                        }
668
669                        self._slide(event, index, newVal);
670
671                }).keyup(function(event) {
672
673                        if (self._keySliding) {
674                                self._stop(event);
675                                self._change(event);
676                                self._keySliding = false;
677                                $(this).removeClass("ui-state-active");
678                        }
679
680                });
681
682                this._refreshValue();
683
684        },
685
686        destroy: function() {
687
688                this.handles.remove();
689
690                this.element
691                        .removeClass("ui-slider"
692                                + " ui-slider-horizontal"
693                                + " ui-slider-vertical"
694                                + " ui-slider-disabled"
695                                + " ui-widget"
696                                + " ui-widget-content"
697                                + " ui-corner-all")
698                        .removeData("slider")
699                        .unbind(".slider");
700
701                this._mouseDestroy();
702
703        },
704
705        _mouseCapture: function(event) {
706
707                var o = this.options;
708
709                if (o.disabled)
710                        return false;
711
712                this._start(event);
713
714                this.elementSize = {
715                        width: this.element.outerWidth(),
716                        height: this.element.outerHeight()
717                };
718                this.elementOffset = this.element.offset();
719
720                var position = { x: event.pageX, y: event.pageY };
721                var normValue = this._normValueFromMouse(position);
722
723                var distance = this._valueMax() + 1, closestHandle;
724                var self = this, index;
725                this.handles.each(function(i) {
726                        var thisDistance = Math.abs(normValue - self.values(i));
727                        if (distance > thisDistance) {
728                                distance = thisDistance;
729                                closestHandle = $(this);
730                                index = i;
731                        }
732                });
733               
734                // workaround for bug #3736 (if both handles of a range are at 0, the first is always used as the one with least distance,
735                // and moving it is obviously prevented by preventing negative ranges)
736                if(o.range && (this.values(0) + this.values(1)) == 0) {
737                        closestHandle = $(this.handles[++index]);
738                }
739
740                self._handleIndex = index;
741
742                closestHandle
743                        .addClass("ui-state-active")
744                        .focus();
745               
746                var offset = closestHandle.offset();
747                var mouseOverHandle = !$(event.target).parents().andSelf().is('.ui-slider-handle');
748                this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
749                        left: event.pageX - offset.left + (parseInt(closestHandle.css('marginLeft'),10) || 0),
750                        top: event.pageY - offset.top + (parseInt(closestHandle.css('marginTop'),10) || 0)
751                };
752
753                normValue = this._normValueFromMouse(position);
754                this._slide(event, index, normValue);
755                return true;
756
757        },
758
759        _mouseStart: function(event) {
760                return true;
761        },
762
763        _mouseDrag: function(event) {
764
765                var position = { x: event.pageX, y: event.pageY };
766                var normValue = this._normValueFromMouse(position);
767               
768                this._slide(event, this._handleIndex, normValue);
769
770                return false;
771
772        },
773
774        _mouseStop: function(event) {
775
776                this.handles.removeClass("ui-state-active");
777                this._stop(event);
778                this._change(event);
779                this._handleIndex = null;
780                this._clickOffset = null;
781
782                return false;
783
784        },
785       
786        _detectOrientation: function() {
787                this.orientation = this.options.orientation == 'auto' ? (this.element[0].offsetWidth/this.element[0].offsetHeight > 1 ? 'horizontal' : 'vertical') : this.options.orientation;
788        },
789
790        _normValueFromMouse: function(position) {
791
792                var pixelTotal, pixelMouse;
793                if ('horizontal' == this.orientation) {
794                        pixelTotal = this.elementSize.width;
795                        pixelMouse = position.x - this.elementOffset.left - (this._clickOffset ? this._clickOffset.left : 0);
796                } else {
797                        pixelTotal = this.elementSize.height;
798                        pixelMouse = position.y - this.elementOffset.top - (this._clickOffset ? this._clickOffset.top : 0);
799                }
800
801                var percentMouse = (pixelMouse / pixelTotal);
802                if (percentMouse > 1) percentMouse = 1;
803                if (percentMouse < 0) percentMouse = 0;
804                if ('vertical' == this.orientation)
805                        percentMouse = 1 - percentMouse;
806
807                var valueTotal = this._valueMax() - this._valueMin(),
808                        valueMouse = percentMouse * valueTotal,
809                        valueMouseModStep = valueMouse % this.options.step,
810                        normValue = this._valueMin() + valueMouse - valueMouseModStep;
811
812                if (valueMouseModStep > (this.options.step / 2))
813                        normValue += this.options.step;
814
815                return normValue;
816
817        },
818
819        _start: function(event) {
820                this._trigger("start", event, {
821                        value: this.value()
822                });
823        },
824
825        _slide: function(event, index, newVal) {
826
827                var handle = this.handles[index];
828
829                if (this.options.values && this.options.values.length) {
830
831                        var otherVal = this.values(index ? 0 : 1);
832
833                        if ((index == 0 && newVal >= otherVal) || (index == 1 && newVal <= otherVal))
834                                newVal = otherVal;
835
836                        if (newVal != this.values(index)) {
837                                var newValues = this.values();
838                                newValues[index] = newVal;
839                                // A slide can be canceled by returning false from the slide callback
840                                var allowed = this._trigger("slide", event, {
841                                        handle: handle,
842                                        value: newVal,
843                                        values: newValues
844                                });
845                                var otherVal = this.values(index ? 0 : 1);
846                                if (allowed !== false) {
847                                        this.values(index, newVal, !( event.type == 'mousedown' && this.options.animate ));
848                                }
849                        }
850
851                } else {
852
853                        if (newVal != this.value()) {
854                                // A slide can be canceled by returning false from the slide callback
855                                var allowed = this._trigger("slide", event, {
856                                        handle: handle,
857                                        value: newVal
858                                });
859                                if (allowed !== false) {
860                                        this._setData('value', newVal, ( event.type == 'mousedown' && this.options.animate ));
861                                }
862                                       
863                        }
864
865                }
866
867        },
868
869        _stop: function(event) {
870                this._trigger("stop", event, {
871                        value: this.value()
872                });
873        },
874
875        _change: function(event) {
876                this._trigger("change", event, {
877                        value: this.value()
878                });
879        },
880
881        value: function(newValue) {
882
883                if (arguments.length) {
884                        this._setData("value", newValue);
885                        this._change();
886                }
887
888                return this._value();
889
890        },
891
892        values: function(index, newValue, noAnimation) {
893
894                if(!this.options.animate) noAnimation = true;
895
896                if (arguments.length > 1) {
897                        this.options.values[index] = newValue;
898                        this._refreshValue(!noAnimation);
899                        this._change();
900                }
901
902                if (arguments.length) {
903                        if (this.options.values && this.options.values.length) {
904                                return this._values(index);
905                        } else {
906                                return this.value();
907                        }
908                } else {
909                        return this._values();
910                }
911
912        },
913
914        _setData: function(key, value) {
915
916                $.widget.prototype._setData.apply(this, arguments);
917
918                switch (key) {
919                        case 'orientation':
920
921                                this._detectOrientation();
922                               
923                                this.element
924                                        .removeClass("ui-slider-horizontal ui-slider-vertical")
925                                        .addClass("ui-slider-" + this.orientation);
926                                this._refreshValue();
927                                break;
928                        case 'value':
929                                this._refreshValue();
930                                break;
931                }
932
933        },
934
935        _step: function() {
936                var step = this.options.step;
937                return step;
938        },
939
940        _value: function() {
941
942                var val = this.options.value;
943                if (val < this._valueMin()) val = this._valueMin();
944                if (val > this._valueMax()) val = this._valueMax();
945
946                return val;
947
948        },
949
950        _values: function(index) {
951
952                if (arguments.length) {
953                        var val = this.options.values[index];
954                        if (val < this._valueMin()) val = this._valueMin();
955                        if (val > this._valueMax()) val = this._valueMax();
956
957                        return val;
958                } else {
959                        return this.options.values;
960                }
961
962        },
963
964        _valueMin: function() {
965                var valueMin = this.options.min;
966                return valueMin;
967        },
968
969        _valueMax: function() {
970                var valueMax = this.options.max;
971                return valueMax;
972        },
973
974        _refreshValue: function(animate) {
975
976                var oRange = this.options.range, o = this.options, self = this;
977
978                if (this.options.values && this.options.values.length) {
979                        var vp0, vp1;
980                        this.handles.each(function(i, j) {
981                                var valPercent = (self.values(i) - self._valueMin()) / (self._valueMax() - self._valueMin()) * 100;
982                                var _set = {}; _set[self.orientation == 'horizontal' ? 'left' : 'bottom'] = valPercent + '%';
983                                $(this).stop(1,1)[animate ? 'animate' : 'css'](_set, o.animate);
984                                if (self.options.range === true) {
985                                        if (self.orientation == 'horizontal') {
986                                                (i == 0) && self.range.stop(1,1)[animate ? 'animate' : 'css']({ left: valPercent + '%' }, o.animate);
987                                                (i == 1) && self.range[animate ? 'animate' : 'css']({ width: (valPercent - lastValPercent) + '%' }, { queue: false, duration: o.animate });
988                                        } else {
989                                                (i == 0) && self.range.stop(1,1)[animate ? 'animate' : 'css']({ bottom: (valPercent) + '%' }, o.animate);
990                                                (i == 1) && self.range[animate ? 'animate' : 'css']({ height: (valPercent - lastValPercent) + '%' }, { queue: false, duration: o.animate });
991                                        }
992                                }
993                                lastValPercent = valPercent;
994                        });
995                } else {
996                        var valPercent = (this.value() - this._valueMin()) / (this._valueMax() - this._valueMin()) * 100;
997                        var _set = {}; _set[self.orientation == 'horizontal' ? 'left' : 'bottom'] = valPercent + '%';
998                        this.handle.stop(1,1)[animate ? 'animate' : 'css'](_set, o.animate);
999
1000                        (oRange == "min") && (this.orientation == "horizontal") && this.range.stop(1,1)[animate ? 'animate' : 'css']({ left: 0, width: valPercent + '%' }, o.animate);
1001                        (oRange == "max") && (this.orientation == "horizontal") && this.range[animate ? 'animate' : 'css']({ left: valPercent + '%', width: (100 - valPercent) + '%' }, { queue: false, duration: o.animate });
1002                        (oRange == "min") && (this.orientation == "vertical") && this.range.stop(1,1)[animate ? 'animate' : 'css']({ top: (100 - valPercent) + '%', height: valPercent + '%' }, o.animate);
1003                        (oRange == "max") && (this.orientation == "vertical") && this.range[animate ? 'animate' : 'css']({ bottom: valPercent + '%', height: (100 - valPercent) + '%' }, { queue: false, duration: o.animate });
1004                }
1005
1006        }
1007
1008}));
1009
1010$.extend($.ui.slider, {
1011        getter: "value values",
1012        version: "1.6rc6",
1013        eventPrefix: "slide",
1014        defaults: {
1015                animate: false,
1016                delay: 0,
1017                distance: 0,
1018                max: 100,
1019                min: 0,
1020                orientation: 'auto',
1021                range: false,
1022                step: 1,
1023                value: 0,
1024                values: null
1025        }
1026});
1027
1028})(jQuery);
Note: See TracBrowser for help on using the repository browser.