TweenJS v1.0.0 API Documentation : tweenjs/plugins/RelativePlugin.js

API Documentation for: 1.0.0
Show:

File:RelativePlugin.js

  1. /*
  2. * RelativePlugin
  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. this.createjs = this.createjs||{};
  34.  
  35. (function() {
  36. "use strict";
  37.  
  38. /**
  39. * The RelativePlugin for TweenJS enables relative numeric values for tweens. Install using:
  40. *
  41. * RelativePlugin.install();
  42. *
  43. * Once installed, you can pass in relative numeric property values as strings beginning with "+" or "-". For example,
  44. * the following tween would tween the x position of `foo` from its initial value of `200` to `50` (200-150), then to
  45. * `125` (50+75).
  46. *
  47. * foo.x = 200;
  48. * Tween.get(foo).to({x:"-150"}, 500).to({x:"+75"}, 500);
  49. *
  50. * @class RelativePlugin
  51. * @constructor
  52. **/
  53. function RelativePlugin() {
  54. throw("RelativePlugin plugin cannot be instantiated.")
  55. }
  56. var s = RelativePlugin;
  57. /**
  58. * READ-ONLY. A unique identifying string for this plugin. Used by TweenJS to ensure duplicate plugins are not installed on a tween.
  59. * @property ID
  60. * @type {String}
  61. * @static
  62. * @readonly
  63. **/
  64. s.ID = "Relative";
  65.  
  66. /**
  67. * Installs this plugin for use with TweenJS. Call this once after TweenJS is loaded to enable this plugin.
  68. * @method install
  69. * @static
  70. **/
  71. s.install = function() {
  72. createjs.Tween._installPlugin(RelativePlugin);
  73. };
  74. /**
  75. * Called by TweenJS when a new property initializes on a tween.
  76. * See {{#crossLink "SamplePlugin/init"}}{{/crossLink}} for more info.
  77. * @method init
  78. * @param {Tween} tween
  79. * @param {String} prop
  80. * @param {any} value
  81. * @return {any}
  82. * @static
  83. **/
  84. s.init = function(tween, prop, value) {
  85. if (!tween.pluginData.Relative_disabled) { tween._addPlugin(s); }
  86. };
  87. /**
  88. * Called when a new step is added to a tween (ie. a new "to" action is added to a tween).
  89. * See {{#crossLink "SamplePlugin/step"}}{{/crossLink}} for more info.
  90. * @method step
  91. * @param {Tween} tween
  92. * @param {TweenStep} step
  93. * @param {Object} props
  94. * @static
  95. **/
  96. s.step = function(tween, step, props) {
  97. // in this method we check if any prop is a string value starting with "+" or "-", and adjust the value accordingly.
  98. for (var n in props) {
  99. var value = props[n];
  100. if (typeof value !== "string") { continue; }
  101. var prev = step.prev.props[n], char0 = value[0];
  102. if (!(char0 === "+" || char0 === "-") || isNaN(value = +value+prev)) { continue; }
  103. step.props[n] = value;
  104. }
  105. };
  106.  
  107. /**
  108. * Called before a property is updated by the tween.
  109. * See {{#crossLink "SamplePlugin/change"}}{{/crossLink}} for more info.
  110. * @method change
  111. * @param {Tween} tween
  112. * @param {TweenStep} step
  113. * @param {String} prop
  114. * @param {any} value
  115. * @param {Number} ratio
  116. * @param {Boolean} end
  117. * @return {any}
  118. * @static
  119. **/
  120. s.change = function(tween, step, prop, value, ratio, end) {
  121. // nothing
  122. };
  123.  
  124. createjs.RelativePlugin = s;
  125. }());
  126.