2
* @license Highstock JS v1.3.10 (2014-03-10)
5
* (c) 2010-2014 Torstein Honsi
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
* Run a general method on the framework, following jQuery syntax
74
* @param {Object} el The HTML element
75
* @param {String} method Which method to run on the wrapped element
77
adapterRun: function (el, method) {
79
// This currently works for getting inner width and height. If adding
80
// more methods later, we need a conditional implementation for each.
81
if (method === 'width' || method === 'height') {
82
return parseInt(document.id(el).getStyle(method), 10);
87
* Downloads a script and executes a callback when done.
88
* @param {String} scriptLocation
89
* @param {Function} callback
91
getScript: function (scriptLocation, callback) {
92
// We cannot assume that Assets class from mootools-more is available so instead insert a script tag to download script.
93
var head = doc.getElementsByTagName('head')[0];
94
var script = doc.createElement('script');
96
script.type = 'text/javascript';
97
script.src = scriptLocation;
98
script.onload = callback;
100
head.appendChild(script);
104
* Animate a HTML element or SVG element wrapper
106
* @param {Object} params
107
* @param {Object} options jQuery-like animation options: duration, easing, callback
109
animate: function (el, params, options) {
110
var isSVGElement = el.attr,
112
complete = options && options.complete;
114
if (isSVGElement && !el.setStyle) {
115
// add setStyle and getStyle methods for internal use in Moo
116
el.getStyle = el.attr;
117
el.setStyle = function () { // property value is given as array in Moo - break it down
118
var args = arguments;
119
this.attr.call(this, args[0], args[1][0]);
121
// dirty hack to trick Moo into handling el as an element wrapper
122
el.$family = function () { return true; };
123
el.getComputedStyle = function () {
124
return el.element.getComputedStyle.apply(el.element, arguments);
128
// stop running animations
129
win.HighchartsAdapter.stop(el);
131
// define and run the effect
132
effect = new Fx.Morph(
133
isSVGElement ? el : document.id(el),
135
transition: Fx.Transitions.Quad.easeInOut
139
// Make sure that the element reference is set when animating svg elements
144
// special treatment for paths
146
effect.toD = params.d;
149
// jQuery-like events
151
effect.addEvent('complete', complete);
155
effect.start(params);
157
// record for use in stop method
162
* MooTool's each function
165
each: function (arr, fn) {
174
* @param {Function} fn
176
map: function (arr, fn) {
181
* Grep or filter an array
183
* @param {Function} fn
185
grep: function (arr, fn) {
186
return arr.filter(fn);
190
* Return the index of an item in an array, or -1 if not matched
192
inArray: function (item, arr, from) {
193
return arr ? arr.indexOf(item, from) : -1;
197
* Get the offset of an element relative to the top left corner of the web page
199
offset: function (el) {
200
var offsets = el.getPosition(); // #1496
208
* Extends an object with Events, if its not done
210
extendWithEvents: function (el) {
211
// if the addEvent method is not defined, el is a custom Highcharts object
212
// like series or point
215
el = document.id(el); // a dynamically generated node
217
$extend(el, new Events()); // a custom object
223
* Add an event listener
224
* @param {Object} el HTML element or custom object
225
* @param {String} type Event type
226
* @param {Function} fn Event handler
228
addEvent: function (el, type, fn) {
229
if (typeof type === 'string') { // chart broke due to el being string, type function
231
if (type === 'unload') { // Moo self destructs before custom unload events
232
type = 'beforeunload';
235
win.HighchartsAdapter.extendWithEvents(el);
237
el.addEvent(type, fn);
241
removeEvent: function (el, type, fn) {
242
if (typeof el === 'string') {
243
// el.removeEvents below apperantly calls this method again. Do not quite understand why, so for now just bail out.
247
if (el.addEvent) { // If el doesn't have an addEvent method, there are no events to remove
249
if (type === 'unload') { // Moo self destructs before custom unload events
250
type = 'beforeunload';
254
el.removeEvent(type, fn);
255
} else if (el.removeEvents) { // #958
256
el.removeEvents(type);
264
fireEvent: function (el, event, eventArguments, defaultFunction) {
269
// create an event object that keeps all functions
270
event = legacyEvent ? new Event(eventArgs) : new DOMEvent(eventArgs);
271
event = $extend(event, eventArguments);
273
// When running an event on the Chart.prototype, MooTools nests the target in event.event
274
if (!event.target && event.event) {
275
event.target = event.event.target;
278
// override the preventDefault function to be able to use
279
// this for custom events
280
event.preventDefault = function () {
281
defaultFunction = null;
283
// if fireEvent is not available on the object, there hasn't been added
284
// any events to it above
286
el.fireEvent(event.type, event);
289
// fire the default if it is passed and it is not prevented above
290
if (defaultFunction) {
291
defaultFunction(event);
296
* Set back e.pageX and e.pageY that MooTools has abstracted away. #1165, #1346.
298
washMouseEvent: function (e) {
307
* Stop running animations on the object
309
stop: function (el) {