2
* @license Highcharts JS v2.2.1 (2012-03-15)
5
* (c) 2010-2011 Torstein Hønsi
7
* License: www.highcharts.com/license
11
/*global Fx, $, $extend, $each, $merge, Events, Event, DOMEvent */
17
mooVersion = win.MooTools.version.substring(0, 3), // Get the first three characters of the version number
18
legacy = mooVersion === '1.2' || mooVersion === '1.1', // 1.1 && 1.2 considered legacy, 1.3 is not.
19
legacyEvent = legacy || mooVersion === '1.3', // In versions 1.1 - 1.3 the event class is named Event, in newer versions it is named DOMEvent.
20
$extend = win.$extend || function () {
21
return Object.append.apply(Object, arguments);
24
win.HighchartsAdapter = {
26
* Initialize the adapter. This is run once as Highcharts is first run.
27
* @param {Object} pathAnim The helper object to do animations across adapters.
29
init: function (pathAnim) {
30
var fxProto = Fx.prototype,
31
fxStart = fxProto.start,
32
morphProto = Fx.Morph.prototype,
33
morphCompute = morphProto.compute;
35
// override Fx.start to allow animation of SVG element wrappers
36
/*jslint unparam: true*//* allow unused parameters in fx functions */
37
fxProto.start = function (from, to) {
41
// special for animating paths
43
//this.fromD = this.element.d.split(' ');
44
fx.paths = pathAnim.init(
50
fxStart.apply(fx, arguments);
52
return this; // chainable
55
// override Fx.step to allow animation of SVG element wrappers
56
morphProto.compute = function (from, to, delta) {
63
pathAnim.step(paths[0], paths[1], delta, fx.toD)
66
return morphCompute.apply(fx, arguments);
69
/*jslint unparam: false*/
73
* Downloads a script and executes a callback when done.
74
* @param {String} scriptLocation
75
* @param {Function} callback
77
getScript: function (scriptLocation, callback) {
78
// We cannot assume that Assets class from mootools-more is available so instead insert a script tag to download script.
79
var head = doc.getElementsByTagName('head')[0];
80
var script = doc.createElement('script');
82
script.type = 'text/javascript';
83
script.src = scriptLocation;
84
script.onload = callback;
86
head.appendChild(script);
90
* Animate a HTML element or SVG element wrapper
92
* @param {Object} params
93
* @param {Object} options jQuery-like animation options: duration, easing, callback
95
animate: function (el, params, options) {
96
var isSVGElement = el.attr,
98
complete = options && options.complete;
100
if (isSVGElement && !el.setStyle) {
101
// add setStyle and getStyle methods for internal use in Moo
102
el.getStyle = el.attr;
103
el.setStyle = function () { // property value is given as array in Moo - break it down
104
var args = arguments;
105
el.attr.call(el, args[0], args[1][0]);
107
// dirty hack to trick Moo into handling el as an element wrapper
108
el.$family = function () { return true; };
111
// stop running animations
112
win.HighchartsAdapter.stop(el);
114
// define and run the effect
115
effect = new Fx.Morph(
116
isSVGElement ? el : $(el),
118
transition: Fx.Transitions.Quad.easeInOut
122
// Make sure that the element reference is set when animating svg elements
127
// special treatment for paths
129
effect.toD = params.d;
132
// jQuery-like events
134
effect.addEvent('complete', complete);
138
effect.start(params);
140
// record for use in stop method
145
* MooTool's each function
148
each: function (arr, fn) {
157
* @param {Function} fn
159
map: function (arr, fn) {
164
* Grep or filter an array
166
* @param {Function} fn
168
grep: function (arr, fn) {
169
return arr.filter(fn);
173
* Deep merge two objects and return a third
176
var args = arguments,
177
args13 = [{}], // MooTools 1.3+
182
ret = $merge.apply(null, args);
185
// Boolean argumens should not be merged.
186
// JQuery explicitly skips this, so we do it here as well.
187
if (typeof args[i] !== 'boolean') {
188
args13[i + 1] = args[i];
191
ret = Object.merge.apply(Object, args13);
198
* Get the offset of an element relative to the top left corner of the web page
200
offset: function (el) {
201
var offsets = $(el).getOffsets();
209
* Extends an object with Events, if its not done
211
extendWithEvents: function (el) {
212
// if the addEvent method is not defined, el is a custom Highcharts object
213
// like series or point
216
el = $(el); // a dynamically generated node
218
$extend(el, new Events()); // a custom object
224
* Add an event listener
225
* @param {Object} el HTML element or custom object
226
* @param {String} type Event type
227
* @param {Function} fn Event handler
229
addEvent: function (el, type, fn) {
230
if (typeof type === 'string') { // chart broke due to el being string, type function
232
if (type === 'unload') { // Moo self destructs before custom unload events
233
type = 'beforeunload';
236
win.HighchartsAdapter.extendWithEvents(el);
238
el.addEvent(type, fn);
242
removeEvent: function (el, type, fn) {
243
if (typeof el === 'string') {
244
// el.removeEvents below apperantly calls this method again. Do not quite understand why, so for now just bail out.
247
win.HighchartsAdapter.extendWithEvents(el);
249
if (type === 'unload') { // Moo self destructs before custom unload events
250
type = 'beforeunload';
254
el.removeEvent(type, fn);
256
el.removeEvents(type);
263
fireEvent: function (el, event, eventArguments, defaultFunction) {
268
// create an event object that keeps all functions
269
event = legacyEvent ? new Event(eventArgs) : new DOMEvent(eventArgs);
270
event = $extend(event, eventArguments);
271
// override the preventDefault function to be able to use
272
// this for custom events
273
event.preventDefault = function () {
274
defaultFunction = null;
276
// if fireEvent is not available on the object, there hasn't been added
277
// any events to it above
279
el.fireEvent(event.type, event);
282
// fire the default if it is passed and it is not prevented above
283
if (defaultFunction) {
284
defaultFunction(event);
289
* Stop running animations on the object
291
stop: function (el) {