Changeset 5141
- Timestamp:
- 03/28/08 16:02:51 (4 months ago)
- Location:
- trunk/ui
- Files:
-
- 12 added
- 3 modified
-
colorpicker (added)
-
colorpicker/colorpicker.html (added)
-
colorpicker/images (added)
-
colorpicker/images/ui.colorpicker.bg.png (added)
-
colorpicker/images/ui.colorpicker.hue.png (added)
-
colorpicker/images/ui.colorpicker.huehandle.gif (added)
-
colorpicker/images/ui.colorpicker.select.gif (added)
-
colorpicker/pngFix (added)
-
colorpicker/pngFix/blank.gif (added)
-
colorpicker/pngFix/jquery.pngFix.js (added)
-
colorpicker/ui.colorpicker.css (added)
-
colorpicker/ui.colorpicker.js (added)
-
demos/ui.slider.html (modified) (1 diff)
-
ui.base.js (modified) (1 diff)
-
ui.slider.js (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ui/demos/ui.slider.html
r5088 r5141 51 51 <div class="playground" style='height: 280px;'> 52 52 <div id='example4' style="position: relative; margin: 40px; width: 20px; height: 200px; background: #eee;"> 53 <div style='position: absolute; z-index: 1; background: green; width: 100%; height: 12px; top: 0px;'></div>54 <div style='position: absolute; z-index: 1; background: green; width: 100%; height: 12px; top: 188px;'></div>53 <div class='ui-slider-handle' style='position: absolute; z-index: 1; background: green; width: 100%; height: 12px; top: 0px;'></div> 54 <div class='ui-slider-handle' style='position: absolute; z-index: 1; background: green; width: 100%; height: 12px; top: 188px;'></div> 55 55 </div> 56 56 </div> -
trunk/ui/ui.base.js
r5136 r5141 141 141 if(!self.initalized && Math.abs(self._MP.left-e.pageX) >= self.options.distance || Math.abs(self._MP.top-e.pageY) >= self.options.distance) { 142 142 if(self.options.start) self.options.start.call(self.options.executor || self, e, self.element); 143 if(self.options.drag) self.options.drag.call(self.options.executor || self, e, this.element); //This is actually not correct, but expected 143 144 self.initialized = true; 144 145 } -
trunk/ui/ui.slider.js
r5136 r5141 33 33 $.extend(o, { 34 34 axis: o.axis || (element.offsetWidth < element.offsetHeight ? 'vertical' : 'horizontal'), 35 max Value: !isNaN(parseInt(o.maxValue,10)) ? parseInt(o.maxValue, 10) : 100,36 min Value: parseInt(o.minValue,10) || 035 max: !isNaN(parseInt(o.max,10)) ? { x: parseInt(o.max, 10), y: parseInt(o.max, 10) } : ({ x: o.max && o.max.x || 100, y: o.max && o.max.y || 100 }), 36 min: !isNaN(parseInt(o.min,10)) ? { x: parseInt(o.min, 10), y: parseInt(o.min, 10) } : ({ x: o.min && o.min.x || 0, y: o.min && o.min.y || 0 }) 37 37 }); 38 38 39 39 //Prepare the real maxValue 40 o.realMaxValue = o.maxValue - o.minValue; 40 o.realMax = { 41 x: o.max.x - o.min.x, 42 y: o.max.y - o.min.y 43 }; 41 44 42 45 //Calculate stepping based on steps 43 o.stepping = parseInt(o.stepping, 10) || (o.steps ? o.realMaxValue/o.steps : 0); 46 o.stepping = { 47 x: o.stepping && o.stepping.x || parseInt(o.stepping, 10) || (o.steps && o.steps.x ? o.realMax.x/o.steps.x : 0), 48 y: o.stepping && o.stepping.y || parseInt(o.stepping, 10) || (o.steps && o.steps.y ? o.realMax.y/o.steps.y : 0) 49 }; 44 50 45 51 $(element).bind("setData.slider", function(event, key, value){ … … 81 87 .bind('blur', function(e) { self.blur(this.firstChild); }) 82 88 .bind('keydown', function(e) { 83 if(/(37|39)/.test(e.keyCode)) { 84 self.moveTo((e.keyCode == 37 ? '-' : '+') + '=' + self.oneStep(),this.firstChild); 89 if(/(37|38|39|40)/.test(e.keyCode)) { 90 self.moveTo({ 91 x: /(37|39)/.test(e.keyCode) ? (e.keyCode == 37 ? '-' : '+') + '=' + self.oneStep(1) : null, 92 y: /(38|40)/.test(e.keyCode) ? (e.keyCode == 38 ? '-' : '+') + '=' + self.oneStep(2) : null 93 }, this.firstChild); 85 94 } 86 95 }) … … 88 97 89 98 //Prepare dynamic properties for later use 90 if(o.axis == 'horizontal') { 91 this.actualSize = this.element.outerWidth(); 92 this.properties = ['left', 'width']; 93 } else { 94 this.actualSize = this.element.outerHeight(); 95 this.properties = ['top', 'height']; 96 } 99 this.actualSize = { width: this.element.outerWidth() , height: this.element.outerHeight() }; 97 100 98 101 //Bind the click to the slider itself … … 100 103 self.click.apply(self, [e]); 101 104 self.currentHandle.data("ui-mouse").trigger(e); 105 self.firstValue = self.firstValue + 1; //This is for always triggering the change event 102 106 }); 103 107 … … 111 115 //If we only have one handle, set the previous handle to this one to allow clicking before selecting the handle 112 116 if(this.handle.length == 1) this.previousHandle = this.handle; 113 114 115 117 if(this.handle.length == 2 && o.range) this.createRange(); 116 118 … … 127 129 }, 128 130 updateRange: function() { 129 this.rangeElement.css(this.properties[0], parseInt($(this.handle[0]).css(this.properties[0]),10) + this.handleSize(0)/2); 130 this.rangeElement.css(this.properties[1], parseInt($(this.handle[1]).css(this.properties[0]),10) - parseInt($(this.handle[0]).css(this.properties[0]),10)); 131 var prop = this.options.axis == "vertical" ? "top" : "left"; 132 var size = this.options.axis == "vertical" ? "height" : "width"; 133 this.rangeElement.css(prop, parseInt($(this.handle[0]).css(prop),10) + this.handleSize(0, this.options.axis == "vertical" ? 2 : 1)/2); 134 this.rangeElement.css(size, parseInt($(this.handle[1]).css(prop),10) - parseInt($(this.handle[0]).css(prop),10)); 131 135 }, 132 136 getRange: function() { 133 return this.rangeElement ? this.convertValue(parseInt(this.rangeElement.css(this. properties[1]),10)) : null;137 return this.rangeElement ? this.convertValue(parseInt(this.rangeElement.css(this.options.axis == "vertical" ? "height" : "width"),10)) : null; 134 138 }, 135 139 ui: function(e) { … … 138 142 options: this.options, 139 143 handle: this.currentHandle, 140 value: this.value(), 144 value: this.options.axis != "both" || !this.options.axis ? Math.round(this.value(null,this.options.axis == "vertical" ? 2 : 1)) : { 145 x: Math.round(this.value(null,1)), 146 y: Math.round(this.value(null,2)) 147 }, 141 148 range: this.getRange() 142 149 }; … … 170 177 if(this.currentHandle && this.currentHandle[0] == handle) { this.previousHandle = this.currentHandle; this.currentHandle = null; }; 171 178 }, 172 value: function(handle ) {179 value: function(handle, axis) { 173 180 if(this.handle.length == 1) this.currentHandle = this.handle; 174 var value = ((parseInt($(handle != undefined ? this.handle[handle] || handle : this.currentHandle).css(this.properties[0]),10) / (this.size() - this.handleSize())) * this.options.realMaxValue) + this.options.minValue; 181 if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; 182 183 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(null,axis))) * this.options.realMax[axis == 1 ? "x" : "y"]) + this.options.min[axis == 1 ? "x" : "y"]; 184 175 185 var o = this.options; 176 if (o.stepping ) {177 value = Math.round(value / o.stepping ) * o.stepping;186 if (o.stepping[axis == 1 ? "x" : "y"]) { 187 value = Math.round(value / o.stepping[axis == 1 ? "x" : "y"]) * o.stepping[axis == 1 ? "x" : "y"]; 178 188 } 179 189 return value; 180 190 }, 181 convertValue: function(value) { 182 return this.options.minValue + (value / (this.size() - this.handleSize())) * this.options.realMaxValue; 183 }, 184 translateValue: function(value) { 185 return ((value - this.options.minValue) / this.options.realMaxValue) * (this.size() - this.handleSize()); 186 }, 187 handleSize: function(handle) { 188 return $(handle != undefined ? this.handle[handle] : this.currentHandle)['outer'+this.properties[1].substr(0,1).toUpperCase()+this.properties[1].substr(1)](); 189 }, 190 size: function() { 191 // if actualSize is 0, the slider was hidden during initialization 192 return this.actualSize || (this.actualSize = this.element.outerWidth()); 191 convertValue: function(value,axis) { 192 if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; 193 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"]; 194 }, 195 translateValue: function(value,axis) { 196 if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; 197 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)); 198 }, 199 handleSize: function(handle,axis) { 200 if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; 201 return $(handle != undefined && handle !== null ? this.handle[handle] : this.currentHandle)[axis == 1 ? "outerWidth" : "outerHeight"](); 193 202 }, 194 203 click: function(e) { … … 207 216 //Move focussed handle to the clicked position 208 217 this.offset = this.element.offset(); 209 this.moveTo(this.convertValue(e[this.properties[0] == 'top' ? 'pageY' : 'pageX'] - this.offset[this.properties[0]] - this.handleSize()/2), null, true); 218 this.moveTo({ 219 y: this.convertValue(e.pageY - this.offset.top - this.currentHandle.outerHeight()/2), 220 x: this.convertValue(e.pageX - this.offset.left - this.currentHandle.outerWidth()/2) 221 }, null, true); 210 222 }, 211 223 start: function(e, handle) { 212 224 213 225 var o = this.options; 214 if(!this.currentHandle) this. currentHandle = this.previousHandle; //This is a especially ugly fix for strange blur events happening on mousemove events226 if(!this.currentHandle) this.focus(this.previousHandle, true); //This is a especially ugly fix for strange blur events happening on mousemove events 215 227 216 228 this.offset = this.element.offset(); … … 227 239 if (this.firstValue != this.value()) 228 240 this.propagate('change', e); 241 this.focus(this.currentHandle, true); //This is a especially ugly fix for strange blur events happening on mousemove events 229 242 return false; 230 243 }, 231 244 232 oneStep: function() { 233 return this.options.stepping ? this.options.stepping : (this.options.realMaxValue / this.size()) * 5; 234 }, 235 236 translateRange: function(value) { 245 oneStep: function(axis) { 246 if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; 247 return this.options.stepping[axis == 1 ? "x" : "y"] ? this.options.stepping[axis == 1 ? "x" : "y"] : (this.options.realMax[axis == 1 ? "x" : "y"] / this.actualSize[axis == 1 ? "width" : "height"]) * 5; 248 }, 249 250 translateRange: function(value,axis) { 237 251 if (this.rangeElement) { 238 if (this.currentHandle[0] == this.handle[0] && value >= this.translateValue(this.value(1) ))239 value = this.translateValue(this.value(1 ) - this.oneStep());240 if (this.currentHandle[0] == this.handle[1] && value <= this.translateValue(this.value(0) ))241 value = this.translateValue(this.value(0 ) + this.oneStep());252 if (this.currentHandle[0] == this.handle[0] && value >= this.translateValue(this.value(1),axis)) 253 value = this.translateValue(this.value(1,axis) - this.oneStep(axis), axis); 254 if (this.currentHandle[0] == this.handle[1] && value <= this.translateValue(this.value(0),axis)) 255 value = this.translateValue(this.value(0,axis) + this.oneStep(axis)); 242 256 } 243 257 if (this.options.handles) { 244 258 var handle = this.options.handles[this.handleIndex()]; 245 if (value < this.translateValue(handle.min )) {246 value = this.translateValue(handle.min );247 } else if (value > this.translateValue(handle.max )) {248 value = this.translateValue(handle.max );259 if (value < this.translateValue(handle.min,axis)) { 260 value = this.translateValue(handle.min,axis); 261 } else if (value > this.translateValue(handle.max,axis)) { 262 value = this.translateValue(handle.max,axis); 249 263 } 250 264 } … … 256 270 }, 257 271 258 translateLimits: function(value) { 259 if (value >= this.size() - this.handleSize()) 260 value = this.size() - this.handleSize(); 272 translateLimits: function(value,axis) { 273 if(!axis) axis = this.options.axis == "vertical" ? 2 : 1; 274 if (value >= this.actualSize[axis == 1 ? "width" : "height"] - this.handleSize(null,axis)) 275 value = this.actualSize[axis == 1 ? "width" : "height"] - this.handleSize(null,axis); 261 276 if (value <= 0) 262 277 value = 0; … … 265 280 266 281 drag: function(e, handle) { 282 267 283 var o = this.options; 268 284 var position = { top: e.pageY - this.offset.top - this.clickOffset.top, left: e.pageX - this.offset.left - this.clickOffset.left}; 269 if(!this.currentHandle) this.currentHandle = this.previousHandle; //This is a especially ugly fix for strange blur events happening on mousemove events 270 271 var modifier = position[this.properties[0]]; 272 273 modifier = this.translateLimits(modifier); 274 275 if (o.stepping) { 276 var value = this.convertValue(modifier); 277 value = Math.round(value / o.stepping) * o.stepping; 278 modifier = this.translateValue(value); 279 } 280 281 modifier = this.translateRange(modifier); 282 283 this.currentHandle.css(this.properties[0], modifier); 285 if(!this.currentHandle) this.focus(this.previousHandle, true); //This is a especially ugly fix for strange blur events happening on mousemove events 286 287 position.left = this.translateLimits(position.left,1); 288 position.top = this.translateLimits(position.top,2); 289 290 if (o.stepping.x) { 291 var value = this.convertValue(position.left,1); 292 value = Math.round(value / o.stepping.x) * o.stepping.x; 293 position.left = this.translateValue(value, 1); 294 } 295 if (o.stepping.y) { 296 var value = this.convertValue(position.top,2); 297 value = Math.round(value / o.stepping.y) * o.stepping.y; 298 position.top = this.translateValue(value, 2); 299 } 300 301 position.left = this.translateRange(position.left, 1); 302 position.top = this.translateRange(position.top, 2); 303 304 if(o.axis != "vertical") this.currentHandle.css({ left: position.left }); 305 if(o.axis != "horizontal") this.currentHandle.css({ top: position.top }); 306 284 307 if (this.rangeElement) 285 308 this.updateRange(); … … 296 319 if (handle != undefined) 297 320 this.currentHandle = this.previousHandle = $(this.handle[handle] || handle); 298 299 if(value.constructor == String) { 300 if (/^\-\=/.test(value) ) { 301 value = this.value() - parseInt(value.replace('-=', ''), 10); 302 } else if (/^\+\=/.test(value) ) { 303 value = this.value() + parseInt(value.replace('+=', ''), 10); 321 322 323 324 if(value.x !== undefined && value.y !== undefined) { 325 var x = value.x; 326 var y = value.y; 327 } else { 328 var x = value, y = value; 329 } 330 331 if(x && x.constructor != Number) { 332 if (/^\-\=/.test(x) ) { 333 x = this.value(null,1) - parseInt(x.replace('-=', ''), 10); 334 } else if (/^\+\=/.test(x) ) { 335 x = this.value(null,1) + parseInt(x.replace('+=', ''), 10); 304 336 } 305 337 } 306 338 307 if(o.stepping) 308 value = Math.round(value / o.stepping) * o.stepping; 309 value = this.translateValue(value); 310 value = this.translateLimits(value); 311 value = this.translateRange(value); 312 313 this.currentHandle.css(this.properties[0], value); 339 if(y && y.constructor != Number) { 340 if (/^\-\=/.test(y) ) { 341 y = this.value(null,2) - parseInt(y.replace('-=', ''), 10); 342 } else if (/^\+\=/.test(y) ) { 343 y = this.value(null,2) + parseInt(y.replace('+=', ''), 10); 344 } 345 } 346 347 if(o.axis != "vertical" && x) { 348 if(o.stepping.x) x = Math.round(x / o.stepping.x) * o.stepping.x; 349 x = this.translateValue(x, 1); 350 x = this.translateLimits(x, 1); 351 x = this.translateRange(x, 1); 352 this.currentHandle.css({ left: x }); 353 } 354 355 if(o.axis != "horizontal" && y) { 356 if(o.stepping.y) y = Math.round(y / o.stepping.y) * o.stepping.y; 357 y = this.translateValue(y, 2); 358 y = this.translateLimits(y, 2); 359 y = this.translateRange(y, 2); 360 this.currentHandle.css({ top: y }); 361 } 362 314 363 if (this.rangeElement) 315 364 this.updateRange();