Ease.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. if (typeof window.RadControlsNamespace == "undefined")
  2. {
  3. window.RadControlsNamespace = {};
  4. }
  5. if (
  6. typeof(window.RadControlsNamespace.Ease) == "undefined" ||
  7. typeof(window.RadControlsNamespace.Ease.Version) == null ||
  8. window.RadControlsNamespace.Ease.Version < 1.3
  9. )
  10. {
  11. RadControlsNamespace.Ease = function (element, configObject, offsetX, offsetY, listener, createOverlay)
  12. {
  13. this.Element = element;
  14. if (createOverlay)
  15. {
  16. this.Overlay = new RadControlsNamespace.Overlay(element);
  17. }
  18. this.OffsetX = offsetX;
  19. this.OffsetY = offsetY;
  20. this.Invert = false;
  21. var parent = this.Element.parentNode;
  22. this.ExpandConfig = this.MergeConfig(configObject.ExpandAnimation);
  23. this.CollapseConfig = this.MergeConfig(configObject.CollapseAnimation);
  24. this.Ticker = new RadControlsNamespace.Ticker(this);
  25. this.Listener = listener;
  26. this.SlideParent = false;
  27. }
  28. RadControlsNamespace.Ease.Version = 1.3;// update in the header IF also
  29. RadControlsNamespace.Ease.Coef = 0;
  30. RadControlsNamespace.Ease.prototype =
  31. {
  32. SetSide : function(side)
  33. {
  34. this.InitialSide = side.charAt(0).toUpperCase() + side.substr(1, side.length - 1);
  35. this.Invert = false;
  36. if (side == 'right')
  37. {
  38. side = 'left';
  39. this.Invert = true;
  40. }
  41. if (side == 'bottom')
  42. {
  43. side = 'top';
  44. this.Invert = true;
  45. }
  46. this.Side = side;
  47. this.Horizontal = side == "left";
  48. },
  49. MergeConfig : function (config)
  50. {
  51. if (!config.Type)
  52. {
  53. config.Type = "OutQuint";
  54. }
  55. if (!config.Duration)
  56. {
  57. config.Duration = 200;
  58. }
  59. return config;
  60. },
  61. GetSide : function ()
  62. {
  63. return this.InitialSide;
  64. },
  65. ShowElements : function ()
  66. {
  67. if (!this.Element.parentNode) return;
  68. if (!this.Element.parentNode.style) return;
  69. this.Element.parentNode.style.display = "block";
  70. this.Element.style.display = "block";
  71. this.Element.parentNode.style.overflow = "hidden";
  72. },
  73. Dispose : function ()
  74. {
  75. this.Ticker.Stop();
  76. this.Element = null;
  77. if (this.Overlay)
  78. {
  79. this.Overlay.Dispose();
  80. }
  81. },
  82. ResetState : function (resetPosition)
  83. {
  84. this.ShowElements();
  85. if (resetPosition)
  86. {
  87. var initialPosition = (this.Horizontal ? this.Element.offsetWidth : this.Element.offsetHeight);
  88. if (!this.Invert)
  89. {
  90. initialPosition = -initialPosition;
  91. }
  92. this.SetPosition(initialPosition);
  93. }
  94. this.InitialPosition = this.GetPosition();
  95. },
  96. UpdateContainerSize : function ()
  97. {
  98. if (!this.Element.parentNode)
  99. {
  100. //r.a.d.callback
  101. return;
  102. }
  103. if (!this.Element.offsetWidth || !this.Element.offsetHeight )
  104. {
  105. return;
  106. }
  107. if (this.Invert)
  108. {
  109. if (this.Side == "left")
  110. {
  111. this.Element.parentNode.style.height = this.Element.offsetHeight + "px";
  112. }
  113. else if (this.Side == "top")
  114. {
  115. this.Element.parentNode.style.width = this.Element.offsetWidth + "px";
  116. }
  117. return;
  118. }
  119. var top = 0;
  120. var left = 0;
  121. if (this.Element.style.top != "")
  122. {
  123. top = Math.max(parseInt(this.Element.style.top), 0);
  124. }
  125. if (this.Element.style.left != "")
  126. {
  127. left = Math.max(parseInt(this.Element.style.left), 0);
  128. }
  129. if (this.SlideParent) // Panelbar
  130. {
  131. top = parseInt(this.Element.style.top);
  132. if (isNaN(top)) top = 0;
  133. }
  134. if ( typeof(RadMenuItem) != "undefined" && this.Listener instanceof RadMenuItem)
  135. {
  136. if (this.Element.parentNode.style.height != this.Element.offsetHeight + top + "px")
  137. {
  138. this.Element.parentNode.style.height = Math.max(this.Element.offsetHeight + top, 0) + "px";
  139. }
  140. if (this.Element.parentNode.style.width != (this.Element.offsetWidth + left)+ "px")
  141. {
  142. this.Element.parentNode.style.width = Math.max(this.Element.offsetWidth + left, 0)+ "px";
  143. }
  144. }
  145. else
  146. {
  147. if (this.Element.parentNode.offsetHeight != this.Element.offsetHeight + top)
  148. {
  149. this.Element.parentNode.style.height = Math.max(this.Element.offsetHeight + top, 0) + "px";
  150. }
  151. if (this.Element.parentNode.offsetWidth != (this.Element.offsetWidth + left))
  152. {
  153. this.Element.parentNode.style.width = Math.max(this.Element.offsetWidth + left, 0)+ "px";
  154. }
  155. }
  156. },
  157. GetSize : function ()
  158. {
  159. return this.Horizontal ? this.Element.offsetWidth : this.Element.offsetHeight;
  160. },
  161. GetPosition : function ()
  162. {
  163. if (!this.Element.style[this.Side])
  164. {
  165. return 0;
  166. }
  167. return parseInt(this.Element.style[this.Side]);
  168. },
  169. SetPosition : function(value)
  170. {
  171. this.Element.style[this.Side] = value + "px";
  172. },
  173. Out : function ()
  174. {
  175. this.ResetState();
  176. this.Direction = -1;
  177. if (this.Invert)
  178. {
  179. this.Delta = this.GetSize() - this.GetPosition();
  180. }
  181. else
  182. {
  183. this.Delta = this.GetPosition() - this.GetSize();
  184. }
  185. this.Start(this.CollapseConfig);
  186. },
  187. In : function ()
  188. {
  189. this.ResetState(true);
  190. this.Direction = 1;
  191. this.Delta = - this.GetPosition();
  192. this.Start(this.ExpandConfig);
  193. },
  194. Start : function (configuration)
  195. {
  196. if (configuration.Type == "None")
  197. {
  198. this.UpdateContainerSize();
  199. this.Ticker.Stop();
  200. this.ChangePosition(this.InitialPosition + this.Delta);
  201. if (this.Overlay)
  202. {
  203. this.Overlay.Update();
  204. }
  205. this.UpdateContainerSize();
  206. this.OnTickEnd();
  207. return;
  208. }
  209. this.Tween = configuration.Type;
  210. this.Ticker.Configure(configuration);
  211. this.Ticker.Start();
  212. this.UpdateContainerSize();
  213. },
  214. ChangePosition : function (newValue)
  215. {
  216. if (isNaN(newValue)) return;
  217. var dimensionValue, dimensionName, dimensionOffset;
  218. if (this.Invert)
  219. {
  220. if (this.Horizontal)
  221. {
  222. dimensionValue = this.Element.offsetWidth;
  223. dimensionName = "width";
  224. dimensionOffset = this.OffsetX;
  225. }
  226. else
  227. {
  228. dimensionValue = this.Element.offsetHeight;
  229. dimensionName = "height";
  230. dimensionOffset = this.OffsetY;
  231. }
  232. this.SetPosition(0);
  233. var updatedValue = Math.max(1, dimensionValue - newValue) + "px";
  234. this.Element.parentNode.style[dimensionName] = updatedValue;
  235. this.Element.parentNode.style[this.Side] = ((dimensionValue - newValue + dimensionOffset) * -1) + "px";
  236. }
  237. else
  238. {
  239. this.Element.style[this.Side] = newValue + "px";
  240. }
  241. if (this.Listener && this.Listener.OnEase)
  242. this.Listener.OnEase(newValue);
  243. },
  244. OnTick : function (time)
  245. {
  246. var newValue = Math.round(Penner[this.Tween](time, this.InitialPosition, this.Delta, this.Ticker.Duration));
  247. if (newValue == this.InitialPosition + this.Delta)
  248. {
  249. this.Ticker.Stop();
  250. return;
  251. }
  252. this.ChangePosition(newValue);
  253. this.UpdateContainerSize();
  254. if (this.Overlay)
  255. {
  256. this.Overlay.Update();
  257. }
  258. },
  259. OnTickEnd : function ()
  260. {
  261. try
  262. {
  263. if (this.Direction == 0)
  264. {
  265. return;
  266. }
  267. this.ChangePosition(this.InitialPosition + this.Delta);
  268. if (this.Overlay)
  269. {
  270. this.Overlay.Update();
  271. }
  272. if (this.Direction > 0)
  273. {
  274. this.Element.parentNode.style.overflow = "visible";
  275. if (this.Listener && this.Listener.OnExpandComplete)
  276. {
  277. this.Listener.OnExpandComplete();
  278. }
  279. }
  280. else
  281. {
  282. this.Element.parentNode.style.display = "none";
  283. if (this.Listener)
  284. {
  285. this.Listener.OnCollapseComplete();
  286. }
  287. }
  288. this.Direction = 0;
  289. }
  290. catch(e)
  291. {
  292. //Atlas updates
  293. }
  294. }
  295. }
  296. }
  297. //BEGIN_ATLAS_NOTIFY
  298. if (typeof(Sys) != "undefined")
  299. {
  300. if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
  301. {
  302. Sys.Application.notifyScriptLoaded();
  303. }
  304. }
  305. //END_ATLAS_NOTIFY