To edit pages or tickets please login with username/password: aaf/aaf

Changeset 169

Show
Ignore:
Timestamp:
03/19/07 20:49:03 (2 years ago)
Author:
jk
Message:

tests for lazy loading

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/app/models/shared_index1.rb

    r142 r169  
    11class SharedIndex1 < ActiveRecord::Base 
    2   acts_as_ferret :single_index => true, :remote => ENV['AAF_REMOTE'] 
     2  # default field list for all classes sharing the index 
     3  DEFAULT_FIELDS = [ :name ] 
     4  acts_as_ferret( { :fields       => { :name => { :store => :yes } },  
     5                    :single_index => true,  
     6                    :remote       => ENV['AAF_REMOTE'] }, 
     7                  { :default_field => DEFAULT_FIELDS } ) 
    38end 
  • trunk/demo/app/models/shared_index2.rb

    r142 r169  
    11class SharedIndex2 < ActiveRecord::Base 
    2   acts_as_ferret :single_index => true, :remote => ENV['AAF_REMOTE'] 
     2  acts_as_ferret( { :fields       => { :name => { :store => :yes } },  
     3                    :single_index => true,  
     4                    :remote       => ENV['AAF_REMOTE'] },  
     5                  { :default_field => SharedIndex1::DEFAULT_FIELDS } ) 
    36end 
  • trunk/demo/config/boot.rb

    r28 r169  
    44  root_path = File.join(File.dirname(__FILE__), '..') 
    55 
    6   unless RUBY_PLATFORM =~ /mswin32
     6  unless RUBY_PLATFORM =~ /(:?mswin|mingw)
    77    require 'pathname' 
    88    root_path = Pathname.new(root_path).cleanpath(true).to_s 
     
    2323 
    2424    if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version 
    25       rails_gem = Gem.cache.search('rails', "=#{version}").first 
     25      # Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems 
     26      rails_gem = Gem.cache.search('rails', "~>#{version}.0").sort_by { |g| g.version.version }.last 
    2627 
    2728      if rails_gem 
    28         require_gem "rails", "=#{version}" 
     29        gem "rails", "=#{rails_gem.version.version}" 
    2930        require rails_gem.full_gem_path + '/lib/initializer' 
    3031      else 
    31         STDERR.puts %(Cannot find gem for Rails =#{version}
     32        STDERR.puts %(Cannot find gem for Rails ~>#{version}.0
    3233    Install the missing gem with 'gem install -v=#{version} rails', or 
    3334    change environment.rb to define RAILS_GEM_VERSION with your desired version. 
     
    3637      end 
    3738    else 
    38       require_gem "rails" 
     39      gem "rails" 
    3940      require 'initializer' 
    4041    end 
  • trunk/demo/public/javascripts/controls.js

    r28 r169  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 
    2 //           (c) 2005 Ivan Krstic (http://blogs.law.harvard.edu/ivan) 
    3 //           (c) 2005 Jon Tirsen (http://www.tirsen.com) 
     1// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 
     2//           (c) 2005, 2006 Ivan Krstic (http://blogs.law.harvard.edu/ivan) 
     3//           (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com) 
    44// Contributors: 
    55//  Richard Livsey 
     
    77//  Rob Wills 
    88//  
    9 // See scriptaculous.js for full license. 
     9// script.aculo.us is freely distributable under the terms of an MIT-style license. 
     10// For details, see the script.aculo.us web site: http://script.aculo.us/ 
    1011 
    1112// Autocompleter.Base handles all the autocompletion functionality  
     
    3334// useful when one of the tokens is \n (a newline), as it  
    3435// allows smart autocompletion after linebreaks. 
     36 
     37if(typeof Effect == 'undefined') 
     38  throw("controls.js requires including script.aculo.us' effects.js library"); 
    3539 
    3640var Autocompleter = {} 
     
    4650    this.entryCount  = 0; 
    4751 
    48     if (this.setOptions) 
     52    if(this.setOptions) 
    4953      this.setOptions(options); 
    5054    else 
     
    5660    this.options.minChars     = this.options.minChars || 1; 
    5761    this.options.onShow       = this.options.onShow ||  
    58     function(element, update){  
    59       if(!update.style.position || update.style.position=='absolute') { 
    60         update.style.position = 'absolute'; 
    61         Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight}); 
    62       } 
    63       Effect.Appear(update,{duration:0.15}); 
    64     }; 
     62      function(element, update){  
     63        if(!update.style.position || update.style.position=='absolute') { 
     64          update.style.position = 'absolute'; 
     65          Position.clone(element, update, { 
     66            setHeight: false,  
     67            offsetTop: element.offsetHeight 
     68          }); 
     69        } 
     70        Effect.Appear(update,{duration:0.15}); 
     71      }; 
    6572    this.options.onHide = this.options.onHide ||  
    66     function(element, update){ new Effect.Fade(update,{duration:0.15}) }; 
    67  
    68     if (typeof(this.options.tokens) == 'string')  
     73      function(element, update){ new Effect.Fade(update,{duration:0.15}) }; 
     74 
     75    if(typeof(this.options.tokens) == 'string')  
    6976      this.options.tokens = new Array(this.options.tokens); 
    7077 
     
    95102   
    96103  fixIEOverlapping: function() { 
    97     Position.clone(this.update, this.iefix); 
     104    Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)}); 
    98105    this.iefix.style.zIndex = 1; 
    99106    this.update.style.zIndex = 2; 
     
    203210    if(this.index > 0) this.index-- 
    204211      else this.index = this.entryCount-1; 
     212    this.getEntry(this.index).scrollIntoView(true); 
    205213  }, 
    206214   
     
    208216    if(this.index < this.entryCount-1) this.index++ 
    209217      else this.index = 0; 
     218    this.getEntry(this.index).scrollIntoView(false); 
    210219  }, 
    211220   
     
    255264      this.update.innerHTML = choices; 
    256265      Element.cleanWhitespace(this.update); 
    257       Element.cleanWhitespace(this.update.firstChild); 
    258  
    259       if(this.update.firstChild && this.update.firstChild.childNodes) { 
     266      Element.cleanWhitespace(this.update.down()); 
     267 
     268      if(this.update.firstChild && this.update.down().childNodes) { 
    260269        this.entryCount =  
    261           this.update.firstChild.childNodes.length; 
     270          this.update.down().childNodes.length; 
    262271        for (var i = 0; i < this.entryCount; i++) { 
    263272          var entry = this.getEntry(i); 
     
    270279 
    271280      this.stopIndicator(); 
    272  
    273281      this.index = 0; 
    274       this.render(); 
     282       
     283      if(this.entryCount==1 && this.options.autoSelect) { 
     284        this.selectEntry(); 
     285        this.hide(); 
     286      } else { 
     287        this.render(); 
     288      } 
    275289    } 
    276290  }, 
     
    460474 
    461475    this.options = Object.extend({ 
     476      paramName: "value", 
    462477      okButton: true, 
    463478      okText: "ok", 
     
    532547    this.createForm(); 
    533548    this.element.parentNode.insertBefore(this.form, this.element); 
    534     Field.scrollFreeActivate(this.editField); 
     549    if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField); 
    535550    // stop the event to avoid a page refresh in Safari 
    536551    if (evt) { 
     
    591606      textField.obj = this; 
    592607      textField.type = "text"; 
    593       textField.name = "value"
     608      textField.name = this.options.paramName
    594609      textField.value = text; 
    595610      textField.style.backgroundColor = this.options.highlightcolor; 
     
    604619      var textArea = document.createElement("textarea"); 
    605620      textArea.obj = this; 
    606       textArea.name = "value"
     621      textArea.name = this.options.paramName
    607622      textArea.value = this.convertHTMLLineBreaks(text); 
    608623      textArea.rows = this.options.rows; 
     
    637652    this.editField.disabled = false; 
    638653    this.editField.value = transport.responseText.stripTags(); 
     654    Field.scrollFreeActivate(this.editField); 
    639655  }, 
    640656  onclickCancel: function() { 
     
    773789        optionTag = document.createElement("option"); 
    774790        optionTag.value = (e instanceof Array) ? e[0] : e; 
     791        if((typeof this.options.value == 'undefined') &&  
     792          ((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true; 
    775793        if(this.options.value==optionTag.value) optionTag.selected = true; 
    776794        optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e)); 
  • trunk/demo/public/javascripts/dragdrop.js

    r28 r169  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 
    2 //           (c) 2005 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) 
     1// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 
     2//           (c) 2005, 2006 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) 
    33//  
    4 // See scriptaculous.js for full license. 
    5  
    6 /*--------------------------------------------------------------------------*/ 
     4// script.aculo.us is freely distributable under the terms of an MIT-style license. 
     5// For details, see the script.aculo.us web site: http://script.aculo.us/ 
     6 
     7if(typeof Effect == 'undefined') 
     8  throw("dragdrop.js requires including script.aculo.us' effects.js library"); 
    79 
    810var Droppables = { 
     
    146148   
    147149  activate: function(draggable) { 
    148     window.focus(); // allows keypress events if window isn't currently focused, fails for Safari 
    149     this.activeDraggable = draggable; 
     150    if(draggable.options.delay) {  
     151      this._timeout = setTimeout(function() {  
     152        Draggables._timeout = null;  
     153        window.focus();  
     154        Draggables.activeDraggable = draggable;  
     155      }.bind(this), draggable.options.delay);  
     156    } else { 
     157      window.focus(); // allows keypress events if window isn't currently focused, fails for Safari 
     158      this.activeDraggable = draggable; 
     159    } 
    150160  }, 
    151161   
     
    161171    if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return; 
    162172    this._lastPointer = pointer; 
     173     
    163174    this.activeDraggable.updateDrag(event, pointer); 
    164175  }, 
    165176   
    166177  endDrag: function(event) { 
     178    if(this._timeout) {  
     179      clearTimeout(this._timeout);  
     180      this._timeout = null;  
     181    } 
    167182    if(!this.activeDraggable) return; 
    168183    this._lastPointer = null; 
     
    191206        if(o[eventName]) o[eventName](eventName, draggable, event); 
    192207      }); 
     208    if(draggable.options[eventName]) draggable.options[eventName](draggable, event); 
    193209  }, 
    194210   
     
    205221 
    206222var Draggable = Class.create(); 
     223Draggable._dragging    = {}; 
     224 
    207225Draggable.prototype = { 
    208226  initialize: function(element) { 
    209     var options = Object.extend(
     227    var defaults =
    210228      handle: false, 
    211       starteffect: function(element) {  
    212         new Effect.Opacity(element, {duration:0.2, from:1.0, to:0.7});  
    213       }, 
    214229      reverteffect: function(element, top_offset, left_offset) { 
    215230        var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02; 
    216         element._revert = new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur}); 
     231        new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur, 
     232          queue: {scope:'_draggable', position:'end'} 
     233        }); 
    217234      }, 
    218       endeffect: function(element) {  
    219         new Effect.Opacity(element, {duration:0.2, from:0.7, to:1.0});  
     235      endeffect: function(element) { 
     236        var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0; 
     237        new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,  
     238          queue: {scope:'_draggable', position:'end'}, 
     239          afterFinish: function(){  
     240            Draggable._dragging[element] = false  
     241          } 
     242        });  
    220243      }, 
    221244      zindex: 1000, 
     
    224247      scrollSensitivity: 20, 
    225248      scrollSpeed: 15, 
    226       snap: false   // false, or xy or [x,y] or function(x,y){ return [x,y] } 
    227     }, arguments[1] || {}); 
     249      snap: false,  // false, or xy or [x,y] or function(x,y){ return [x,y] } 
     250      delay: 0 
     251    }; 
     252     
     253    if(!arguments[1] || typeof arguments[1].endeffect == 'undefined') 
     254      Object.extend(defaults, { 
     255        starteffect: function(element) { 
     256          element._opacity = Element.getOpacity(element); 
     257          Draggable._dragging[element] = true; 
     258          new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});  
     259        } 
     260      }); 
     261     
     262    var options = Object.extend(defaults, arguments[1] || {}); 
    228263 
    229264    this.element = $(element); 
    230265     
    231     if(options.handle && (typeof options.handle == 'string')) { 
    232       var h = Element.childrenWithClassName(this.element, options.handle, true); 
    233       if(h.length>0) this.handle = h[0]; 
    234     } 
     266    if(options.handle && (typeof options.handle == 'string')) 
     267      this.handle = this.element.down('.'+options.handle, 0); 
     268     
    235269    if(!this.handle) this.handle = $(options.handle); 
    236270    if(!this.handle) this.handle = this.element; 
    237271     
    238     if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) 
     272    if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) { 
    239273      options.scroll = $(options.scroll); 
     274      this._isScrollChild = Element.childOf(this.element, options.scroll); 
     275    } 
    240276 
    241277    Element.makePositioned(this.element); // fix IE     
     
    263299   
    264300  initDrag: function(event) { 
     301    if(typeof Draggable._dragging[this.element] != 'undefined' && 
     302      Draggable._dragging[this.element]) return; 
    265303    if(Event.isLeftClick(event)) {     
    266304      // abort on form elements, fixes a Firefox issue 
     
    273311        src.tagName=='TEXTAREA')) return; 
    274312         
    275       if(this.element._revert) { 
    276         this.element._revert.cancel(); 
    277         this.element._revert = null; 
    278       } 
    279        
    280313      var pointer = [Event.pointerX(event), Event.pointerY(event)]; 
    281314      var pos     = Position.cumulativeOffset(this.element); 
     
    313346     
    314347    Draggables.notify('onStart', this, event); 
     348         
    315349    if(this.options.starteffect) this.options.starteffect(this.element); 
    316350  }, 
     
    321355    Droppables.show(pointer, this.element); 
    322356    Draggables.notify('onDrag', this, event); 
     357     
    323358    this.draw(pointer); 
    324359    if(this.options.change) this.options.change(this); 
     
    332367      } else { 
    333368        p = Position.page(this.options.scroll); 
    334         p[0] += this.options.scroll.scrollLeft
    335         p[1] += this.options.scroll.scrollTop
     369        p[0] += this.options.scroll.scrollLeft + Position.deltaX
     370        p[1] += this.options.scroll.scrollTop + Position.deltaY
    336371        p.push(p[0]+this.options.scroll.offsetWidth); 
    337372        p.push(p[1]+this.options.scroll.offsetHeight); 
     
    379414    if(this.options.endeffect)  
    380415      this.options.endeffect(this.element); 
    381  
     416       
    382417    Draggables.deactivate(this); 
    383418    Droppables.reset(); 
     
    399434  draw: function(point) { 
    400435    var pos = Position.cumulativeOffset(this.element); 
     436    if(this.options.ghosting) { 
     437      var r   = Position.realOffset(this.element); 
     438      pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY; 
     439    } 
     440     
    401441    var d = this.currentDelta(); 
    402442    pos[0] -= d[0]; pos[1] -= d[1]; 
    403443     
    404     if(this.options.scroll && (this.options.scroll != window)) { 
     444    if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) { 
    405445      pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft; 
    406446      pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop; 
     
    413453    if(this.options.snap) { 
    414454      if(typeof this.options.snap == 'function') { 
    415         p = this.options.snap(p[0],p[1]); 
     455        p = this.options.snap(p[0],p[1],this); 
    416456      } else { 
    417457      if(this.options.snap instanceof Array) { 
     
    429469    if((!this.options.constraint) || (this.options.constraint=='vertical')) 
    430470      style.top  = p[1] + "px"; 
     471     
    431472    if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering 
    432473  }, 
     
    441482   
    442483  startScrolling: function(speed) { 
     484    if(!(speed[0] || speed[1])) return; 
    443485    this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed]; 
    444486    this.lastScrolled = new Date(); 
     
    465507    Droppables.show(Draggables._lastPointer, this.element); 
    466508    Draggables.notify('onDrag', this); 
    467     Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer); 
    468     Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000; 
    469     Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000; 
    470     if (Draggables._lastScrollPointer[0] < 0) 
    471       Draggables._lastScrollPointer[0] = 0; 
    472     if (Draggables._lastScrollPointer[1] < 0) 
    473       Draggables._lastScrollPointer[1] = 0; 
    474     this.draw(Draggables._lastScrollPointer); 
     509    if (this._isScrollChild) { 
     510      Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer); 
     511      Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000; 
     512      Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000; 
     513      if (Draggables._lastScrollPointer[0] < 0) 
     514        Draggables._lastScrollPointer[0] = 0; 
     515      if (Draggables._lastScrollPointer[1] < 0) 
     516        Draggables._lastScrollPointer[1] = 0; 
     517      this.draw(Draggables._lastScrollPointer); 
     518    } 
    475519     
    476520    if(this.options.change) this.options.change(this); 
     
    524568 
    525569var Sortable = { 
     570  SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/, 
     571   
    526572  sortables: {}, 
    527573   
     
    564610      handle:      false,      // or a CSS class 
    565611      only:        false, 
     612      delay:       0, 
    566613      hoverclass:  null, 
    567614      ghosting:    false, 
     
    569616      scrollSensitivity: 20, 
    570617      scrollSpeed: 15, 
    571       format:      /^[^_]*_(.*)$/
     618      format:      this.SERIALIZE_RULE
    572619      onChange:    Prototype.emptyFunction, 
    573620      onUpdate:    Prototype.emptyFunction 
     
    583630      scrollSpeed: options.scrollSpeed, 
    584631      scrollSensitivity: options.scrollSensitivity, 
     632      delay:       options.delay, 
    585633      ghosting:    options.ghosting, 
    586634      constraint:  options.constraint, 
     
    611659      hoverclass:  options.hoverclass, 
    612660      onHover:     Sortable.onHover 
    613       //greedy:      !options.dropOnEmpty 
    614661    } 
    615662     
     
    636683      // handles are per-draggable 
    637684      var handle = options.handle ?  
    638         Element.childrenWithClassName(e, options.handle)[0] : e;     
     685        $(e).down('.'+options.handle,0) : e;     
    639686      options.draggables.push( 
    640687        new Draggable(e, Object.extend(options_for_draggable, { handle: handle }))); 
     
    707754      var index; 
    708755       
    709       var children = Sortable.findElements(dropon, {tag: droponOptions.tag}); 
     756      var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only}); 
    710757      var child = null; 
    711758             
     
    734781 
    735782  unmark: function() { 
    736     if(Sortable._marker) Element.hide(Sortable._marker); 
     783    if(Sortable._marker) Sortable._marker.hide(); 
    737784  }, 
    738785 
     
    743790 
    744791    if(!Sortable._marker) { 
    745       Sortable._marker = $('dropmarker') || document.createElement('DIV'); 
    746       Element.hide(Sortable._marker); 
    747       Element.addClassName(Sortable._marker, 'dropmarker'); 
    748       Sortable._marker.style.position = 'absolute'; 
     792      Sortable._marker =  
     793        ($('dropmarker') || Element.extend(document.createElement('DIV'))). 
     794          hide().addClassName('dropmarker').setStyle({position:'absolute'}); 
    749795      document.getElementsByTagName("body").item(0).appendChild(Sortable._marker); 
    750796    }     
    751797    var offsets = Position.cumulativeOffset(dropon); 
    752     Sortable._marker.style.left = offsets[0] + 'px'; 
    753     Sortable._marker.style.top = offsets[1] + 'px'; 
     798    Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'}); 
    754799     
    755800    if(position=='after') 
    756801      if(sortable.overlap == 'horizontal')  
    757         Sortable._marker.style.left = (offsets[0]+dropon.clientWidth) + 'px'
     802        Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'})
    758803      else 
    759         Sortable._marker.style.top = (offsets[1]+dropon.clientHeight) + 'px'
    760      
    761     Element.show(Sortable._marker); 
     804        Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'})
     805     
     806    Sortable._marker.show(); 
    762807  }, 
    763808   
     
    774819        element: element, 
    775820        parent: parent, 
    776         children: new Array
     821        children: []
    777822        position: parent.children.length, 
    778         container: Sortable._findChildrenElement(children[i], options.treeTag.toUpperCase()
     823        container: $(children[i]).down(options.treeTag
    779824      } 
    780825       
     
    787832 
    788833    return parent;  
    789   }, 
    790  
    791   /* Finds the first element of the given tag type within a parent element. 
    792     Used for finding the first LI[ST] within a L[IST]I[TEM].*/ 
    793   _findChildrenElement: function (element, containerTag) { 
    794     if (element && element.hasChildNodes) 
    795       for (var i = 0; i < element.childNodes.length; ++i) 
    796         if (element.childNodes[i].tagName == containerTag) 
    797           return element.childNodes[i]; 
    798    
    799     return null; 
    800834  }, 
    801835 
     
    814848      id: null, 
    815849      parent: null, 
    816       children: new Array
     850      children: []
    817851      container: element, 
    818852      position: 0 
    819853    } 
    820854     
    821     return Sortable._tree (element, options, root); 
     855    return Sortable._tree(element, options, root); 
    822856  }, 
    823857 
     
    868902    if (options.tree) { 
    869903      return Sortable.tree(element, arguments[1]).children.map( function (item) { 
    870         return [name + Sortable._constructIndex(item) + "=" +  
     904        return [name + Sortable._constructIndex(item) + "[id]=" +  
    871905                encodeURIComponent(item.id)].concat(item.children.map(arguments.callee)); 
    872906      }).flatten().join('&'); 
     
    879913} 
    880914 
    881 /* Returns true if child is contained within element */ 
     915// Returns true if child is contained within element 
    882916Element.isParent = function(child, element) { 
    883917  if (!child.parentNode || child == element) return false; 
    884  
    885918  if (child.parentNode == element) return true; 
    886  
    887919  return Element.isParent(child.parentNode, element); 
    888920} 
     
    907939 
    908940Element.offsetSize = function (element, type) { 
    909   if (type == 'vertical' || type == 'height') 
    910     return element.offsetHeight; 
    911   else 
    912     return element.offsetWidth; 
     941  return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')]; 
    913942} 
  • trunk/demo/public/javascripts/effects.js

    r28 r169  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 
     1// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 
    22// Contributors: 
    33//  Justin Palmer (http://encytemedia.com/) 
     
    55//  Martin Bialasinki 
    66//  
    7 // See scriptaculous.js for full license.   
     7// script.aculo.us is freely distributable under the terms of an MIT-style license. 
     8// For details, see the script.aculo.us web site: http://script.aculo.us/  
    89 
    910// converts rgb() and #xxx to #xxxxxx format,   
    1011// returns self (or first argument) if not convertable   
    1112String.prototype.parseColor = function() {   
    12   var color = '#';   
     13  var color = '#'; 
    1314  if(this.slice(0,4) == 'rgb(') {   
    1415    var cols = this.slice(4,this.length-1).split(',');   
     
    4243Element.setContentZoom = function(element, percent) { 
    4344  element = $(element);   
    44   Element.setStyle(element, {fontSize: (percent/100) + 'em'});    
     45  element.setStyle({fontSize: (percent/100) + 'em'});    
    4546  if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); 
    46 
    47  
    48 Element.getOpacity = function(element){   
     47  return element; 
     48
     49 
     50Element.getOpacity = function(element){ 
     51  element = $(element); 
    4952  var opacity; 
    50   if (opacity = Element.getStyle(element, 'opacity'))   
     53  if (opacity = element.getStyle('opacity'))   
    5154    return parseFloat(opacity);   
    52   if (opacity = (Element.getStyle(element, 'filter') || '').match(/alpha\(opacity=(.*)\)/))   
     55  if (opacity = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))   
    5356    if(opacity[1]) return parseFloat(opacity[1]) / 100;   
    5457  return 1.0;   
     
    5861  element= $(element);   
    5962  if (value == 1){ 
    60     Element.setStyle(element, { opacity:  
     63    element.setStyle({ opacity:  
    6164      (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ?  
    62       0.999999 : null }); 
    63     if(/MSIE/.test(navigator.userAgent))   
    64       Element.setStyle(element, {filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});   
     65      0.999999 : 1.0 }); 
     66    if(/MSIE/.test(navigator.userAgent) && !window.opera)   
     67      element.setStyle({filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});   
    6568  } else {   
    6669    if(value < 0.00001) value = 0;   
    67     Element.setStyle(element, {opacity: value}); 
    68     if(/MSIE/.test(navigator.userAgent))   
    69      Element.setStyle(element,  
    70        { filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') + 
    71                  'alpha(opacity='+value*100+')' });   
    72   } 
     70    element.setStyle({opacity: value}); 
     71    if(/MSIE/.test(navigator.userAgent) && !window.opera)   
     72      element.setStyle( 
     73        { filter: element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') + 
     74            'alpha(opacity='+value*100+')' });   
     75  } 
     76  return element; 
    7377 
    7478  
     
    7680  return $(element).style.opacity || ''; 
    7781 
    78  
    79 Element.childrenWithClassName = function(element, className, findFirst) { 
    80   var classNameRegExp = new RegExp("(^|\\s)" + className + "(\\s|$)"); 
    81   var results = $A($(element).getElementsByTagName('*'))[findFirst ? 'detect' : 'select']( function(c) {  
    82     return (c.className && c.className.match(classNameRegExp)); 
    83   }); 
    84   if(!results) results = []; 
    85   return results; 
    86 } 
    8782 
    8883Element.forceRerendering = function(element) { 
     
    105100 
    106101var Effect = { 
     102  _elementDoesNotExistError: { 
     103    name: 'ElementDoesNotExistError', 
     104    message: 'The specified DOM element does not exist, but is required for this effect to operate' 
     105  }, 
    107106  tagifyText: function(element) { 
     107    if(typeof Builder == 'undefined') 
     108      throw("Effect.tagifyText requires including script.aculo.us' builder.js library"); 
     109       
    108110    var tagifyStyle = 'position:relative'; 
    109     if(/MSIE/.test(navigator.userAgent)) tagifyStyle += ';zoom:1'; 
     111    if(/MSIE/.test(navigator.userAgent) && !window.opera) tagifyStyle += ';zoom:1'; 
     112     
    110113    element = $(element); 
    111114    $A(element.childNodes).each( function(child) { 
     
    160163/* ------------- transitions ------------- */ 
    161164 
    162 Effect.Transitions = {} 
    163  
    164 Effect.Transitions.linear = function(pos) { 
    165   return pos; 
    166 
    167 Effect.Transitions.sinoidal = function(pos) { 
    168   return (-Math.cos(pos*Math.PI)/2) + 0.5; 
    169 
    170 Effect.Transitions.reverse  = function(pos) { 
    171   return 1-pos; 
    172 
    173 Effect.Transitions.flicker = function(pos) { 
    174   return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 
    175 
    176 Effect.Transitions.wobble = function(pos) { 
    177   return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; 
    178 
    179 Effect.Transitions.pulse = function(pos) { 
    180   return (Math.floor(pos*10) % 2 == 0 ?  
    181     (pos*10-Math.floor(pos*10)) : 1-(pos*10-Math.floor(pos*10))); 
    182 
    183 Effect.Transitions.none = function(pos) { 
    184   return 0; 
    185 
    186 Effect.Transitions.full = function(pos) { 
    187   return 1; 
    188 
     165Effect.Transitions = { 
     166  linear: Prototype.K, 
     167  sinoidal: function(pos) { 
     168    return (-Math.cos(pos*Math.PI)/2) + 0.5; 
     169  }, 
     170  reverse: function(pos) { 
     171    return 1-pos; 
     172  }, 
     173  flicker: function(pos) { 
     174    return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 
     175  }, 
     176  wobble: function(pos) { 
     177    return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; 
     178  }, 
     179  pulse: function(pos, pulses) {  
     180    pulses = pulses || 5;  
     181    return ( 
     182      Math.round((pos % (1/pulses)) * pulses) == 0 ?  
     183            ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) :  
     184        1 - ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) 
     185      ); 
     186  }, 
     187  none: function(pos) { 
     188    return 0; 
     189  }, 
     190  full: function(pos) { 
     191    return 1; 
     192  } 
     193}; 
    189194 
    190195/* ------------- core effects ------------- */ 
     
    212217            e.finishOn += effect.finishOn; 
    213218          }); 
     219        break; 
     220      case 'with-last': 
     221        timestamp = this.effects.pluck('startOn').max() || timestamp; 
    214222        break; 
    215223      case 'end': 
     
    349357}); 
    350358 
     359Effect.Event = Class.create(); 
     360Object.extend(Object.extend(Effect.Event.prototype, Effect.Base.prototype), { 
     361  initialize: function() { 
     362    var options = Object.extend({ 
     363      duration: 0 
     364    }, arguments[0] || {}); 
     365    this.start(options); 
     366  }, 
     367  update: Prototype.emptyFunction 
     368}); 
     369 
    351370Effect.Opacity = Class.create(); 
    352371Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), { 
    353372  initialize: function(element) { 
    354373    this.element = $(element); 
     374    if(!this.element) throw(Effect._elementDoesNotExistError); 
    355375    // make this work on IE on elements without 'layout' 
    356     if(/MSIE/.test(navigator.userAgent) && (!this.element.hasLayout)) 
     376    if(/MSIE/.test(navigator.userAgent) && !window.opera && (!this.element.currentStyle.hasLayout)) 
    357377      this.element.setStyle({zoom: 1}); 
    358378    var options = Object.extend({ 
     
    371391  initialize: function(element) { 
    372392    this.element = $(element); 
     393    if(!this.element) throw(Effect._elementDoesNotExistError); 
    373394    var options = Object.extend({ 
    374395      x:    0, 
     
    394415  update: function(position) { 
    395416    this.element.setStyle({ 
    396       left: this.options.x  * position + this.originalLeft + 'px', 
    397       top:  this.options.y  * position + this.originalTop  + 'px' 
     417      left: Math.round(this.options.x  * position + this.originalLeft) + 'px', 
     418      top:  Math.round(this.options.y  * position + this.originalTop)  + 'px' 
    398419    }); 
    399420  } 
     
    409430Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), { 
    410431  initialize: function(element, percent) { 
    411     this.element = $(element) 
     432    this.element = $(element); 
     433    if(!this.element) throw(Effect._elementDoesNotExistError); 
    412434    var options = Object.extend({ 
    413435      scaleX: true, 
     
    434456     
    435457    var fontSize = this.element.getStyle('font-size') || '100%'; 
    436     ['em','px','%'].each( function(fontSizeType) { 
     458    ['em','px','%','pt'].each( function(fontSizeType) { 
    437459      if(fontSize.indexOf(fontSizeType)>0) { 
    438460        this.fontSize     = parseFloat(fontSize); 
     
    459481  }, 
    460482  finish: function(position) { 
    461     if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle); 
     483    if(this.restoreAfterFinish) this.element.setStyle(this.originalStyle); 
    462484  }, 
    463485  setDimensions: function(height, width) { 
    464486    var d = {}; 
    465     if(this.options.scaleX) d.width = width + 'px'; 
    466     if(this.options.scaleY) d.height = height + 'px'; 
     487    if(this.options.scaleX) d.width = Math.round(width) + 'px'; 
     488    if(this.options.scaleY) d.height = Math.round(height) + 'px'; 
    467489    if(this.options.scaleFromCenter) { 
    468490      var topd  = (height - this.dims[0])/2; 
     
    484506  initialize: function(element) { 
    485507    this.element = $(element); 
     508    if(!this.element) throw(Effect._elementDoesNotExistError); 
    486509    var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {}); 
    487510    this.start(options); 
     
    548571  afterFinishInternal: function(effect) {  
    549572    if(effect.options.to!=0) return; 
    550     effect.element.hide(); 
    551     effect.element.setStyle({opacity: oldOpacity});  
     573    effect.element.hide().setStyle({opacity: oldOpacity});  
    552574  }}, arguments[1] || {}); 
    553575  return new Effect.Opacity(element,options); 
     
    564586  }, 
    565587  beforeSetup: function(effect) { 
    566     effect.element.setOpacity(effect.options.from); 
    567     effect.element.show();  
     588    effect.element.setOpacity(effect.options.from).show();  
    568589  }}, arguments[1] || {}); 
    569590  return new Effect.Opacity(element,options); 
     
    572593Effect.Puff = function(element) { 
    573594  element = $(element); 
    574   var oldStyle = { opacity: element.getInlineOpacity(), position: element.getStyle('position') }; 
     595  var oldStyle = {  
     596    opacity: element.getInlineOpacity(),  
     597    position: element.getStyle('position'), 
     598    top:  element.style.top, 
     599    left: element.style.left, 
     600    width: element.style.width, 
     601    height: element.style.height 
     602  }; 
    575603  return new Effect.Parallel( 
    576604   [ new Effect.Scale(element, 200,  
     
    579607     Object.extend({ duration: 1.0,  
    580608      beforeSetupInternal: function(effect) { 
    581         effect.effects[0].element.setStyle({position: 'absolute'}); }, 
     609        Position.absolutize(effect.effects[0].element) 
     610      }, 
    582611      afterFinishInternal: function(effect) { 
    583          effect.effects[0].element.hide(); 
    584          effect.effects[0].element.setStyle(oldStyle); } 
     612         effect.effects[0].element.hide().setStyle(oldStyle); } 
    585613     }, arguments[1] || {}) 
    586614   ); 
     
    590618  element = $(element); 
    591619  element.makeClipping(); 
    592   return new Effect.Scale(element, 0,  
     620  return new Effect.Scale(element, 0, 
    593621    Object.extend({ scaleContent: false,  
    594622      scaleX: false,  
    595623      restoreAfterFinish: true, 
    596624      afterFinishInternal: function(effect) { 
    597         effect.element.hide(); 
    598         effect.element.undoClipping(); 
     625        effect.element.hide().undoClipping(); 
    599626      }  
    600627    }, arguments[1] || {}) 
     
    605632  element = $(element); 
    606633  var elementDimensions = element.getDimensions(); 
    607   return new Effect.Scale(element, 100,  
    608     Object.extend({ scaleContent: false,  
    609       scaleX: false, 
    610       scaleFrom: 0, 
    611       scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 
    612       restoreAfterFinish: true, 
    613       afterSetup: function(effect) { 
    614         effect.element.makeClipping(); 
    615         effect.element.setStyle({height: '0px'}); 
    616         effect.element.show();  
    617       },   
    618       afterFinishInternal: function(effect) { 
    619         effect.element.undoClipping(); 
    620       } 
    621     }, arguments[1] || {}) 
    622   ); 
     634  return new Effect.Scale(element, 100, Object.extend({  
     635    scaleContent: false,  
     636    scaleX: false, 
     637    scaleFrom: 0, 
     638    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 
     639    restoreAfterFinish: true, 
     640    afterSetup: function(effect) { 
     641      effect.element.makeClipping().setStyle({height: '0px'}).show();  
     642    },   
     643    afterFinishInternal: function(effect) { 
     644      effect.element.undoClipping(); 
     645    } 
     646  }, arguments[1] || {})); 
    623647} 
    624648 
     
    626650  element = $(element); 
    627651  var oldOpacity = element.getInlineOpacity(); 
    628   return new Effect.Appear(element, {  
     652  return new Effect.Appear(element, Object.extend({ 
    629653    duration: 0.4, 
    630654    from: 0, 
     
    635659        scaleX: false, scaleContent: false, restoreAfterFinish: true, 
    636660        beforeSetup: function(effect) {  
    637           effect.element.makePositioned(); 
    638           effect.element.makeClipping(); 
     661          effect.element.makePositioned().makeClipping(); 
    639662        }, 
    640663        afterFinishInternal: function(effect) { 
    641           effect.element.hide(); 
    642           effect.element.undoClipping(); 
    643           effect.element.undoPositioned(); 
    644           effect.element.setStyle({opacity: oldOpacity}); 
     664          effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity}); 
    645665        } 
    646666      }) 
    647667    } 
    648   }); 
     668  }, arguments[1] || {})); 
    649669} 
    650670 
     
    664684        }, 
    665685        afterFinishInternal: function(effect) { 
    666           effect.effects[0].element.hide(); 
    667           effect.effects[0].element.undoPositioned(); 
    668           effect.effects[0].element.setStyle(oldStyle); 
     686          effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle); 
    669687        }  
    670688      }, arguments[1] ||