PageSourceSearch

https://www.casadadanca.pt/wp-content/themes/CD-theme/assets/js/Animated-plugin/animation.gsap.js

js casadadanca.pt collected 2026-10-06 20:27:11 UTC 19,311 bytes, 306 lines download raw bytes

1/*!
2 * @file ScrollMagic GSAP Animation Plugin.
3 *
4 * requires: GSAP ~1.14
5 * Powered by the Greensock Animation Platform (GSAP): http://www.greensock.com/js
6 * Greensock License info at http://www.greensock.com/licensing/
7 */
8/**
9 * This plugin is meant to be used in conjunction with the Greensock Animation Plattform.  
10 * It offers an easy API to trigger Tweens or synchronize them to the scrollbar movement.
11 *
12 * Both the `lite` and the `max` versions of the GSAP library are supported.  
13 * The most basic requirement is `TweenLite`.
14 * 
15 * To have access to this extension, please include `plugins/animation.gsap.js`.
16 * @requires {@link http://greensock.com/gsap|GSAP ~1.14.x}
17 * @mixin animation.GSAP
18 */
19(function (root, factory) {
20    if (typeof define === 'function' && define.amd) {
21        // AMD. Register as an anonymous module.
22        define(['ScrollMagic', 'TweenMax', 'TimelineMax'], factory);
23    } else if (typeof exports === 'object') {
24        // CommonJS
25        // Loads whole gsap package onto global scope.
26        require('gsap');
27        factory(require('scrollmagic'), TweenMax, TimelineMax);
28    } else {
29        // Browser globals
30        factory(root.ScrollMagic || (root.jQuery && root.jQuery.ScrollMagic), root.TweenMax || root.TweenLite, root.TimelineMax || root.TimelineLite);
31    }
32}(this, function(ScrollMagic, Tween, Timeline) {
33    "use strict";
34    var NAMESPACE = "animation.gsap";
35
36    // (BUILD) - REMOVE IN MINIFY - START
37    var
38        console = window.console || {},
39        err = Function.prototype.bind.call(console.error || console.log || function() {}, console);
40    if (!ScrollMagic) {
41        err("(" + NAMESPACE + ") -> ERROR: The ScrollMagic main module could not be found. Please make sure it's loaded before this plugin or use an asynchronous loader like requirejs.");
42    }
43    if (!Tween) {
44        err("(" + NAMESPACE + ") -> ERROR: TweenLite or TweenMax could not be found. Please make sure GSAP is loaded before ScrollMagic or use an asynchronous loader like requirejs.");
45    }
46    // (BUILD) - REMOVE IN MINIFY - END
47    
48    /*
49     * ----------------------------------------------------------------
50     * Extensions for Scene
51     * ----------------------------------------------------------------
52     */
53    /**
54     * Every instance of ScrollMagic.Scene now accepts an additional option.  
55     * See {@link ScrollMagic.Scene} for a complete list of the standard options.
56     * @memberof! animation.GSAP#
57     * @method new ScrollMagic.Scene(options)
58     * @example
59     * var scene = new ScrollMagic.Scene({tweenChanges: true});
60     *
61     * @param {object} [options] - Options for the Scene. The options can be updated at any time.
62     * @param {boolean} [options.tweenChanges=false] - Tweens Animation to the progress target instead of setting it.  
63                                                      Does not affect animations where duration is `0`.
64     */
65    /**
66     * **Get** or **Set** the tweenChanges option value.  
67     * This only affects scenes with a duration. If `tweenChanges` is `true`, the progress update when scrolling will not be immediate, but instead the animation will smoothly animate to the target state.  
68     * For a better understanding, try enabling and disabling this option in the [Scene Manipulation Example](../examples/basic/scene_manipulation.html).
69     * @memberof! animation.GSAP#
70     * @method Scene.tweenChanges
71     * 
72     * @example
73     * // get the current tweenChanges option
74     * var tweenChanges = scene.tweenChanges();
75     *
76     * // set new tweenChanges option
77     * scene.tweenChanges(true);
78     *
79     * @fires {@link Scene.change}, when used as setter
80     * @param {boolean} [newTweenChanges] - The new tweenChanges setting of the scene.
81     * @returns {boolean} `get` -  Current tweenChanges option value.
82     * @returns {Scene} `set` -  Parent object for chaining.
83     */
84    // add option (TODO: DOC (private for dev))
85    ScrollMagic.Scene.addOption(
86        "tweenChanges", // name
87        false, // default
88        function (val) { // validation callback
89            return !!val;
90        }
91    );
92    // extend scene
93    ScrollMagic.Scene.extend(function () {
94        var Scene = this,
95        _tween;
96
97        // (BUILD) - REMOVE IN MINIFY - START
98        var log = function () {
99            if (Scene._log) { // not available, when main source minified
100                Array.prototype.splice.call(arguments, 1, 0, "(" + NAMESPACE + ")", "->");
101                Scene._log.apply(this, arguments);
102            }
103        };
104        // (BUILD) - REMOVE IN MINIFY - END
105
106        // set listeners
107        Scene.on("progress.plugin_gsap", function () {
108            updateTweenProgress();
109        });
110        Scene.on("destroy.plugin_gsap", function (e) {
111            Scene.removeTween(e.reset);
112        });
113
114        /**
115         * Update the tween progress to current position.
116         * @private
117         */
118        var updateTweenProgress = function () {
119            if (_tween) {
120                var
121                    progress = Scene.progress(),
122                    state = Scene.state();
123                if (_tween.repeat && _tween.repeat() === -1) {
124                    // infinite loop, so not in relation to progress
125                    if (state === 'DURING' && _tween.paused()) {
126                        _tween.play();
127                    } else if (state !== 'DURING' && !_tween.paused()) {
128                        _tween.pause();
129                    }
130                } else if (progress != _tween.progress()) { // do we even need to update the progress?
131                    // no infinite loop - so should we just play or go to a specific point in time?
132                    if (Scene.duration() === 0) {
133                        // play the animation
134                        if (progress > 0) { // play from 0 to 1
135                            _tween.play();
136                        } else { // play from 1 to 0
137                            _tween.reverse();
138                        }
139                    } else {
140                        // go to a specific point in time
141                        if (Scene.tweenChanges() && _tween.tweenTo) {
142                            // go smooth
143                            _tween.tweenTo(progress * _tween.duration());
144                        } else {
145                            // just hard set it
146                            _tween.progress(progress).pause();
147                        }
148                    }
149                }
150            }
151        };
152
153        /**
154         * Add a tween to the scene.  
155         * If you want to add multiple tweens, add them into a GSAP Timeline object and supply it instead (see example below).  
156         * 
157         * If the scene has a duration, the tween's duration will be projected to the scroll distance of the scene, meaning its progress will be synced to scrollbar movement.  
158         * For a scene with a duration of `0`, the tween will be triggered when scrolling forward past the scene's trigger position and reversed, when scrolling back.  
159         * To gain better understanding, check out the [Simple Tweening example](../examples/basic/simple_tweening.html).
160         *
161         * Instead of supplying a tween this method can also be used as a shorthand for `TweenMax.to()` (see example below).
162         * @memberof! animation.GSAP#
163         *
164         * @example
165         * // add a single tween directly
166         * scene.setTween(TweenMax.to("obj"), 1, {x: 100});
167         *
168         * // add a single tween via variable
169         * var tween = TweenMax.to("obj"), 1, {x: 100};
170         * scene.setTween(tween);
171         *
172         * // add multiple tweens, wrapped in a timeline.
173         * var timeline = new TimelineMax();
174         * var tween1 = TweenMax.from("obj1", 1, {x: 100});
175         * var tween2 = TweenMax.to("obj2", 1, {y: 100});
176         * timeline
177         *      .add(tween1)
178         *      .add(tween2);
179         * scene.addTween(timeline);
180         *
181         * // short hand to add a TweenMax.to() tween
182         * scene.setTween("obj3", 0.5, {y: 100});
183         *
184         * // short hand to add a TweenMax.to() tween for 1 second
185         * // this is useful, when the scene has a duration and the tween duration isn't important anyway
186         * scene.setTween("obj3", {y: 100});
187         *
188         * @param {(object|string)} TweenObject - A TweenMax, TweenLite, TimelineMax or TimelineLite object that should be animated in the scene. Can also be a Dom Element or Selector, when using direct tween definition (see examples).
189         * @param {(number|object)} duration - A duration for the tween, or tween parameters. If an object containing parameters are supplied, a default
189 duration of 1 will be used.
190         * @param {object} params - The parameters for the tween
191         * @returns {Scene} Parent object for chaining.
192         */
193        Scene.setTween = function (TweenObject, duration, params) {
194            var newTween;
195            if (arguments.length > 1) {
196                if ( arguments.length < 3) {
197                    params = duration;
198                    duration = 1;
199                }
200                TweenObject = Tween.to(TweenObject, duration, params);
201            }
202            try {
203                // wrap Tween into a Timeline Object if available to include delay and repeats in the duration and standardize methods.
204                if (Timeline) {
205                    newTween = new Timeline({smoothChildTiming: true})
206                        .add(TweenObject);
207                } else {
208                    newTween = TweenObject;
209                }
210                newTween.pause();
211            } catch (e) {
212                log(1, "ERROR calling method 'setTween()': Supplied argument is not a valid TweenObject");
213                return Scene;
214            }
215            if (_tween) { // kill old tween?
216                Scene.removeTween();
217            }
218            _tween = newTween;
219
220            // some properties need to be transferred it to the wrapper, otherwise they would get lost.
221            if (TweenObject.repeat && TweenObject.repeat() === -1) {// TweenMax or TimelineMax Object?
222                _tween.repeat(-1);
223                _tween.yoyo(TweenObject.yoyo());
224            }
225            // (BUILD) - REMOVE IN MINIFY - START
226            // Some tween validations and debugging helpers
227
228            if (Scene.tweenChanges() && !_tween.tweenTo) {
229                log(2, "WARNING: tweenChanges will only work if the TimelineMax object is available for ScrollMagic.");
230            }
231
232            // check if there are position tweens defined for the trigger and warn about it :)
233            if (_tween && Scene.controller()  && Scene.triggerElement() && Scene.loglevel() >= 2) {// controller is needed to know scroll direction.
234                var
235                    triggerTweens = Tween.getTweensOf(Scene.triggerElement()),
236                    vertical = Scene.controller().info("vertical");
237                triggerTweens.forEach(function (value, index) {
238                    var
239                        tweenvars = value.vars.css || value.vars,
240                        condition = vertical ? (tweenvars.top !== undefined || tweenvars.bottom !== undefined) : (tweenvars.left !== undefined || tweenvars.right !== undefined);
241                    if (condition) {
242                        log(2, "WARNING: Tweening the position of the trigger element affects the scene timing and should be avoided!");
243                        return false;
244                    }
245                });
246            }
247
248            // warn about tween overwrites, when an element is tweened multiple times
249            if (parseFloat(TweenLite.version) >= 1.14) { // onOverwrite only present since GSAP v1.14.0
250                var
251                    list = _tween.getChildren ? _tween.getChildren(true, true, false) : [_tween], // get all nested tween objects
252                    newCallback = function () {
253                        log(2, "WARNING: tween was overwritten by another. To learn how to avoid this issue see here: https://github.com/janpaepke/ScrollMagic/wiki/WARNING:-tween-was-overwritten-by-another");
254                    };
255                for (var i=0, thisTween, oldCallback; i<list.length; i++) {
256                    /*jshint loopfunc: true */
257                    thisTween = list[i];
258                    if (oldCallback !== newCallback) { // if tweens is added more than once
259                        oldCallback = thisTween.vars.onOverwrite;
260                        thisTween.vars.onOverwrite = function () {
261                            if (oldCallback) {
262                                oldCallback.apply(this, arguments);
263                            }
264                            newCallback.apply(this, arguments);
265                        };
266                    }
267                }
268            }
269            // (BUILD) - REMOVE IN MINIFY - END
270            log(3, "added tween");
271
272            updateTweenProgress();
273            return Scene;
274        };
275
276        /**
277         * Remove the tween from the scene.  
278         * This will terminate the control of the Scene over the tween.
279         *
280         * Using the reset option you can decide if the tween should remain in the current state or be rewound to set the target elements back to the state they were in before the tween was added to the scene.
281         * @memberof! animation.GSAP#
282         *
283         * @example
284         * // remove the tween from the scene without resetting it
285         * scene.removeTween();
286         *
287         * // remove the tween from the scene and reset it to initial position
288         * scene.removeTween(true);
289         *
290         * @param {boolean} [reset=false] - If `true` the tween will be reset to its initial values.
291         * @returns {Scene} Parent object for chaining.
292         */
293        Scene.removeTween = function (reset) {
294            if (_tween) {
295                if (reset) {
296                    _tween.progress(0).pause();
297                }
298                _tween.kill();
299                _tween = undefined;
300                log(3, "removed tween (reset: " + (reset ? "true" : "false") + ")");
301            }
302            return Scene;
303        };
304
305    });
306}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.