jqplot.effects.core.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * jQuery UI Effects 1.9pre
  3. *
  4. * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT or GPL Version 2 licenses.
  6. * http://jquery.org/license
  7. *
  8. * http://docs.jquery.com/UI/Effects/
  9. */
  10. //////
  11. // Much reduced version of jquery ui effects core used
  12. // for series animation in jqplot.
  13. //////
  14. (function($) {
  15. var backCompat = $.uiBackCompat !== false;
  16. $.jqplot.effects = {
  17. effect: {}
  18. };
  19. // prefix used for storing data on .data()
  20. var dataSpace = "jqplot.storage.";
  21. /******************************************************************************/
  22. /*********************************** EFFECTS **********************************/
  23. /******************************************************************************/
  24. $.extend( $.jqplot.effects, {
  25. version: "1.9pre",
  26. // Saves a set of properties in a data storage
  27. save: function( element, set ) {
  28. for( var i=0; i < set.length; i++ ) {
  29. if ( set[ i ] !== null ) {
  30. element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
  31. }
  32. }
  33. },
  34. // Restores a set of previously saved properties from a data storage
  35. restore: function( element, set ) {
  36. for( var i=0; i < set.length; i++ ) {
  37. if ( set[ i ] !== null ) {
  38. element.css( set[ i ], element.data( dataSpace + set[ i ] ) );
  39. }
  40. }
  41. },
  42. setMode: function( el, mode ) {
  43. if (mode === "toggle") {
  44. mode = el.is( ":hidden" ) ? "show" : "hide";
  45. }
  46. return mode;
  47. },
  48. // Wraps the element around a wrapper that copies position properties
  49. createWrapper: function( element ) {
  50. // if the element is already wrapped, return it
  51. if ( element.parent().is( ".ui-effects-wrapper" )) {
  52. return element.parent();
  53. }
  54. // wrap the element
  55. var props = {
  56. width: element.outerWidth(true),
  57. height: element.outerHeight(true),
  58. "float": element.css( "float" )
  59. },
  60. wrapper = $( "<div></div>" )
  61. .addClass( "ui-effects-wrapper" )
  62. .css({
  63. fontSize: "100%",
  64. background: "transparent",
  65. border: "none",
  66. margin: 0,
  67. padding: 0
  68. }),
  69. // Store the size in case width/height are defined in % - Fixes #5245
  70. size = {
  71. width: element.width(),
  72. height: element.height()
  73. },
  74. active = document.activeElement;
  75. element.wrap( wrapper );
  76. // Fixes #7595 - Elements lose focus when wrapped.
  77. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  78. $( active ).focus();
  79. }
  80. wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually loose the reference to the wrapped element
  81. // transfer positioning properties to the wrapper
  82. if ( element.css( "position" ) === "static" ) {
  83. wrapper.css({ position: "relative" });
  84. element.css({ position: "relative" });
  85. } else {
  86. $.extend( props, {
  87. position: element.css( "position" ),
  88. zIndex: element.css( "z-index" )
  89. });
  90. $.each([ "top", "left", "bottom", "right" ], function(i, pos) {
  91. props[ pos ] = element.css( pos );
  92. if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
  93. props[ pos ] = "auto";
  94. }
  95. });
  96. element.css({
  97. position: "relative",
  98. top: 0,
  99. left: 0,
  100. right: "auto",
  101. bottom: "auto"
  102. });
  103. }
  104. element.css(size);
  105. return wrapper.css( props ).show();
  106. },
  107. removeWrapper: function( element ) {
  108. var active = document.activeElement;
  109. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  110. element.parent().replaceWith( element );
  111. // Fixes #7595 - Elements lose focus when wrapped.
  112. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  113. $( active ).focus();
  114. }
  115. }
  116. return element;
  117. }
  118. });
  119. // return an effect options object for the given parameters:
  120. function _normalizeArguments( effect, options, speed, callback ) {
  121. // short path for passing an effect options object:
  122. if ( $.isPlainObject( effect ) ) {
  123. return effect;
  124. }
  125. // convert to an object
  126. effect = { effect: effect };
  127. // catch (effect)
  128. if ( options === undefined ) {
  129. options = {};
  130. }
  131. // catch (effect, callback)
  132. if ( $.isFunction( options ) ) {
  133. callback = options;
  134. speed = null;
  135. options = {};
  136. }
  137. // catch (effect, speed, ?)
  138. if ( $.type( options ) === "number" || $.fx.speeds[ options ]) {
  139. callback = speed;
  140. speed = options;
  141. options = {};
  142. }
  143. // catch (effect, options, callback)
  144. if ( $.isFunction( speed ) ) {
  145. callback = speed;
  146. speed = null;
  147. }
  148. // add options to effect
  149. if ( options ) {
  150. $.extend( effect, options );
  151. }
  152. speed = speed || options.duration;
  153. effect.duration = $.fx.off ? 0 : typeof speed === "number"
  154. ? speed : speed in $.fx.speeds ? $.fx.speeds[ speed ] : $.fx.speeds._default;
  155. effect.complete = callback || options.complete;
  156. return effect;
  157. }
  158. function standardSpeed( speed ) {
  159. // valid standard speeds
  160. if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) {
  161. return true;
  162. }
  163. // invalid strings - treat as "normal" speed
  164. if ( typeof speed === "string" && !$.jqplot.effects.effect[ speed ] ) {
  165. // TODO: remove in 2.0 (#7115)
  166. if ( backCompat && $.jqplot.effects[ speed ] ) {
  167. return false;
  168. }
  169. return true;
  170. }
  171. return false;
  172. }
  173. $.fn.extend({
  174. jqplotEffect: function( effect, options, speed, callback ) {
  175. var args = _normalizeArguments.apply( this, arguments ),
  176. mode = args.mode,
  177. queue = args.queue,
  178. effectMethod = $.jqplot.effects.effect[ args.effect ],
  179. // DEPRECATED: remove in 2.0 (#7115)
  180. oldEffectMethod = !effectMethod && backCompat && $.jqplot.effects[ args.effect ];
  181. if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) {
  182. // delegate to the original method (e.g., .show()) if possible
  183. if ( mode ) {
  184. return this[ mode ]( args.duration, args.complete );
  185. } else {
  186. return this.each( function() {
  187. if ( args.complete ) {
  188. args.complete.call( this );
  189. }
  190. });
  191. }
  192. }
  193. function run( next ) {
  194. var elem = $( this ),
  195. complete = args.complete,
  196. mode = args.mode;
  197. function done() {
  198. if ( $.isFunction( complete ) ) {
  199. complete.call( elem[0] );
  200. }
  201. if ( $.isFunction( next ) ) {
  202. next();
  203. }
  204. }
  205. // if the element is hiddden and mode is hide,
  206. // or element is visible and mode is show
  207. if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
  208. done();
  209. } else {
  210. effectMethod.call( elem[0], args, done );
  211. }
  212. }
  213. // TODO: remove this check in 2.0, effectMethod will always be true
  214. if ( effectMethod ) {
  215. return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
  216. } else {
  217. // DEPRECATED: remove in 2.0 (#7115)
  218. return oldEffectMethod.call(this, {
  219. options: args,
  220. duration: args.duration,
  221. callback: args.complete,
  222. mode: args.mode
  223. });
  224. }
  225. }
  226. });
  227. })(jQuery);