~chromium-team/chromium-browser/trusty-beta

« back to all changes in this revision

Viewing changes to debian/tests/data/HTML5test/scripts/highcharts/adapters/mootools-adapter.src.js

  • Committer: Olivier Tilloy
  • Date: 2017-10-23 16:46:53 UTC
  • mfrom: (1172.1.38 trusty-stable)
  • Revision ID: olivier.tilloy@canonical.com-20171023164653-zmpfzblxxnkj0jhj
Merge back changes from stable branch:
  * debian/control: bump Standards-Version to 4.1.1
  * debian/patches/set-rpath-on-chromium-executables.patch: updated
  * debian/tests/*:
    - removed stale autopkgtests
    - added new autopkgtests based on chromium's new headless mode
  * debian/source/include-binaries: updated to reflect new binary data in tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @license Highcharts JS v2.2.1 (2012-03-15)
 
3
 * MooTools adapter
 
4
 *
 
5
 * (c) 2010-2011 Torstein Hønsi
 
6
 *
 
7
 * License: www.highcharts.com/license
 
8
 */
 
9
 
 
10
// JSLint options:
 
11
/*global Fx, $, $extend, $each, $merge, Events, Event, DOMEvent */
 
12
 
 
13
(function () {
 
14
 
 
15
var win = window,
 
16
        doc = document,
 
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);
 
22
        };
 
23
 
 
24
win.HighchartsAdapter = {
 
25
        /**
 
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.
 
28
         */
 
29
        init: function (pathAnim) {
 
30
                var fxProto = Fx.prototype,
 
31
                        fxStart = fxProto.start,
 
32
                        morphProto = Fx.Morph.prototype,
 
33
                        morphCompute = morphProto.compute;
 
34
 
 
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) {
 
38
                        var fx = this,
 
39
                                elem = fx.element;
 
40
 
 
41
                        // special for animating paths
 
42
                        if (from.d) {
 
43
                                //this.fromD = this.element.d.split(' ');
 
44
                                fx.paths = pathAnim.init(
 
45
                                        elem,
 
46
                                        elem.d,
 
47
                                        fx.toD
 
48
                                );
 
49
                        }
 
50
                        fxStart.apply(fx, arguments);
 
51
 
 
52
                        return this; // chainable
 
53
                };
 
54
 
 
55
                // override Fx.step to allow animation of SVG element wrappers
 
56
                morphProto.compute = function (from, to, delta) {
 
57
                        var fx = this,
 
58
                                paths = fx.paths;
 
59
 
 
60
                        if (paths) {
 
61
                                fx.element.attr(
 
62
                                        'd',
 
63
                                        pathAnim.step(paths[0], paths[1], delta, fx.toD)
 
64
                                );
 
65
                        } else {
 
66
                                return morphCompute.apply(fx, arguments);
 
67
                        }
 
68
                };
 
69
                /*jslint unparam: false*/
 
70
        },
 
71
 
 
72
        /**
 
73
         * Downloads a script and executes a callback when done.
 
74
         * @param {String} scriptLocation
 
75
         * @param {Function} callback
 
76
         */
 
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');
 
81
 
 
82
                script.type = 'text/javascript';
 
83
                script.src = scriptLocation;
 
84
                script.onload = callback;
 
85
 
 
86
                head.appendChild(script);
 
87
        },
 
88
 
 
89
        /**
 
90
         * Animate a HTML element or SVG element wrapper
 
91
         * @param {Object} el
 
92
         * @param {Object} params
 
93
         * @param {Object} options jQuery-like animation options: duration, easing, callback
 
94
         */
 
95
        animate: function (el, params, options) {
 
96
                var isSVGElement = el.attr,
 
97
                        effect,
 
98
                        complete = options && options.complete;
 
99
 
 
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]);
 
106
                        };
 
107
                        // dirty hack to trick Moo into handling el as an element wrapper
 
108
                        el.$family = function () { return true; };
 
109
                }
 
110
 
 
111
                // stop running animations
 
112
                win.HighchartsAdapter.stop(el);
 
113
 
 
114
                // define and run the effect
 
115
                effect = new Fx.Morph(
 
116
                        isSVGElement ? el : $(el),
 
117
                        $extend({
 
118
                                transition: Fx.Transitions.Quad.easeInOut
 
119
                        }, options)
 
120
                );
 
121
 
 
122
                // Make sure that the element reference is set when animating svg elements
 
123
                if (isSVGElement) {
 
124
                        effect.element = el;
 
125
                }
 
126
 
 
127
                // special treatment for paths
 
128
                if (params.d) {
 
129
                        effect.toD = params.d;
 
130
                }
 
131
 
 
132
                // jQuery-like events
 
133
                if (complete) {
 
134
                        effect.addEvent('complete', complete);
 
135
                }
 
136
 
 
137
                // run
 
138
                effect.start(params);
 
139
 
 
140
                // record for use in stop method
 
141
                el.fx = effect;
 
142
        },
 
143
 
 
144
        /**
 
145
         * MooTool's each function
 
146
         *
 
147
         */
 
148
        each: function (arr, fn) {
 
149
                return legacy ?
 
150
                        $each(arr, fn) :
 
151
                        Array.each(arr, fn);
 
152
        },
 
153
 
 
154
        /**
 
155
         * Map an array
 
156
         * @param {Array} arr
 
157
         * @param {Function} fn
 
158
         */
 
159
        map: function (arr, fn) {
 
160
                return arr.map(fn);
 
161
        },
 
162
 
 
163
        /**
 
164
         * Grep or filter an array
 
165
         * @param {Array} arr
 
166
         * @param {Function} fn
 
167
         */
 
168
        grep: function (arr, fn) {
 
169
                return arr.filter(fn);
 
170
        },
 
171
 
 
172
        /**
 
173
         * Deep merge two objects and return a third
 
174
         */
 
175
        merge: function () {
 
176
                var args = arguments,
 
177
                        args13 = [{}], // MooTools 1.3+
 
178
                        i = args.length,
 
179
                        ret;
 
180
 
 
181
                if (legacy) {
 
182
                        ret = $merge.apply(null, args);
 
183
                } else {
 
184
                        while (i--) {
 
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];
 
189
                                }
 
190
                        }
 
191
                        ret = Object.merge.apply(Object, args13);
 
192
                }
 
193
 
 
194
                return ret;
 
195
        },
 
196
 
 
197
        /**
 
198
         * Get the offset of an element relative to the top left corner of the web page
 
199
         */
 
200
        offset: function (el) {
 
201
                var offsets = $(el).getOffsets();
 
202
                return {
 
203
                        left: offsets.x,
 
204
                        top: offsets.y
 
205
                };
 
206
        },
 
207
 
 
208
        /**
 
209
         * Extends an object with Events, if its not done
 
210
         */
 
211
        extendWithEvents: function (el) {
 
212
                // if the addEvent method is not defined, el is a custom Highcharts object
 
213
                // like series or point
 
214
                if (!el.addEvent) {
 
215
                        if (el.nodeName) {
 
216
                                el = $(el); // a dynamically generated node
 
217
                        } else {
 
218
                                $extend(el, new Events()); // a custom object
 
219
                        }
 
220
                }
 
221
        },
 
222
 
 
223
        /**
 
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
 
228
         */
 
229
        addEvent: function (el, type, fn) {
 
230
                if (typeof type === 'string') { // chart broke due to el being string, type function
 
231
 
 
232
                        if (type === 'unload') { // Moo self destructs before custom unload events
 
233
                                type = 'beforeunload';
 
234
                        }
 
235
 
 
236
                        win.HighchartsAdapter.extendWithEvents(el);
 
237
 
 
238
                        el.addEvent(type, fn);
 
239
                }
 
240
        },
 
241
 
 
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.
 
245
                        return;
 
246
                }
 
247
                win.HighchartsAdapter.extendWithEvents(el);
 
248
                if (type) {
 
249
                        if (type === 'unload') { // Moo self destructs before custom unload events
 
250
                                type = 'beforeunload';
 
251
                        }
 
252
 
 
253
                        if (fn) {
 
254
                                el.removeEvent(type, fn);
 
255
                        } else {
 
256
                                el.removeEvents(type);
 
257
                        }
 
258
                } else {
 
259
                        el.removeEvents();
 
260
                }
 
261
        },
 
262
 
 
263
        fireEvent: function (el, event, eventArguments, defaultFunction) {
 
264
                var eventArgs = {
 
265
                        type: event,
 
266
                        target: el
 
267
                };
 
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;
 
275
                };
 
276
                // if fireEvent is not available on the object, there hasn't been added
 
277
                // any events to it above
 
278
                if (el.fireEvent) {
 
279
                        el.fireEvent(event.type, event);
 
280
                }
 
281
 
 
282
                // fire the default if it is passed and it is not prevented above
 
283
                if (defaultFunction) {
 
284
                        defaultFunction(event);
 
285
                }
 
286
        },
 
287
 
 
288
        /**
 
289
         * Stop running animations on the object
 
290
         */
 
291
        stop: function (el) {
 
292
                if (el.fx) {
 
293
                        el.fx.cancel();
 
294
                }
 
295
        }
 
296
};
 
297
 
 
298
}());