Passed
Push — master ( 384962...a2213c )
by Benjamin
26:55 queued 19:06
created

Garnish.Base.extend.init   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 2
b 0
f 0
1
/** global: Analytics */
2
/** global: Garnish */
3
/** global: google */
4
/**
5
 * Visualization
6
 */
7
Analytics.Visualization = Garnish.Base.extend({
8
9
    options: null,
10
    afterInitStack: [],
11
12
    init: function(options) {
13
        this.options = options;
14
15
        if (Analytics.GoogleVisualizationCalled == false) {
0 ignored issues
show
Best Practice introduced by
Comparing Analytics.GoogleVisualizationCalled to false using the == operator is not safe. Consider using === instead.
Loading history...
16
            Analytics.GoogleVisualizationCalled = true;
17
18
            google.charts.load('current', {
19
                packages: ['corechart', 'table'],
20
                language: Analytics.chartLanguage,
21
                mapsApiKey: Analytics.mapsApiKey,
22
                callback: $.proxy(function() {
23
                    Analytics.GoogleVisualizationReady = true;
24
25
                    this.onAfterInit();
26
27
                    this.onAfterFirstInit();
28
                }, this)
29
            });
30
        } else {
31
            this.onAfterInit();
32
        }
33
    },
34
35
    onAfterFirstInit: function() {
36
        // call inAfterInits that are waiting for initialization completion
37
38
        for (i = 0; i < this.afterInitStack.length; i++) {
0 ignored issues
show
Bug introduced by
The variable i seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.i.
Loading history...
39
            this.afterInitStack[i]();
40
        }
41
    },
42
43
    onAfterInit: function() {
44
        if (Analytics.GoogleVisualizationReady) {
45
            this.options.onAfterInit();
46
        } else {
47
            // add it to the stack
48
            this.afterInitStack.push(this.options.onAfterInit);
49
        }
50
    }
51
});