Changeset 2937
- Timestamp:
- 11/08/05 08:16:55 (3 years ago)
- Files:
-
- plugins/scriptaculous_slider/CHANGELOG (added)
- plugins/scriptaculous_slider/javascripts/slider.js (modified) (10 diffs)
- plugins/scriptaculous_slider/README (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/scriptaculous_slider/javascripts/slider.js
r2824 r2937 1 // Copyright (c) 2005 Marty Haught 1 // Copyright (c) 2005 Marty Haught, Thomas Fuchs 2 // 3 // See http://script.aculo.us for more info 2 4 // 3 // See scriptaculous.js for full license. 5 // Permission is hereby granted, free of charge, to any person obtaining 6 // a copy of this software and associated documentation files (the 7 // "Software"), to deal in the Software without restriction, including 8 // without limitation the rights to use, copy, modify, merge, publish, 9 // distribute, sublicense, and/or sell copies of the Software, and to 10 // permit persons to whom the Software is furnished to do so, subject to 11 // the following conditions: 12 // 13 // The above copyright notice and this permission notice shall be 14 // included in all copies or substantial portions of the Software. 15 // 16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 4 23 5 24 if(!Control) var Control = {}; … … 33 52 this.values = this.handles.map( function() { return 0 }); 34 53 this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false; 54 this.options.startSpan = $(this.options.startSpan || null); 55 this.options.endSpan = $(this.options.endSpan || null); 56 35 57 this.restricted = this.options.restricted || false; 36 58 … … 61 83 this.eventMouseMove = this.update.bindAsEventListener(this); 62 84 63 // Initialize handles 85 // Initialize handles in reverse (make sure first handle is active) 64 86 this.handles.each( function(h,i) { 87 i = slider.handles.length-1-i; 65 88 slider.setValue(parseFloat( 66 89 (slider.options.sliderValue instanceof Array ? … … 116 139 this.activeHandle = this.handles[handleIdx]; 117 140 this.activeHandleIdx = handleIdx; 141 this.updateStyles(); 118 142 } 119 143 handleIdx = handleIdx || this.activeHandleIdx || 0; … … 132 156 133 157 this.drawSpans(); 134 this.updateFinished();158 if(!this.event) this.updateFinished(); 135 159 }, 136 160 setValueBy: function(delta, handleIdx) { … … 162 186 var slider = this; 163 187 if(this.spans) 164 $R(0, this.spans.length-1).each(function(r) { slider.setSpan(r, slider.getRange(r)) }); 188 $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) }); 189 if(this.options.startSpan) 190 this.setSpan(this.options.startSpan, 191 $R(0, this.values.length>1 ? this.getRange(0).min() : this.value )); 192 if(this.options.endSpan) 193 this.setSpan(this.options.endSpan, 194 $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum)); 165 195 }, 166 196 setSpan: function(span, range) { 167 197 if(this.isVertical()) { 168 this.spans[span].style.top = this.translateToPx(range.start);169 this.spans[span].style.height = this.translateToPx(range.end - range.start);198 span.style.top = this.translateToPx(range.start); 199 span.style.height = this.translateToPx(range.end - range.start); 170 200 } else { 171 this.spans[span].style.left = this.translateToPx(range.start); 172 this.spans[span].style.width = this.translateToPx(range.end - range.start); 173 } 201 span.style.left = this.translateToPx(range.start); 202 span.style.width = this.translateToPx(range.end - range.start); 203 } 204 }, 205 updateStyles: function() { 206 this.handles.each( function(h){ Element.removeClassName(h, 'selected') }); 207 Element.addClassName(this.activeHandle, 'selected'); 174 208 }, 175 209 startDrag: function(event) { … … 181 215 var pointer = [Event.pointerX(event), Event.pointerY(event)]; 182 216 if(handle==this.track) { 183 var offsets = Position.cumulativeOffset(this.track); 217 var offsets = Position.cumulativeOffset(this.track); 218 this.event = event; 184 219 this.setValue(this.translateToValue( 185 220 this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0] … … 195 230 this.activeHandle = handle; 196 231 this.activeHandleIdx = this.handles.indexOf(this.activeHandle); 232 this.updateStyles(); 197 233 198 234 var offsets = Position.cumulativeOffset(this.activeHandle); … … 221 257 pointer[0] -= this.offsetX + offsets[0]; 222 258 pointer[1] -= this.offsetY + offsets[1]; 259 this.event = event; 223 260 this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] )); 224 261 if(this.initialized && this.options.onSlide) this.options.onSlide(this.values.length>1 ? this.values : this.value, this); … … 238 275 }, 239 276 updateFinished: function() { 240 if(this.initialized && this.options.onChange) this.options.onChange(this.values.length>1 ? this.values : this.value, this); 277 if(this.initialized && this.options.onChange) 278 this.options.onChange(this.values.length>1 ? this.values : this.value, this); 279 this.event = null; 241 280 } 242 281 } plugins/scriptaculous_slider/README
r2836 r2937 24 24 copy/paste to your own CSS files). 25 25 26 NOTE: This is very preliminary, better version coming soon. 26 To see the full functionality and possibilities of the slider control, 27 have a look a the functional and unit tests provided in the script.aculo.us 28 SVN trunk, see http://wiki.script.aculo.us/scriptaculous/show/Versions. 29 27 30 For discussion of this plugin use the rails-spinoffs mailing list! 28 31 29 Copyright (c) 2005 Thomas Fuchs, released under the MIT license32 Copyright (c) 2005 Marty Haught, Thomas Fuchs, released under the MIT license