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

Changeset 4796

Show
Ignore:
Timestamp:
08/20/06 18:05:58 (2 years ago)
Author:
madrobby
Message:

script.aculo.us: Added a custom exception to all base effects when used on non-existing DOM elements (plus added the assertRaise method to unit tests)

Files:

Legend:

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

    r4785 r4796  
    11*SVN* 
     2 
     3* Added a custom exception to all base effects when used on non-existing DOM elements, added a assertRaise method to unit tests 
    24 
    35* Fix autoscrolling when dragging an element unto a scrollable container, fixes #5017 [thx tomg] 
  • spinoffs/scriptaculous/src/effects.js

    r4711 r4796  
    105105 
    106106var Effect = { 
     107  _elementDoesNotExistError: { 
     108    name: 'ElementDoesNotExistError', 
     109    message: 'The specified DOM element does not exist, but is required for this effect to operate' 
     110  }, 
    107111  tagifyText: function(element) { 
    108112    if(typeof Builder == 'undefined') 
     
    355359  initialize: function(element) { 
    356360    this.element = $(element); 
     361    if(!this.element) throw(Effect._elementDoesNotExistError); 
    357362    // make this work on IE on elements without 'layout' 
    358363    if(/MSIE/.test(navigator.userAgent) && (!this.element.currentStyle.hasLayout)) 
     
    373378  initialize: function(element) { 
    374379    this.element = $(element); 
     380    if(!this.element) throw(Effect._elementDoesNotExistError); 
    375381    var options = Object.extend({ 
    376382      x:    0, 
     
    411417Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), { 
    412418  initialize: function(element, percent) { 
    413     this.element = $(element) 
     419    this.element = $(element); 
     420    if(!this.element) throw(Effect._elementDoesNotExistError); 
    414421    var options = Object.extend({ 
    415422      scaleX: true, 
     
    486493  initialize: function(element) { 
    487494    this.element = $(element); 
     495    if(!this.element) throw(Effect._elementDoesNotExistError); 
    488496    var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {}); 
    489497    this.start(options); 
  • spinoffs/scriptaculous/src/unittest.js

    r4621 r4796  
    333333    catch(e) { this.error(e); }  
    334334  }, 
     335  assertRaise: function(exceptionName, method) { 
     336    var message = arguments[2] || 'assertRaise'; 
     337    try {  
     338      method(); 
     339      this.fail(message + ": exception expected but none was raised"); } 
     340    catch(e) { 
     341      (e.name==exceptionName) ? this.pass() : this.error(e);  
     342    } 
     343  }, 
    335344  _isVisible: function(element) { 
    336345    element = $(element); 
  • spinoffs/scriptaculous/test/unit/effects_test.html

    r4229 r4796  
    4848    testBackwardsCompat: function() { with(this) { 
    4949      assertInstanceOf(Effect.Opacity, new Effect2.Fade('sandbox')); 
     50    }}, 
     51     
     52    testExceptionOnNonExistingElement: function() { with(this) { 
     53      assertRaise('ElementDoesNotExistError',  
     54        function(){new Effect.Opacity('nothing-to-see-here')}); 
     55      assertRaise('ElementDoesNotExistError',  
     56        function(){new Effect.Move('nothing-to-see-here')}); 
     57      assertRaise('ElementDoesNotExistError',  
     58        function(){new Effect.Scale('nothing-to-see-here')}); 
     59      assertRaise('ElementDoesNotExistError',  
     60        function(){new Effect.Highlight('nothing-to-see-here')}); 
    5061    }}, 
    5162