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

Changeset 2764

Show
Ignore:
Timestamp:
10/27/05 14:14:36 (3 years ago)
Author:
madrobby
Message:

script.aculo.us: Make Effect.Queue an Enumerable, fix a problem with Effect.Grow, more unit tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/scriptaculous/CHANGELOG

    r2760 r2764  
    11*SVN* 
     2 
     3* Make Effect.Queue an Enumerable, fix a problem with Effect.Grow, more unit tests 
    24 
    35* Added restricted option to prevent moved of handles prior/after adjacent handles on Sliders with multiple handles 
  • spinoffs/scriptaculous/src/effects.js

    r2708 r2764  
    2424  return(color.length==7 ? color : (arguments[0] || this));   
    2525 
    26   
     26 
    2727Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {   
    2828  var children = $(element).childNodes;   
     
    3939  }   
    4040  
    41   return text;   
    42 }   
    43   
     41  return text; 
     42} 
     43 
    4444Element.setContentZoom = function(element, percent) {   
    4545  element = $(element);   
    4646  element.style.fontSize = (percent/100) + "em";    
    4747  if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);   
    48 }   
    49   
     48} 
     49 
    5050Element.getOpacity = function(element){   
    5151  var opacity;   
     
    5555    if(opacity[1]) return parseFloat(opacity[1]) / 100;   
    5656  return 1.0;   
    57 }   
    58   
     57} 
     58 
    5959Element.setOpacity = function(element, value){   
    6060  element= $(element);   
     
    257257Effect.Queue = { 
    258258  effects:  [], 
     259  _each: function(iterator) { 
     260    this.effects._each(iterator); 
     261  }, 
    259262  interval: null, 
    260263  add: function(effect) { 
     
    293296  } 
    294297} 
     298Object.extend(Effect.Queue, Enumerable); 
    295299 
    296300Effect.Base = function() {}; 
     
    873877               els.left = oldLeft; 
    874878               els.height = oldHeight; 
    875                els.width = originalWidth
     879               els.width = originalWidth + 'px'
    876880               Element.setInlineOpacity(el, oldOpacity); 
    877881             } 
  • spinoffs/scriptaculous/test/functional/effects4_test.html

    r1990 r2764  
    1818<h1>script.aculo.us Effects functional test file</h1> 
    1919 
    20 <h2>Effect2.Highlight</h2> 
     20<a href="#" onclick="new Effect.Highlight('d1',{duration:1.5}); return false;">Highlight</a> | 
     21<a href="#" onclick="new Effect.BlindUp('d1',{duration:1.5}); return false;">BlindUp</a> | 
     22<a href="#" onclick="new Effect.BlindDown('d1',{duration:1.5}); return false;">BlindDown</a> | 
     23<a href="#" onclick="new Effect.SlideUp('d1',{duration:1.5}); return false;">SlideUp</a> | 
     24<a href="#" onclick="new Effect.SlideDown('d1',{duration:1.5}); return false;">SlideDown</a> 
    2125 
    22 <a href="#" onclick="new Effect.Highlight('d1',{duration:1.5}); return false;">Highlight</a> 
    23  
    24 <div id="d1"> 
    25 <p> 
     26<div id="d1"><div style="overflow:hidden"> 
    2627Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas enim. Nulla facilisi. Vestibulum accumsan augue vulputate justo. Fusce faucibus. Sed blandit, neque sed lacinia nonummy, diam quam imperdiet justo, at dictum augue nunc a neque. Sed urna lacus, tincidunt at, aliquam id, fringilla id, felis. Vivamus feugiat molestie quam. Sed id dolor. Sed ac purus id sapien sollicitudin ultricies. Aliquam hendrerit orci et odio. Suspendisse volutpat wisi at sem. Integer eget nulla. Duis eu diam a nunc condimentum tempus. Praesent gravida metus vitae massa. Aliquam neque magna, fringilla eu, porta id, interdum sit amet, dui. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin lorem est, ultrices sit amet, condimentum vitae, vehicula a, massa. 
    27 </p> 
    28 </div> 
     28</div></div> 
    2929 
    3030</body> 
  • spinoffs/scriptaculous/test/unit/effects_test.html

    r2502 r2764  
    3232    ['Fade','Appear','BlindUp','BlindDown','Puff','SwitchOff','DropOut','Shake', 
    3333     'SlideUp','SlideDown','Pulsate','Squish','Fold','Grow','Shrink']; 
     34      
     35  var tmp, tmp2; 
    3436 
    3537  new Test.Unit.Runner({ 
     
    3739    setup: function() { with (this) { 
    3840      $('sandbox').innerHTML = ""; 
     41    }}, 
     42     
     43    teardown: function() { with(this) { 
     44      // remove all queued effects 
     45      Effect.Queue.each(function(e) { e.cancel() }); 
     46    }}, 
     47     
     48    testBackwardsCompat: function() { with(this) { 
     49      assertInstanceOf(Effect.Opacity, new Effect2.Fade('sandbox')); 
     50    }}, 
     51     
     52    testCallbacks: function() { with(this) { 
     53      tmp = tmp2 = 0; 
     54      var e1 = new Effect.Opacity('sandbox',{from:1.0,to:0.5,duration:0.5, 
     55        beforeStart: function() { tmp++ }, 
     56        beforeStartInternal: function() { tmp++ }, 
     57        beforeSetup: function() { tmp++ }, 
     58        beforeSetupInternal: function() { tmp++ }, 
     59        afterSetup: function() { tmp++ }, 
     60        afterSetupInternal: function() { tmp++ }, 
     61        beforeUpdate: function() { tmp2++ }, 
     62        beforeUpdateInternal: function() { tmp2++ }, 
     63        beforeFinish: function() { tmp++ }, 
     64        beforeFinishInternal: function() { tmp++ }, 
     65        afterFinish: function() { tmp++ }, 
     66        afterFinishInternal: function() { tmp++ } 
     67      }); 
     68      wait(1000, function() { 
     69        assertEqual(10, tmp); 
     70        assert(tmp2 > 0); 
     71      }); 
     72    }}, 
     73     
     74    testEffectsQueue: function() { with(this) { 
     75      var e1 = new Effect.Highlight('sandbox'); 
     76      var e2 = new Effect.Appear('sandbox'); 
     77       
     78      assertEqual(2, Effect.Queue.effects.length); 
     79       
     80      tmp = 0; 
     81      Effect.Queue.each(function(e) { tmp++ }); 
     82      assertEqual(2, tmp); 
     83       
     84      // the internal interval timer should be active 
     85      assertNotNull(Effect.Queue.interval); 
     86      e1.cancel(); 
     87      e2.cancel(); 
     88      assertEqual(0, Effect.Queue.effects.length); 
     89       
     90      // should be inactive after all effects are removed from queue 
     91      assertNull(Effect.Queue.interval); 
     92       
     93      // should be in e3,e1,e2 order 
     94      var e1 = new Effect.Highlight('sandbox'); 
     95      var e2 = new Effect.Appear('sandbox',{queue:'end'}); 
     96      var e3 = new Effect.Fade('sandbox',{queue:'front'}); 
     97      assert(e2.startOn > e1.startOn); 
     98      assert(e3.startOn < e1.startOn); 
     99      assert(e3.startOn < e2.startOn); 
     100      assertEqual(3, Effect.Queue.effects.length); 
     101       
     102      Effect.Queue.each(function(e) { e.cancel() }); 
     103      assertEqual(0, Effect.Queue.effects.length); 
     104    }}, 
     105     
     106    testEffectMultiple: function() { with(this) { 
     107      $('sandbox').appendChild(Builder.node('div',{id:'test_1'})); 
     108      $('sandbox').appendChild(Builder.node('div',{id:'test_2'},[Builder.node('div',{id:'test_2a'})])); 
     109      $('sandbox').appendChild(Builder.node('div',{id:'test_3'})); 
     110       
     111      // only direct child elements 
     112      Effect.multiple('sandbox',Effect.Fade); 
     113      assertEqual(3, Effect.Queue.effects.length); 
     114       
     115      Effect.Queue.each(function(e) { e.cancel() }); 
     116      assertEqual(0, Effect.Queue.effects.length); 
     117       
     118      // call with array 
     119      Effect.multiple(['test_1','test_3'],Effect.Puff); 
     120      assertEqual(2, Effect.Queue.effects.length); 
     121    }}, 
     122     
     123    testEffectTagifyText: function() { with(this) { 
     124      $('sandbox').innerHTML = "Blah<strong>bleb</strong> Blub"; 
     125      assertEqual(3, $('sandbox').childNodes.length); 
     126      Effect.tagifyText('sandbox'); 
     127      assertEqual(10, $('sandbox').childNodes.length); 
     128       
     129      Effect.multiple('sandbox', Effect.Fade); 
     130      assertEqual(10, Effect.Queue.effects.length); 
    39131    }}, 
    40132 
     
    46138          Builder.node('div',{id:'test_element'}, 
    47139            [Builder.node('span','test')])); //some effects require a child element 
    48         var effect = new Effect[COMBINED_EFFECTS[j]]('test_element',{sync:true}); 
     140             
     141        // should work with new Effect.Blah syntax 
     142        var effect = new Effect[COMBINED_EFFECTS[j]]('test_element'); 
     143        assertEqual(0, effect.currentFrame); 
     144         
     145        // and without the 'new' 
     146        var effect = Effect[COMBINED_EFFECTS[j]]('test_element'); 
    49147        assertEqual(0, effect.currentFrame); 
    50148      } 
     149    }}, 
     150     
     151    testSynchronizedEffects: function() { with(this) { 
     152      var e1 = new Effect.Fade('sandbox',{sync:true}); 
     153      wait(250, function() { 
     154        // effect should still be at frame 0 
     155        assertEqual(0, e1.currentFrame); 
     156        assertEqual('idle', e1.state); 
     157        e1.render(0.01); 
     158         
     159        // no frame count for sync effects 
     160        assertEqual(0, e1.currentFrame); 
     161        assertEqual('running', e1.state); 
     162      }); 
    51163    }}, 
    52164     
     
    57169      }); 
    58170      assertNull(testeffect.position); 
     171      assertEqual('idle', testeffect.state); 
    59172      wait(1000, function() { 
    60173        assertEqual('0.5', $('sandbox').innerHTML); 
    61174        assertEqual(0.5, testeffect.position); 
     175        assertEqual('finished', testeffect.state); 
    62176      }); 
    63177    }}