Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2937

Show
Ignore:
Timestamp:
11/08/05 08:16:55 (3 years ago)
Author:
madrobby
Message:

Updated scriptaculous_slider plugin to latest .js version

Files:

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 
    24//  
    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. 
    423 
    524if(!Control) var Control = {}; 
     
    3352    this.values    = this.handles.map( function() { return 0 }); 
    3453    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 
    3557    this.restricted = this.options.restricted || false; 
    3658 
     
    6183    this.eventMouseMove = this.update.bindAsEventListener(this); 
    6284 
    63     // Initialize handles 
     85    // Initialize handles in reverse (make sure first handle is active) 
    6486    this.handles.each( function(h,i) { 
     87      i = slider.handles.length-1-i; 
    6588      slider.setValue(parseFloat( 
    6689        (slider.options.sliderValue instanceof Array ?  
     
    116139      this.activeHandle    = this.handles[handleIdx]; 
    117140      this.activeHandleIdx = handleIdx; 
     141      this.updateStyles(); 
    118142    } 
    119143    handleIdx = handleIdx || this.activeHandleIdx || 0; 
     
    132156     
    133157    this.drawSpans(); 
    134     this.updateFinished(); 
     158    if(!this.event) this.updateFinished(); 
    135159  }, 
    136160  setValueBy: function(delta, handleIdx) { 
     
    162186    var slider = this; 
    163187    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)); 
    165195  }, 
    166196  setSpan: function(span, range) { 
    167197    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); 
    170200    } 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'); 
    174208  }, 
    175209  startDrag: function(event) { 
     
    181215        var pointer  = [Event.pointerX(event), Event.pointerY(event)]; 
    182216        if(handle==this.track) { 
    183           var offsets  = Position.cumulativeOffset(this.track);           
     217          var offsets  = Position.cumulativeOffset(this.track);  
     218          this.event = event;          
    184219          this.setValue(this.translateToValue(  
    185220            this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0] 
     
    195230          this.activeHandle    = handle; 
    196231          this.activeHandleIdx = this.handles.indexOf(this.activeHandle); 
     232          this.updateStyles(); 
    197233         
    198234          var offsets  = Position.cumulativeOffset(this.activeHandle); 
     
    221257    pointer[0] -= this.offsetX + offsets[0]; 
    222258    pointer[1] -= this.offsetY + offsets[1]; 
     259    this.event = event; 
    223260    this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] )); 
    224261    if(this.initialized && this.options.onSlide) this.options.onSlide(this.values.length>1 ? this.values : this.value, this); 
     
    238275  }, 
    239276  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; 
    241280  } 
    242281} 
  • plugins/scriptaculous_slider/README

    r2836 r2937  
    2424copy/paste to your own CSS files). 
    2525 
    26 NOTE: This is very preliminary, better version coming soon. 
     26To see the full functionality and possibilities of the slider control, 
     27have a look a the functional and unit tests provided in the script.aculo.us 
     28SVN trunk, see http://wiki.script.aculo.us/scriptaculous/show/Versions. 
     29 
    2730For discussion of this plugin use the rails-spinoffs mailing list! 
    2831   
    29 Copyright (c) 2005 Thomas Fuchs, released under the MIT license 
     32Copyright (c) 2005 Marty Haught, Thomas Fuchs, released under the MIT license