jQuery: The Write Less, Do More JavaScript Library

Changeset 5539

Show
Ignore:
Timestamp:
05/09/08 16:48:33 (4 days ago)
Author:
paul.bakaus
Message:

ui-slider: fixed calculation issues (fixes #2677, #2438, #2813)

Location:
trunk/ui
Files:
2 modified

Legend:

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

    r5533 r5539  
    99            stepping: stepping, 
    1010            startValue: start, 
     11            min: 0, 
     12            max: 1000, 
    1113            change: function(e, ui) { 
    1214                equals(ui.value, result, "changed to " + ui.value); 
     
    4547})) 
    4648 
    47 test("moveTo, relative positive value, above max", assertChange(1, 10, 100, function() { 
    48     this.slider("moveTo", "+=200"); 
     49test("moveTo, relative positive value, above max", assertChange(1, 10, 1000, function() { 
     50    this.slider("moveTo", "+=2000"); 
    4951})) 
    5052 
  • trunk/ui/ui.slider.js

    r5538 r5539  
    184184            // propagate only for distance > 0, otherwise propagation is done my drag 
    185185            this.offset = this.element.offset(); 
     186 
    186187            this.moveTo({ 
    187188                y: this.convertValue(e.pageY - this.offset.top - this.currentHandle[0].offsetHeight/2, "y"), 
     
    206207        }, 
    207208        getRange: function() { 
    208             return this.rangeElement ? this.convertValue(parseInt(this.rangeElement.css(this.options.axis == "vertical" ? "height" : "width"),10)) : null; 
     209            return this.rangeElement ? this.convertValue(parseInt(this.rangeElement.css(this.options.axis == "vertical" ? "height" : "width"),10), this.options.axis == "vertical" ? "y" : "x") : null; 
    209210        }, 
    210211 
     
    215216            if(this.handle.length == 1) this.currentHandle = this.handle; 
    216217            if(!axis) axis = this.options.axis == "vertical" ? "y" : "x"; 
    217              
    218             var value = ((parseInt($(handle != undefined && handle !== null ? this.handle[handle] || handle : this.currentHandle).css(axis == "x" ? "left" : "top"),10) / (this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(handle,axis))) * this.options.realMax[axis]) + this.options.min[axis]; 
    219              
    220             var o = this.options; 
    221             if (o.stepping[axis]) { 
    222                 value = Math.round(value / o.stepping[axis]) * o.stepping[axis]; 
    223             } 
    224             return value; 
     218 
     219            var curHandle = $(handle != undefined && handle !== null ? this.handle[handle] || handle : this.currentHandle); 
     220             
     221            if(curHandle.data("mouse").sliderValue) { 
     222                return parseInt(curHandle.data("mouse").sliderValue[axis],10); 
     223            } else { 
     224                return parseInt(((parseInt(curHandle.css(axis == "x" ? "left" : "top"),10) / (this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(handle,axis))) * this.options.realMax[axis]) + this.options.min[axis],10); 
     225            } 
     226 
    225227        }, 
    226228        convertValue: function(value,axis) { 
     
    263265 
    264266 
    265  
    266  
    267  
    268  
    269267        start: function(e, handle) { 
    270268         
     
    321319            if(o.axis != "horizontal") this.currentHandle.css({ top: position.top }); 
    322320             
     321            //Store the slider's value 
     322            this.currentHandle.data("mouse").sliderValue = { 
     323                x: this.convertValue(position.left, "x"), 
     324                y: this.convertValue(position.top, "y") 
     325            }; 
     326             
    323327            if (this.rangeElement) 
    324328                this.updateRange(); 
     
    354358            if(x !== undefined && x.constructor != Number) { 
    355359                var me = /^\-\=/.test(x), pe = /^\+\=/.test(x); 
    356                 x = this.value(null, "x") + parseInt(x.replace(me ? '=' : '+=', ''), 10); 
     360                if(me || pe) { 
     361                    x = this.value(null, "x") + parseInt(x.replace(me ? '=' : '+=', ''), 10); 
     362                } else { 
     363                    x = isNaN(parseInt(x, 10)) ? undefined : parseInt(x, 10); 
     364                } 
    357365            } 
    358366             
    359367            if(y !== undefined && y.constructor != Number) { 
    360368                var me = /^\-\=/.test(y), pe = /^\+\=/.test(y); 
    361                 y = this.value(null, "y") + parseInt(y.replace(me ? '=' : '+=', ''), 10); 
     369                if(me || pe) { 
     370                    y = this.value(null, "y") + parseInt(y.replace(me ? '=' : '+=', ''), 10); 
     371                } else { 
     372                    y = isNaN(parseInt(y, 10)) ? undefined : parseInt(y, 10); 
     373                } 
    362374            } 
    363375 
     
    380392            if (this.rangeElement) 
    381393                this.updateRange(); 
     394                 
     395            //Store the slider's value 
     396            this.currentHandle.data("mouse").sliderValue = { 
     397                x: this.convertValue(x, "x"), 
     398                y: this.convertValue(y, "y") 
     399            }; 
    382400             
    383401            if (!noPropagation) {