summaryrefslogtreecommitdiffstats
path: root/static/metricsgraphics/js/main.js
blob: 651c3a7b89e4b576d999cb48e6437e8fc9b6b038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
var theme = 'dark';

(function() {
    'use strict';

    //set the active pill and section on first load
    var section = (document.location.hash) ? document.location.hash.slice(1) : 'signature_lookup';

    if (section.indexOf("bugzilla") != -1) {
      $('#trunk').load('charts/bugzilla/' + section + '.htm', function() {
        $('pre code').each(function(i, block) {
            hljs.highlightBlock(block);
        });
      });
    } else {
      if (section.indexOf("bz_signatures") != -1) {
        $('#trunk').load('charts/bz_signatures.htm', function() {
          $('pre code').each(function(i, block) {
            hljs.highlightBlock(block);
          });
        });
      } else {
        $('#trunk').load('charts/' + section + '.htm', function() {
          $('pre code').each(function(i, block) {
            hljs.highlightBlock(block);
          });
        });
      }
    }

    $('.menu a#goto-' + section).addClass('active');

    //handle mouse clicks and so on
    assignEventListeners();

    function assignEventListeners() {
        $('button.load').on('click', function(event) {
            var metric = document.getElementById('select_metric').selectedOptions[0].value;
            if (metric.indexOf('bugzilla') != -1) {
                metric = 'bugzilla/' + metric;
            }
            var chart = 'charts/' + metric + '.htm';
            $('#trunk').load(chart, function() {
                $('pre code').each(function(i, block) {
                    hljs.highlightBlock(block);
                });
            });
        })
        
        $('a.pill').on('click', function(event) {
            event.preventDefault();
            $('a.pill').removeClass('active');
            $(this).addClass('active');

            var section = $(this).attr('id').slice(5);
            if (section.indexOf("bugzilla") != -1) {
              $('#trunk').load('charts/bugzilla/' + section + '.htm', function() {
                $('pre code').each(function(i, block) {
                  hljs.highlightBlock(block);
                });
              });
            } else {
              $('#trunk').load('charts/' + section + '.htm', function() {
                $('pre code').each(function(i, block) {
                  hljs.highlightBlock(block);
                });
              });
            }

            document.location.hash = section;

            return false;
        })

        $('#dark-css').on('click', function () {
            theme = 'dark';

            $('.missing')
                .css('background-image', 'url(images/missing-data-dark.png)');

            $('.wip')
                .css('background-color', '#3b3b3b');

            $('.trunk-section')
                .css('border-top-color', '#5e5e5e');

            $('.mg-missing-background')
                .css('stroke', '#ccc');

            $('.head ul li a.pill').removeClass('active');
            $(this).toggleClass('active');
            $('#dark').attr({href : 'css/metricsgraphics-demo-dark.css'});
            $('#dark-code').attr({href : 'css/railscasts.css'});
            $('#accessible').attr({href : ''});

            return false;
        });

        $('#light-css').on('click', function () {
            theme = 'light';

            $('.missing')
                .css('background-image', 'url(images/missing-data.png)');

            $('.wip')
                .css('background-color', '#f1f1f1');

            $('.trunk-section')
                .css('border-top-color', '#ccc');

            $('.mg-missing-background')
                .css('stroke', 'blue');

            $('.head ul li a.pill').removeClass('active');
            $(this).toggleClass('active');
            $('#dark').attr({href : ''});
            $('#dark-code').attr({href : ''});
            $('#accessible').attr({href : ''});

            return false;
        });
        
       

        $('#accessible-css').on('click', function () {
            $('.head ul li a.pill').removeClass('active');
            $(this).toggleClass('active');
            $('#accessible').attr({href : 'css/metricsgraphics-demo-accessible.css'});

            return false;
        });
    }

    // replace all SVG images with inline SVG
    // http://stackoverflow.com/questions/11978995/how-to-change-color-of-svg
    // -image-using-css-jquery-svg-image-replacement
    $('img.svg').each(function() {
        var $img = jQuery(this);
        var imgID = $img.attr('id');
        var imgClass = $img.attr('class');
        var imgURL = $img.attr('src');

        $.get(imgURL, function(data) {
            // Get the SVG tag, ignore the rest
            var $svg = jQuery(data).find('svg');

            // Add replaced image's ID to the new SVG
            if (typeof imgID !== 'undefined') {
                $svg = $svg.attr('id', imgID);
            }
            // Add replaced image's classes to the new SVG
            if (typeof imgClass !== 'undefined') {
                $svg = $svg.attr('class', imgClass + ' replaced-svg');
            }

            // Remove any invalid XML tags as per http://validator.w3.org
            $svg = $svg.removeAttr('xmlns:a');

            // Replace image with new SVG
            $img.replaceWith($svg);

        }, 'xml');
    });
})();