Bug Tracker

Changeset 4897

Show
Ignore:
Timestamp:
03/14/08 11:20:46 (9 months ago)
Author:
joern.zaefferer
Message:

ui.slider: Added testsuite and a first bunch of tests; fixes for #2496, #2053, #2500

Location:
trunk/ui
Files:
2 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/ui.slider.js

    r4890 r4897  
    3333            axis: o.axis || (element.offsetWidth < element.offsetHeight ? 'vertical' : 'horizontal'), 
    3434            maxValue: !isNaN(parseInt(o.maxValue,10)) ? parseInt(o.maxValue,10) :  100, 
    35             minValue: parseInt(o.minValue,10) || 0, 
    36             startValue: parseInt(o.startValue,10) || 'none'      
     35            minValue: parseInt(o.minValue,10) || 0 
    3736        }); 
    3837         
     
    7372                .bind('blur', function(e) { self.blur(this.firstChild); }) 
    7473                .bind('keydown', function(e) { 
    75                     if(/(37|39)/.test(e.keyCode)) 
     74                    if(/(37|39)/.test(e.keyCode)) { 
    7675                        self.moveTo((e.keyCode == 37 ? '-' : '+')+'='+(self.options.stepping ? self.options.stepping : (self.options.realMaxValue / self.size)*5),this.firstChild); 
     76                    } 
    7777                }) 
    7878        ; 
     
    9494         
    9595        //Move the first handle to the startValue 
    96         if(!isNaN(o.startValue)) this.moveTo(o.startValue, 0); 
     96        if (o.startValue && o.startValue.length) { 
     97            $.each(o.startValue, function(index, value) { 
     98                self.moveTo(value, index, true); 
     99            }); 
     100        } else if (!isNaN(o.startValue)) 
     101            this.moveTo(o.startValue, 0, true); 
    97102         
    98103        //If we only have one handle, set the previous handle to this one to allow clicking before selecting the handle 
     
    137142            this.element 
    138143                .removeClass("ui-slider ui-slider-disabled") 
    139                 .removeData("ul-slider") 
     144                .removeData("ui-slider") 
    140145                .unbind(".slider"); 
    141             this.handles.removeMouseInteraction(); 
     146            this.handle.removeMouseInteraction(); 
    142147        }, 
    143148        enable: function() { 
     
    232237             
    233238        }, 
    234         moveTo: function(value, handle) { 
    235  
     239        moveTo: function(value, handle, noPropagation) { 
    236240            var o = this.options; 
    237241            if(handle == undefined && !this.currentHandle && this.handle.length != 1) return false; //If no handle has been passed, no current handle is available and we have multiple handles, return false 
    238242            if(handle == undefined && !this.currentHandle) handle = 0; //If only one handle is available, use it 
    239243            if(handle != undefined) this.currentHandle = this.previousHandle = $(this.handle[handle] || handle); 
    240  
    241             if(value.constructor == String) value = /\-\=/.test(value) ? this.value() - parseInt(value.replace('-=', ''),10) : this.value() + parseInt(value.replace('+=', ''),10); 
     244     
     245            if(value.constructor == String) { 
     246                if (/^\-\=/.test(value) ) { 
     247                    value = this.value() - parseInt(value.replace('-=', ''), 10) 
     248                } else if (/^\+\=/.test(value) ) { 
     249                    value = this.value() + parseInt(value.replace('+=', ''), 10) 
     250                } 
     251            } 
     252             
    242253            if(o.stepping) value = Math.round(value / o.stepping) * o.stepping; 
    243254            value = this.translateValue(value); 
     
    253264            if(this.rangeElement) this.updateRange(); 
    254265             
    255             this.propagate('start', null); 
    256             this.propagate('stop', null); 
    257             this.propagate('change', null); 
    258  
     266            if (!noPropagation) { 
     267                this.propagate('start', null); 
     268                this.propagate('stop', null); 
     269                this.propagate('change', null); 
     270            } 
    259271        } 
    260272    });