|
| 1 | +/* |
| 2 | +* DotPlugin |
| 3 | +* Visit http://createjs.com/ for documentation, updates and examples. |
| 4 | +* |
| 5 | +* Copyright (c) 2010 gskinner.com, inc. |
| 6 | +* |
| 7 | +* Permission is hereby granted, free of charge, to any person |
| 8 | +* obtaining a copy of this software and associated documentation |
| 9 | +* files (the "Software"), to deal in the Software without |
| 10 | +* restriction, including without limitation the rights to use, |
| 11 | +* copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | +* copies of the Software, and to permit persons to whom the |
| 13 | +* Software is furnished to do so, subject to the following |
| 14 | +* conditions: |
| 15 | +* |
| 16 | +* The above copyright notice and this permission notice shall be |
| 17 | +* included in all copies or substantial portions of the Software. |
| 18 | +* |
| 19 | +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 21 | +* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 23 | +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 24 | +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 25 | +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 26 | +* OTHER DEALINGS IN THE SOFTWARE. |
| 27 | +*/ |
| 28 | + |
| 29 | +/** |
| 30 | + * @module TweenJS |
| 31 | + */ |
| 32 | + |
| 33 | +// namespace: |
| 34 | +this.createjs = this.createjs||{}; |
| 35 | + |
| 36 | +(function() { |
| 37 | + "use strict"; |
| 38 | + |
| 39 | + /** |
| 40 | + * The RelativePlugin for TweenJS enables tweening nested properties using dot syntax. Install using: |
| 41 | + * |
| 42 | + * RotationPlugin.install(); |
| 43 | + * |
| 44 | + * To use the plugin, begin property names with `.`, such as: |
| 45 | + * |
| 46 | + * createjs.Tween.get(targ).to({".position.x":20}) |
| 47 | + * |
| 48 | + * You can access array indexes with the same dot syntax: |
| 49 | + * |
| 50 | + * // this would tween: foo.points[1].y |
| 51 | + * createjs.Tween.get(foo).to({".points.1.y":30}) |
| 52 | + * |
| 53 | + * @class DotPlugin |
| 54 | + * @constructor |
| 55 | + **/ |
| 56 | + function DotPlugin() { |
| 57 | + throw("DotPlugin cannot be instantiated."); |
| 58 | + }; |
| 59 | + var s = DotPlugin; |
| 60 | + |
| 61 | +// static interface: |
| 62 | + /** |
| 63 | + * @property priority |
| 64 | + * @protected |
| 65 | + * @static |
| 66 | + **/ |
| 67 | + s.priority = 100; // high priority, should read first and write last |
| 68 | + |
| 69 | + /** |
| 70 | + * READ-ONLY. A unique identifying string for this plugin. Used by TweenJS to ensure duplicate plugins are not installed on a tween. |
| 71 | + * @property ID |
| 72 | + * @type {String} |
| 73 | + * @static |
| 74 | + * @readonly |
| 75 | + **/ |
| 76 | + s.ID = "Dot"; |
| 77 | + |
| 78 | + /** |
| 79 | + * Installs this plugin for use with TweenJS. Call this once after TweenJS is loaded to enable this plugin. |
| 80 | + * @method install |
| 81 | + * @static |
| 82 | + **/ |
| 83 | + s.install = function() { |
| 84 | + createjs.Tween._installPlugin(DotPlugin); |
| 85 | + }; |
| 86 | + |
| 87 | + /** |
| 88 | + * Called by TweenJS when a new property initializes on a tween. |
| 89 | + * See {{#crossLink "SamplePlugin/init"}}{{/crossLink}} for more info. |
| 90 | + * @method init |
| 91 | + * @param {Tween} tween |
| 92 | + * @param {String} prop |
| 93 | + * @param {any} value |
| 94 | + * @return {any} |
| 95 | + * @static |
| 96 | + **/ |
| 97 | + s.init = function(tween, prop, value) { |
| 98 | + var data = tween.pluginData; |
| 99 | + if (data.Dot_disabled) { return; } |
| 100 | + |
| 101 | + // only operate on props starting with ".": |
| 102 | + if (prop[0] !== ".") { return; } |
| 103 | + tween._addPlugin(DotPlugin); |
| 104 | + |
| 105 | + var t = tween.target, arr=prop.split("."); |
| 106 | + for (var i=1, l=arr.length; i<l-1; i++) { |
| 107 | + if (!(t = t[arr[i]])) { return createjs.Tween.IGNORE; } |
| 108 | + } |
| 109 | + var n = arr[i], targetVal = t[n]; |
| 110 | + var defaultVal = (value === undefined) ? targetVal : value; |
| 111 | + |
| 112 | + data.Dot = data.Dot || {}; |
| 113 | + data.Dot[prop] = {t:t, n:n}; |
| 114 | + |
| 115 | + return defaultVal; |
| 116 | + }; |
| 117 | + |
| 118 | + /** |
| 119 | + * Called when a new step is added to a tween (ie. a new "to" action is added to a tween). |
| 120 | + * See {{#crossLink "SamplePlugin/step"}}{{/crossLink}} for more info. |
| 121 | + * @method step |
| 122 | + * @param {Tween} tween |
| 123 | + * @param {TweenStep} step |
| 124 | + * @param {Object} props |
| 125 | + * @static |
| 126 | + **/ |
| 127 | + s.step = function(tween, step, props) {}; |
| 128 | + |
| 129 | + /** |
| 130 | + * Called before a property is updated by the tween. |
| 131 | + * See {{#crossLink "SamplePlugin/change"}}{{/crossLink}} for more info. |
| 132 | + * @method change |
| 133 | + * @param {Tween} tween |
| 134 | + * @param {TweenStep} step |
| 135 | + * @param {String} prop |
| 136 | + * @param {any} value |
| 137 | + * @param {Number} ratio |
| 138 | + * @param {Boolean} end |
| 139 | + * @return {any} |
| 140 | + * @static |
| 141 | + **/ |
| 142 | + s.change = function(tween, step, prop, value, ratio, end) { |
| 143 | + var data = tween.pluginData.Dot, o; |
| 144 | + if (!data || !(o=data[prop])) { return; } |
| 145 | + |
| 146 | + o.t[o.n] = value; |
| 147 | + |
| 148 | + return createjs.Tween.IGNORE; |
| 149 | + }; |
| 150 | + |
| 151 | + |
| 152 | + createjs.DotPlugin = s; |
| 153 | +}()); |
0 commit comments