PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/pykeg/src/pykeg/web/media/highcharts/js/adapters/mootools-adapter.src.js

https://code.google.com/p/kegbot/
JavaScript | 210 lines | 111 code | 30 blank | 69 comment | 21 complexity | a8f6716b90c3c07e3bd02714a7264dc8 MD5 | raw file
Possible License(s): GPL-2.0
  1. /**
  2. * @license Highcharts JS v2.1.0 (2010-11-23)
  3. * MooTools adapter
  4. *
  5. * (c) 2010 Torstein H?¸nsi
  6. *
  7. * License: www.highcharts.com/license
  8. */
  9. // JSLint options:
  10. /*global Highcharts, Fx, $, $extend, $each, $merge, Events, Event */
  11. var HighchartsAdapter = {
  12. /**
  13. * Initialize the adapter. This is run once as Highcharts is first run.
  14. */
  15. init: function() {
  16. var fxProto = Fx.prototype,
  17. fxStart = fxProto.start,
  18. morphProto = Fx.Morph.prototype,
  19. morphCompute = morphProto.compute;
  20. // override Fx.step to allow animation of SVG element wrappers
  21. fxProto.start = function(from, to) {
  22. var fx = this,
  23. elem = fx.element;
  24. // special for animating paths
  25. if (from.d) {
  26. //this.fromD = this.element.d.split(' ');
  27. fx.paths = Highcharts.pathAnim.init(
  28. elem,
  29. elem.d,
  30. fx.toD
  31. );
  32. }
  33. fxStart.apply(fx, arguments);
  34. };
  35. // override Fx.step to allow animation of SVG element wrappers
  36. morphProto.compute = function(from, to, delta) {
  37. var fx = this,
  38. paths = fx.paths;
  39. if (paths) {
  40. fx.element.attr(
  41. 'd',
  42. Highcharts.pathAnim.step(paths[0], paths[1], delta, fx.toD)
  43. );
  44. } else {
  45. return morphCompute.apply(fx, arguments);
  46. }
  47. };
  48. },
  49. /**
  50. * Animate a HTML element or SVG element wrapper
  51. * @param {Object} el
  52. * @param {Object} params
  53. * @param {Object} options jQuery-like animation options: duration, easing, callback
  54. */
  55. animate: function (el, params, options) {
  56. var isSVGElement = el.attr,
  57. effect,
  58. complete = options && options.complete;
  59. if (isSVGElement && !el.setStyle) {
  60. // add setStyle and getStyle methods for internal use in Moo
  61. el.setStyle = el.getStyle = el.attr;
  62. // dirty hack to trick Moo into handling el as an element wrapper
  63. el.$family = el.uid = true;
  64. }
  65. // stop running animations
  66. HighchartsAdapter.stop(el);
  67. // define and run the effect
  68. effect = new Fx.Morph(
  69. isSVGElement ? el : $(el),
  70. $extend({
  71. transition: Fx.Transitions.Quad.easeInOut
  72. }, options)
  73. );
  74. // special treatment for paths
  75. if (params.d) {
  76. effect.toD = params.d;
  77. }
  78. // jQuery-like events
  79. if (complete) {
  80. effect.addEvent('complete', complete);
  81. }
  82. // run
  83. effect.start(params);
  84. // record for use in stop method
  85. el.fx = effect;
  86. },
  87. /**
  88. * MooTool's each function
  89. *
  90. */
  91. each: $each,
  92. /**
  93. * Map an array
  94. * @param {Array} arr
  95. * @param {Function} fn
  96. */
  97. map: function (arr, fn){
  98. return arr.map(fn);
  99. },
  100. /**
  101. * Grep or filter an array
  102. * @param {Array} arr
  103. * @param {Function} fn
  104. */
  105. grep: function(arr, fn) {
  106. return arr.filter(fn);
  107. },
  108. /**
  109. * Deep merge two objects and return a third
  110. */
  111. merge: $merge,
  112. /**
  113. * Hyphenate a string, like minWidth becomes min-width
  114. * @param {Object} str
  115. */
  116. hyphenate: function (str){
  117. return str.hyphenate();
  118. },
  119. /**
  120. * Add an event listener
  121. * @param {Object} el HTML element or custom object
  122. * @param {String} type Event type
  123. * @param {Function} fn Event handler
  124. */
  125. addEvent: function (el, type, fn) {
  126. if (typeof type == 'string') { // chart broke due to el being string, type function
  127. if (type == 'unload') { // Moo self destructs before custom unload events
  128. type = 'beforeunload';
  129. }
  130. // if the addEvent method is not defined, el is a custom Highcharts object
  131. // like series or point
  132. if (!el.addEvent) {
  133. if (el.nodeName) {
  134. el = $(el); // a dynamically generated node
  135. } else {
  136. $extend(el, new Events()); // a custom object
  137. }
  138. }
  139. el.addEvent(type, fn);
  140. }
  141. },
  142. removeEvent: function(el, type, fn) {
  143. if (type) {
  144. if (type == 'unload') { // Moo self destructs before custom unload events
  145. type = 'beforeunload';
  146. }
  147. el.removeEvent(type, fn);
  148. }
  149. },
  150. fireEvent: function(el, event, eventArguments, defaultFunction) {
  151. // create an event object that keeps all functions
  152. event = new Event({
  153. type: event,
  154. target: el
  155. });
  156. event = $extend(event, eventArguments);
  157. // override the preventDefault function to be able to use
  158. // this for custom events
  159. event.preventDefault = function() {
  160. defaultFunction = null;
  161. };
  162. // if fireEvent is not available on the object, there hasn't been added
  163. // any events to it above
  164. if (el.fireEvent) {
  165. el.fireEvent(event.type, event);
  166. }
  167. // fire the default if it is passed and it is not prevented above
  168. if (defaultFunction) {
  169. defaultFunction(event);
  170. }
  171. },
  172. /**
  173. * Stop running animations on the object
  174. */
  175. stop: function (el) {
  176. if (el.fx) {
  177. el.fx.cancel();
  178. }
  179. }
  180. };