mootools-adapter.src.js.soonsu 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. (function() {
  2. var win = window,
  3. legacy = !!win.$merge
  4. $extend = win.$extend || function() {
  5. return Object.append.apply(Object, arguments)
  6. };
  7. win.HighchartsAdapter = {
  8. init: function() {
  9. var fxProto = Fx.prototype,
  10. fxStart = fxProto.start,
  11. morphProto = Fx.Morph.prototype,
  12. morphCompute = morphProto.compute;
  13. fxProto.start = function(from, to) {
  14. var fx = this,
  15. elem = fx.element;
  16. if (from.d) {
  17. fx.paths = Highcharts.pathAnim.init(
  18. elem,
  19. elem.d,
  20. fx.toD
  21. );
  22. }
  23. fxStart.apply(fx, arguments);
  24. };
  25. morphProto.compute = function(from, to, delta) {
  26. var fx = this,
  27. paths = fx.paths;
  28. if (paths) {
  29. fx.element.attr(
  30. 'd',
  31. Highcharts.pathAnim.step(paths[0], paths[1], delta, fx.toD)
  32. );
  33. } else {
  34. return morphCompute.apply(fx, arguments);
  35. }
  36. };
  37. },
  38. animate: function (el, params, options) {
  39. var isSVGElement = el.attr,
  40. effect,
  41. complete = options && options.complete;
  42. if (isSVGElement && !el.setStyle) {
  43. el.getStyle = el.attr;
  44. el.setStyle = function() {
  45. var args = arguments;
  46. el.attr.call(el, args[0], args[1][0]);
  47. }
  48. el.$family = el.uid = true;
  49. }
  50. HighchartsAdapter.stop(el);
  51. effect = new Fx.Morph(
  52. isSVGElement ? el : $(el),
  53. $extend({
  54. transition: Fx.Transitions.Quad.easeInOut
  55. }, options)
  56. );
  57. if (params.d) {
  58. effect.toD = params.d;
  59. }
  60. if (complete) {
  61. effect.addEvent('complete', complete);
  62. }
  63. effect.start(params);
  64. el.fx = effect;
  65. },
  66. each: function(arr, fn) {
  67. return legacy ?
  68. $each(arr, fn) :
  69. arr.each(fn);
  70. },
  71. map: function (arr, fn){
  72. return arr.map(fn);
  73. },
  74. grep: function(arr, fn) {
  75. return arr.filter(fn);
  76. },
  77. merge: function() {
  78. var args = arguments,
  79. args13 = [{}],
  80. i = args.length,
  81. ret;
  82. if (legacy) {
  83. ret = $merge.apply(null, args);
  84. } else {
  85. while (i--) {
  86. args13[i + 1] = args[i];
  87. }
  88. ret = Object.merge.apply(Object, args13);
  89. }
  90. return ret;
  91. },
  92. hyphenate: function (str){
  93. return str.hyphenate();
  94. },
  95. addEvent: function (el, type, fn) {
  96. if (typeof type == 'string') {
  97. if (type == 'unload') {
  98. type = 'beforeunload';
  99. }
  100. if (!el.addEvent) {
  101. if (el.nodeName) {
  102. el = $(el);
  103. } else {
  104. $extend(el, new Events());
  105. }
  106. }
  107. el.addEvent(type, fn);
  108. }
  109. },
  110. removeEvent: function(el, type, fn) {
  111. if (type) {
  112. if (type == 'unload') {
  113. type = 'beforeunload';
  114. }
  115. el.removeEvent(type, fn);
  116. }
  117. },
  118. fireEvent: function(el, event, eventArguments, defaultFunction) {
  119. m_event = new Event({
  120. type: event,
  121. target: el
  122. });
  123. m_event = $extend(event, eventArguments);
  124. m_event.preventDefault = function() {
  125. defaultFunction = null;
  126. };
  127. if (el.fireEvent) {
  128. el.fireEvent(m_event.type, m_event);
  129. }
  130. if (defaultFunction) {
  131. defaultFunction(m_event);
  132. }
  133. },
  134. stop: function (el) {
  135. if (el.fx) {
  136. el.fx.cancel();
  137. }
  138. }
  139. }
  140. })();