| | 24 | plugins: {}, |
| | 25 | ui: function(e) { |
| | 26 | return { |
| | 27 | instance: this, |
| | 28 | options: this.options, |
| | 29 | handle: this.currentHandle, |
| | 30 | value: this.options.axis != "both" || !this.options.axis ? Math.round(this.value(null,this.options.axis == "vertical" ? "y" : "x")) : { |
| | 31 | x: Math.round(this.value(null,"x")), |
| | 32 | y: Math.round(this.value(null,"y")) |
| | 33 | }, |
| | 34 | range: this.getRange() |
| | 35 | }; |
| | 36 | }, |
| | 37 | propagate: function(n,e) { |
| | 38 | $.ui.plugin.call(this, n, [e, this.ui()]); |
| | 39 | this.element.triggerHandler(n == "slide" ? n : "slide"+n, [e, this.ui()], this.options[n]); |
| | 40 | }, |
| | 41 | destroy: function() { |
| | 42 | this.element |
| | 43 | .removeClass("ui-slider ui-slider-disabled") |
| | 44 | .removeData("slider") |
| | 45 | .unbind(".slider"); |
| | 46 | this.handle |
| | 47 | .unwrap("a") |
| | 48 | .mouse("destroy"); |
| | 49 | this.generated && this.generated.remove(); |
| | 50 | }, |
| | 51 | enable: function() { |
| | 52 | this.element.removeClass("ui-slider-disabled"); |
| | 53 | this.disabled = false; |
| | 54 | }, |
| | 55 | disable: function() { |
| | 56 | this.element.addClass("ui-slider-disabled"); |
| | 57 | this.disabled = true; |
| | 58 | }, |
| | 59 | setData: function(key, value) { |
| | 60 | this.options[key] = value; |
| | 61 | if (/min|max|steps/.test(key)) { |
| | 62 | this.initBoundaries(); |
| | 63 | } |
| | 64 | }, |
| | 65 | |
| 118 | | plugins: {}, |
| 119 | | createRange: function() { |
| 120 | | this.rangeElement = $('<div></div>') |
| 121 | | .addClass('ui-slider-range') |
| 122 | | .css({ position: 'absolute' }) |
| 123 | | .appendTo(this.element); |
| 124 | | this.updateRange(); |
| 125 | | }, |
| 126 | | updateRange: function() { |
| 127 | | var prop = this.options.axis == "vertical" ? "top" : "left"; |
| 128 | | var size = this.options.axis == "vertical" ? "height" : "width"; |
| 129 | | this.rangeElement.css(prop, parseInt($(this.handle[0]).css(prop),10) + this.handleSize(0, this.options.axis == "vertical" ? 2 : 1)/2); |
| 130 | | this.rangeElement.css(size, parseInt($(this.handle[1]).css(prop),10) - parseInt($(this.handle[0]).css(prop),10)); |
| 131 | | }, |
| 132 | | getRange: function() { |
| 133 | | return this.rangeElement ? this.convertValue(parseInt(this.rangeElement.css(this.options.axis == "vertical" ? "height" : "width"),10)) : null; |
| 134 | | }, |
| 135 | | ui: function(e) { |
| 136 | | return { |
| 137 | | instance: this, |
| 138 | | options: this.options, |
| 139 | | handle: this.currentHandle, |
| 140 | | value: this.options.axis != "both" || !this.options.axis ? Math.round(this.value(null,this.options.axis == "vertical" ? 2 : 1)) : { |
| 141 | | x: Math.round(this.value(null,1)), |
| 142 | | y: Math.round(this.value(null,2)) |
| 143 | | }, |
| 144 | | range: this.getRange() |
| 145 | | }; |
| 146 | | }, |
| 147 | | propagate: function(n,e) { |
| 148 | | $.ui.plugin.call(this, n, [e, this.ui()]); |
| 149 | | this.element.triggerHandler(n == "slide" ? n : "slide"+n, [e, this.ui()], this.options[n]); |
| 150 | | }, |
| 151 | | destroy: function() { |
| 152 | | this.element |
| 153 | | .removeClass("ui-slider ui-slider-disabled") |
| 154 | | .removeData("slider") |
| 155 | | .unbind(".slider"); |
| 156 | | this.handle |
| 157 | | .unwrap("a") |
| 158 | | .mouse("destroy"); |
| 159 | | this.generated && this.generated.remove(); |
| 160 | | }, |
| 161 | | enable: function() { |
| 162 | | this.element.removeClass("ui-slider-disabled"); |
| 163 | | this.disabled = false; |
| 164 | | }, |
| 165 | | disable: function() { |
| 166 | | this.element.addClass("ui-slider-disabled"); |
| 167 | | this.disabled = true; |
| | 145 | |
| | 146 | |
| | 147 | keydown: function(keyCode, handle) { |
| | 148 | if(/(37|38|39|40)/.test(keyCode)) { |
| | 149 | this.moveTo({ |
| | 150 | x: /(37|39)/.test(keyCode) ? (keyCode == 37 ? '-' : '+') + '=' + this.oneStep("x") : 0, |
| | 151 | y: /(38|40)/.test(keyCode) ? (keyCode == 38 ? '-' : '+') + '=' + this.oneStep("y") : 0 |
| | 152 | }, handle); |
| | 153 | } |
| 177 | | }, |
| 178 | | value: function(handle, axis) { |
| 179 | | if(this.handle.length == 1) this.currentHandle = this.handle; |
| 180 | | if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; |
| 181 | | |
| 182 | | var value = ((parseInt($(handle != undefined && handle !== null ? this.handle[handle] || handle : this.currentHandle).css(axis == 1 ? "left" : "top"),10) / (this.actualSize[axis == 1 ? "width" : "height"] - this.handleSize(handle,axis))) * this.options.realMax[axis == 1 ? "x" : "y"]) + this.options.min[axis == 1 ? "x" : "y"]; |
| 183 | | |
| 184 | | var o = this.options; |
| 185 | | if (o.stepping[axis == 1 ? "x" : "y"]) { |
| 186 | | value = Math.round(value / o.stepping[axis == 1 ? "x" : "y"]) * o.stepping[axis == 1 ? "x" : "y"]; |
| 187 | | } |
| 188 | | return value; |
| 189 | | }, |
| 190 | | convertValue: function(value,axis) { |
| 191 | | if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; |
| 192 | | return this.options.min[axis == 1 ? "x" : "y"] + (value / (this.actualSize[axis == 1 ? "width" : "height"] - this.handleSize(null,axis))) * this.options.realMax[axis == 1 ? "x" : "y"]; |
| 193 | | }, |
| 194 | | translateValue: function(value,axis) { |
| 195 | | if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; |
| 196 | | return ((value - this.options.min[axis == 1 ? "x" : "y"]) / this.options.realMax[axis == 1 ? "x" : "y"]) * (this.actualSize[axis == 1 ? "width" : "height"] - this.handleSize(null,axis)); |
| 197 | | }, |
| 198 | | handleSize: function(handle,axis) { |
| 199 | | if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; |
| 200 | | return $(handle != undefined && handle !== null ? this.handle[handle] : this.currentHandle)[0][axis == 1 ? "offsetWidth" : "offsetHeight"]; |
| | 191 | |
| | 192 | |
| | 193 | |
| | 194 | createRange: function() { |
| | 195 | this.rangeElement = $('<div></div>') |
| | 196 | .addClass('ui-slider-range') |
| | 197 | .css({ position: 'absolute' }) |
| | 198 | .appendTo(this.element); |
| | 199 | this.updateRange(); |
| | 200 | }, |
| | 201 | updateRange: function() { |
| | 202 | var prop = this.options.axis == "vertical" ? "top" : "left"; |
| | 203 | var size = this.options.axis == "vertical" ? "height" : "width"; |
| | 204 | this.rangeElement.css(prop, parseInt($(this.handle[0]).css(prop),10) + this.handleSize(0, this.options.axis == "vertical" ? "y" : "x")/2); |
| | 205 | this.rangeElement.css(size, parseInt($(this.handle[1]).css(prop),10) - parseInt($(this.handle[0]).css(prop),10)); |
| | 206 | }, |
| | 207 | getRange: function() { |
| | 208 | return this.rangeElement ? this.convertValue(parseInt(this.rangeElement.css(this.options.axis == "vertical" ? "height" : "width"),10)) : null; |
| | 209 | }, |
| | 210 | |
| | 211 | handleIndex: function() { |
| | 212 | return this.handle.index(this.currentHandle[0]); |
| | 213 | }, |
| | 214 | value: function(handle, axis) { |
| | 215 | if(this.handle.length == 1) this.currentHandle = this.handle; |
| | 216 | 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; |
| | 225 | }, |
| | 226 | convertValue: function(value,axis) { |
| | 227 | return this.options.min[axis] + (value / (this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(null,axis))) * this.options.realMax[axis]; |
| | 228 | }, |
| | 229 | |
| | 230 | translateValue: function(value,axis) { |
| | 231 | return ((value - this.options.min[axis]) / this.options.realMax[axis]) * (this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(null,axis)); |
| | 232 | }, |
| | 233 | translateRange: function(value,axis) { |
| | 234 | if (this.rangeElement) { |
| | 235 | if (this.currentHandle[0] == this.handle[0] && value >= this.translateValue(this.value(1),axis)) |
| | 236 | value = this.translateValue(this.value(1,axis) - this.oneStep(axis), axis); |
| | 237 | if (this.currentHandle[0] == this.handle[1] && value <= this.translateValue(this.value(0),axis)) |
| | 238 | value = this.translateValue(this.value(0,axis) + this.oneStep(axis)); |
| | 239 | } |
| | 240 | if (this.options.handles) { |
| | 241 | var handle = this.options.handles[this.handleIndex()]; |
| | 242 | if (value < this.translateValue(handle.min,axis)) { |
| | 243 | value = this.translateValue(handle.min,axis); |
| | 244 | } else if (value > this.translateValue(handle.max,axis)) { |
| | 245 | value = this.translateValue(handle.max,axis); |
| | 246 | } |
| | 247 | } |
| | 248 | return value; |
| | 249 | }, |
| | 250 | translateLimits: function(value,axis) { |
| | 251 | if (value >= this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(null,axis)) |
| | 252 | value = this.actualSize[axis == "x" ? "width" : "height"] - this.handleSize(null,axis); |
| | 253 | if (value <= 0) |
| | 254 | value = 0; |
| | 255 | return value; |
| | 256 | }, |
| | 257 | handleSize: function(handle,axis) { |
| | 258 | return $(handle != undefined && handle !== null ? this.handle[handle] : this.currentHandle)[0]["offset"+(axis == "x" ? "Width" : "Height")]; |
| | 259 | }, |
| | 260 | oneStep: function(axis) { |
| | 261 | return this.options.stepping[axis] || 1; |
| | 262 | }, |
| | 263 | |
| | 264 | |
| | 265 | |
| | 266 | |
| | 267 | |
| | 268 | |
| 259 | | |
| 260 | | oneStep: function(axis) { |
| 261 | | if (!axis) |
| 262 | | axis = this.options.axis == "vertical" ? 2 : 1; |
| 263 | | return this.options.stepping[axis == 1 ? "x" : "y"] |
| 264 | | ? this.options.stepping[axis == 1 ? "x" : "y"] |
| 265 | | : (this.options.realMax[axis == 1 ? "x" : "y"] / this.actualSize[axis == 1 ? "width" : "height"]) * 5; |
| 266 | | }, |
| 267 | | |
| 268 | | translateRange: function(value,axis) { |
| 269 | | if (this.rangeElement) { |
| 270 | | if (this.currentHandle[0] == this.handle[0] && value >= this.translateValue(this.value(1),axis)) |
| 271 | | value = this.translateValue(this.value(1,axis) - this.oneStep(axis), axis); |
| 272 | | if (this.currentHandle[0] == this.handle[1] && value <= this.translateValue(this.value(0),axis)) |
| 273 | | value = this.translateValue(this.value(0,axis) + this.oneStep(axis)); |
| 274 | | } |
| 275 | | if (this.options.handles) { |
| 276 | | var handle = this.options.handles[this.handleIndex()]; |
| 277 | | if (value < this.translateValue(handle.min,axis)) { |
| 278 | | value = this.translateValue(handle.min,axis); |
| 279 | | } else if (value > this.translateValue(handle.max,axis)) { |
| 280 | | value = this.translateValue(handle.max,axis); |
| 281 | | } |
| 282 | | } |
| 283 | | return value; |
| 284 | | }, |
| 285 | | |
| 286 | | handleIndex: function() { |
| 287 | | return this.handle.index(this.currentHandle[0]); |
| 288 | | }, |
| 289 | | |
| 290 | | translateLimits: function(value,axis) { |
| 291 | | if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; |
| 292 | | if (value >= this.actualSize[axis == 1 ? "width" : "height"] - this.handleSize(null,axis)) |
| 293 | | value = this.actualSize[axis == 1 ? "width" : "height"] - this.handleSize(null,axis); |
| 294 | | if (value <= 0) |
| 295 | | value = 0; |
| 296 | | return value; |
| 297 | | }, |
| 298 | | |