Changeset 506

Show
Ignore:
Timestamp:
01/15/06 08:02:34 (3 years ago)
Author:
therve@gmail.com
Message:

Add doc, correct bug on Pulsate.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mochikit/branches/scriptaculous/MochiKit/Effects.js

    r505 r506  
    614614        MochiKit.DOM.setStyle(this.element, 
    615615            MochiKit.Base.update(this.oldStyle, { 
    616             backgroundColor: this.options.endColor 
     616                backgroundColor: this.options.endColor 
    617617        })); 
    618618    } 
     
    670670 
    671671Effect.Fade = function (element, options) { 
     672    /*** 
     673 
     674    Fade a given element: change its opacity and hide it in the end. 
     675 
     676    @param options: 'to' and 'from' to change opacity. 
     677 
     678    ***/ 
    672679    var oldOpacity = MochiKit.DOM.getInlineOpacity(element); 
    673680    options = MochiKit.Base.update({ 
     
    675682        to: 0.0, 
    676683        afterFinishInternal: function (effect) { 
    677             if (effect.options.to != 0) { 
     684            if (!effect.options.to) { 
    678685                return; 
    679686            } 
     
    686693 
    687694Effect.Appear = function (element, options) { 
     695    /*** 
     696 
     697    Make an element appear. 
     698 
     699    @param options: 'to' and 'from' to change opacity. 
     700 
     701    ***/ 
    688702    options = MochiKit.Base.update({ 
    689         from: (MochiKit.DOM.getStyle(element, 'display') == 'none' ? 0.0 : MochiKit.DOM.getOpacity(element) || 0.0), 
     703        from: (MochiKit.DOM.getStyle(element, 'display') == 'none' ? 0.0 : 
     704               MochiKit.DOM.getOpacity(element) || 0.0), 
    690705        to: 1.0, 
    691706        beforeSetup: function (effect) { 
     
    698713 
    699714Effect.Puff = function (element, options) { 
     715    /*** 
     716 
     717    'Puff' an element: grow it to double size, fading it and make it hidden. 
     718 
     719    @param options: 'duration' in seconds for the effect, default to 1.0. 
     720 
     721    ***/ 
    700722    element = MochiKit.DOM.getElement(element); 
    701723    var oldStyle = { 
     
    706728        duration: 1.0, 
    707729        beforeSetupInternal: function (effect) { 
    708             MochiKit.DOM.setStyle(effect.effects[0].element, {position: 'absolute'}); 
     730            MochiKit.DOM.setStyle(effect.effects[0].element, 
     731                                  {position: 'absolute'}); 
    709732        }, 
    710733        afterFinishInternal: function (effect) { 
     
    714737    }, options || {}); 
    715738    return new Effect.Parallel( 
    716      [new Effect.Scale(element, 200, 
     739        [new Effect.Scale(element, 200, 
    717740            {sync: true, scaleFromCenter: true, 
    718741             scaleContent: true, restoreAfterFinish: true}), 
    719       new Effect.Opacity(element, {sync: true, to: 0.0 })], 
    720       options 
     742         new Effect.Opacity(element, {sync: true, to: 0.0 })], 
     743        options 
    721744    ); 
    722745}; 
    723746 
    724747Effect.BlindUp = function (element, options) { 
     748    /*** 
     749 
     750    Blind an element up: change its vertical size to 0. 
     751 
     752    ***/ 
    725753    element = MochiKit.DOM.getElement(element); 
    726754    MochiKit.DOM.makeClipping(element); 
     
    739767 
    740768Effect.BlindDown = function (element, options) { 
     769    /*** 
     770 
     771    Blind an element down: restore its vertical size. 
     772 
     773    ***/ 
    741774    element = MochiKit.DOM.getElement(element); 
    742775    var oldHeight = MochiKit.DOM.getStyle(element, 'height'); 
     
    763796 
    764797Effect.SwitchOff = function (element) { 
     798    /*** 
     799 
     800    Apply a switch-off-like effect. 
     801 
     802    ***/ 
    765803    element = MochiKit.DOM.getElement(element); 
    766804    var oldOpacity = MochiKit.DOM.getInlineOpacity(element); 
     
    793831 
    794832Effect.DropOut = function (element, options) { 
     833    /*** 
     834 
     835    Make an element fall and disappear. 
     836 
     837    ***/ 
    795838    element = MochiKit.DOM.getElement(element); 
    796839    var oldStyle = { 
     
    818861 
    819862Effect.Shake = function (element) { 
     863    /*** 
     864 
     865    Move an element from left to right several times. 
     866 
     867    ***/ 
    820868    element = MochiKit.DOM.getElement(element); 
    821869    var oldStyle = { 
     
    823871        left: MochiKit.DOM.getStyle(element, 'left') }; 
    824872        return new Effect.Move(element, 
    825             {x: 20, y: 0, duration: 0.05, afterFinishInternal: function (effect) { 
     873          {x: 20, y: 0, duration: 0.05, afterFinishInternal: function (effect) { 
    826874        new Effect.Move(effect.element, 
    827             {x: -40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 
     875          {x: -40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 
    828876        new Effect.Move(effect.element, 
    829             {x: 40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 
     877           {x: 40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 
    830878        new Effect.Move(effect.element, 
    831             {x: -40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 
     879          {x: -40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 
    832880        new Effect.Move(effect.element, 
    833             {x: 40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 
     881           {x: 40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 
    834882        new Effect.Move(effect.element, 
    835             {x: -20, y: 0, duration: 0.05, afterFinishInternal: function (effect) { 
     883         {x: -20, y: 0, duration: 0.05, afterFinishInternal: function (effect) { 
    836884                MochiKit.DOM.undoPositioned(effect.element); 
    837885                MochiKit.DOM.setStyle(effect.element, oldStyle); 
     
    840888 
    841889Effect.SlideDown = function (element, options) { 
     890    /*** 
     891 
     892    Slide an element down. 
     893    It needs to have the content of the element wrapped in a container 
     894    element with fixed height. 
     895 
     896    ***/ 
    842897    element = MochiKit.DOM.getElement(element); 
    843898    MochiKit.DOM.cleanWhitespace(element); 
    844     // SlideDown need to have the content of the element wrapped in 
    845     // a container element with fixed height! 
    846899    var oldInnerBottom = MochiKit.DOM.getStyle(element.firstChild, 'bottom'); 
    847900    var elementDimensions = MochiKit.DOM.elementDimensions(element); 
     
    871924            MochiKit.DOM.undoPositioned(effect.element.firstChild); 
    872925            MochiKit.DOM.undoPositioned(effect.element); 
    873             MochiKit.DOM.setStyle(effect.element.firstChild, {bottom: oldInnerBottom}); 
     926            MochiKit.DOM.setStyle(effect.element.firstChild, 
     927                                  {bottom: oldInnerBottom}); 
    874928        } 
    875929    }, options || {}); 
     
    879933 
    880934Effect.SlideUp = function (element, options) { 
     935    /*** 
     936 
     937    Slide an element up. 
     938    It needs to have the content of the element wrapped in a container 
     939    element with fixed height. 
     940 
     941    ***/ 
    881942    element = MochiKit.DOM.getElement(element); 
    882943    MochiKit.DOM.cleanWhitespace(element); 
     
    912973}; 
    913974 
    914 // Bug in opera makes the TD containing this element expand for a instance after finish 
    915 Effect.Squish = function (element) { 
    916     return new Effect.Scale(element, MochiKit.Base.isOpera() ? 1 : 0, 
    917         {restoreAfterFinish: true, 
    918          beforeSetup: function (effect) { 
     975// Bug in opera makes the TD containing this element expand for a instance 
     976// after finish 
     977Effect.Squish = function (element, options) { 
     978    /*** 
     979 
     980    Reduce an element and make it disappear. 
     981 
     982    ***/ 
     983    options = MochiKit.Base.update({ 
     984        restoreAfterFinish: true, 
     985        beforeSetup: function (effect) { 
    919986             MochiKit.DOM.makeClipping(effect.element); 
    920         }, 
    921         afterFinishInternal: function (effect) { 
     987        }, 
     988        afterFinishInternal: function (effect) { 
    922989              MochiKit.DOM.hideElement(effect.element); 
    923990              MochiKit.DOM.undoClipping(effect.element); 
    924          } 
    925     }); 
     991        } 
     992    }, options || {}); 
     993 
     994    return new Effect.Scale(element, MochiKit.Base.isOpera() ? 1 : 0, options); 
    926995}; 
    927996 
    928997Effect.Grow = function (element, options) { 
     998    /*** 
     999 
     1000    Grow an element to its original size. Make it zero-sized before 
     1001    if necessary. 
     1002 
     1003    ***/ 
    9291004    element = MochiKit.DOM.getElement(element); 
    9301005    options = MochiKit.Base.update({ 
     
    9971072            new Effect.Parallel( 
    9981073                [new Effect.Opacity(effect.element, { 
    999                     sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition 
     1074                    sync: true, to: 1.0, from: 0.0, 
     1075                    transition: options.opacityTransition 
    10001076                 }), 
    10011077                 new Effect.Move(effect.element, { 
    1002                      x: moveX, y: moveY, sync: true, transition: options.moveTransition 
     1078                     x: moveX, y: moveY, sync: true, 
     1079                     transition: options.moveTransition 
    10031080                 }), 
    10041081                 new Effect.Scale(effect.element, 100, { 
     
    10171094 
    10181095Effect.Shrink = function (element, options) { 
     1096    /*** 
     1097 
     1098    Shrink an element and make it disappear. 
     1099 
     1100    ***/ 
    10191101    element = MochiKit.DOM.getElement(element); 
    10201102    options = MochiKit.Base.update({ 
     
    10561138    } 
    10571139 
    1058     var optionsParallel = MochiKit.Base.update( 
    1059     { 
     1140    var optionsParallel = MochiKit.Base.update({ 
    10601141        beforeStartInternal: function (effect) { 
    10611142            MochiKit.DOM.makePositioned(effect.effects[0].element); 
     
    10871168 
    10881169Effect.Pulsate = function (element, options) { 
     1170    /*** 
     1171 
     1172    Pulse an element between appear/fade. 
     1173 
     1174    ***/ 
    10891175    element = MochiKit.DOM.getElement(element); 
    10901176    options = MochiKit.Base.update({ 
     
    10931179        afterFinishInternal: function (effect) { 
    10941180            MochiKit.DOM.setStyle(effect.element, {opacity: oldOpacity}); 
    1095         }, 
    1096         transition: reverser 
     1181        } 
    10971182    }, options || {}); 
    10981183    var oldOpacity = MochiKit.DOM.getInlineOpacity(element); 
    10991184    var transition = options.transition || Effect.Transitions.sinoidal; 
    1100     var reverser = function (pos) { 
     1185    var reverser = MochiKit.Base.bind(function (pos) { 
    11011186        return transition(1 - Effect.Transitions.pulse(pos)); 
    1102     }
     1187    }, transition)
    11031188    MochiKit.Base.bind(reverser, transition); 
    1104     return new Effect.Opacity(element, options); 
     1189    return new Effect.Opacity(element, MochiKit.Base.update({ 
     1190        transition: reverser}, options)); 
    11051191}; 
    11061192 
    11071193Effect.Fold = function (element, options) { 
     1194    /*** 
     1195 
     1196    Fold an element, first vertically, then horizontally. 
     1197 
     1198    ***/ 
    11081199    element = MochiKit.DOM.getElement(element); 
    11091200    var oldStyle = {