OLD | NEW |
| 1 // Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
| 2 // For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt |
| 3 |
1 // Coverage.py HTML report browser code. | 4 // Coverage.py HTML report browser code. |
2 /*jslint browser: true, sloppy: true, vars: true, plusplus: true, maxerr: 50, in
dent: 4 */ | 5 /*jslint browser: true, sloppy: true, vars: true, plusplus: true, maxerr: 50, in
dent: 4 */ |
3 /*global coverage: true, document, window, $ */ | 6 /*global coverage: true, document, window, $ */ |
4 | 7 |
5 coverage = {}; | 8 coverage = {}; |
6 | 9 |
7 // Find all the elements with shortkey_* class, and use them to assign a shotrtc
ut key. | 10 // Find all the elements with shortkey_* class, and use them to assign a shortcu
t key. |
8 coverage.assign_shortkeys = function () { | 11 coverage.assign_shortkeys = function () { |
9 $("*[class*='shortkey_']").each(function (i, e) { | 12 $("*[class*='shortkey_']").each(function (i, e) { |
10 $.each($(e).attr("class").split(" "), function (i, c) { | 13 $.each($(e).attr("class").split(" "), function (i, c) { |
11 if (/^shortkey_/.test(c)) { | 14 if (/^shortkey_/.test(c)) { |
12 $(document).bind('keydown', c.substr(9), function () { | 15 $(document).bind('keydown', c.substr(9), function () { |
13 $(e).click(); | 16 $(e).click(); |
14 }); | 17 }); |
15 } | 18 } |
16 }); | 19 }); |
17 }); | 20 }); |
(...skipping 10 matching lines...) Expand all Loading... |
28 $(".help_panel").offset({ | 31 $(".help_panel").offset({ |
29 top: koff.top-poff.top, | 32 top: koff.top-poff.top, |
30 left: koff.left-poff.left | 33 left: koff.left-poff.left |
31 }); | 34 }); |
32 }); | 35 }); |
33 $("#panel_icon").click(function () { | 36 $("#panel_icon").click(function () { |
34 $(".help_panel").hide(); | 37 $(".help_panel").hide(); |
35 }); | 38 }); |
36 }; | 39 }; |
37 | 40 |
| 41 // Create the events for the filter box. |
| 42 coverage.wire_up_filter = function () { |
| 43 // Cache elements. |
| 44 var table = $("table.index"); |
| 45 var table_rows = table.find("tbody tr"); |
| 46 var table_row_names = table_rows.find("td.name a"); |
| 47 var no_rows = $("#no_rows"); |
| 48 |
| 49 // Create a duplicate table footer that we can modify with dynamic summed va
lues. |
| 50 var table_footer = $("table.index tfoot tr"); |
| 51 var table_dynamic_footer = table_footer.clone(); |
| 52 table_dynamic_footer.attr('class', 'total_dynamic hidden'); |
| 53 table_footer.after(table_dynamic_footer); |
| 54 |
| 55 // Observe filter keyevents. |
| 56 $("#filter").on("keyup change", $.debounce(150, function (event) { |
| 57 var filter_value = $(this).val(); |
| 58 |
| 59 if (filter_value === "") { |
| 60 // Filter box is empty, remove all filtering. |
| 61 table_rows.removeClass("hidden"); |
| 62 |
| 63 // Show standard footer, hide dynamic footer. |
| 64 table_footer.removeClass("hidden"); |
| 65 table_dynamic_footer.addClass("hidden"); |
| 66 |
| 67 // Hide placeholder, show table. |
| 68 if (no_rows.length > 0) { |
| 69 no_rows.hide(); |
| 70 } |
| 71 table.show(); |
| 72 |
| 73 } |
| 74 else { |
| 75 // Filter table items by value. |
| 76 var hide = $([]); |
| 77 var show = $([]); |
| 78 |
| 79 // Compile elements to hide / show. |
| 80 $.each(table_row_names, function () { |
| 81 var element = $(this).parents("tr"); |
| 82 |
| 83 if ($(this).text().indexOf(filter_value) === -1) { |
| 84 // hide |
| 85 hide = hide.add(element); |
| 86 } |
| 87 else { |
| 88 // show |
| 89 show = show.add(element); |
| 90 } |
| 91 }); |
| 92 |
| 93 // Perform DOM manipulation. |
| 94 hide.addClass("hidden"); |
| 95 show.removeClass("hidden"); |
| 96 |
| 97 // Show placeholder if no rows will be displayed. |
| 98 if (no_rows.length > 0) { |
| 99 if (show.length === 0) { |
| 100 // Show placeholder, hide table. |
| 101 no_rows.show(); |
| 102 table.hide(); |
| 103 } |
| 104 else { |
| 105 // Hide placeholder, show table. |
| 106 no_rows.hide(); |
| 107 table.show(); |
| 108 } |
| 109 } |
| 110 |
| 111 // Manage dynamic header: |
| 112 if (hide.length > 0) { |
| 113 // Calculate new dynamic sum values based on visible rows. |
| 114 for (var column = 2; column < 20; column++) { |
| 115 // Calculate summed value. |
| 116 var cells = table_rows.find('td:nth-child(' + column + ')'); |
| 117 if (!cells.length) { |
| 118 // No more columns...! |
| 119 break; |
| 120 } |
| 121 |
| 122 var sum = 0, numer = 0, denom = 0; |
| 123 $.each(cells.filter(':visible'), function () { |
| 124 var ratio = $(this).data("ratio"); |
| 125 if (ratio) { |
| 126 var splitted = ratio.split(" "); |
| 127 numer += parseInt(splitted[0], 10); |
| 128 denom += parseInt(splitted[1], 10); |
| 129 } |
| 130 else { |
| 131 sum += parseInt(this.innerHTML, 10); |
| 132 } |
| 133 }); |
| 134 |
| 135 // Get footer cell element. |
| 136 var footer_cell = table_dynamic_footer.find('td:nth-child('
+ column + ')'); |
| 137 |
| 138 // Set value into dynamic footer cell element. |
| 139 if (cells[0].innerHTML.indexOf('%') > -1) { |
| 140 // Percentage columns use the numerator and denominator, |
| 141 // and adapt to the number of decimal places. |
| 142 var match = /\.([0-9]+)/.exec(cells[0].innerHTML); |
| 143 var places = 0; |
| 144 if (match) { |
| 145 places = match[1].length; |
| 146 } |
| 147 var pct = numer * 100 / denom; |
| 148 footer_cell.text(pct.toFixed(places) + '%'); |
| 149 } |
| 150 else { |
| 151 footer_cell.text(sum); |
| 152 } |
| 153 } |
| 154 |
| 155 // Hide standard footer, show dynamic footer. |
| 156 table_footer.addClass("hidden"); |
| 157 table_dynamic_footer.removeClass("hidden"); |
| 158 } |
| 159 else { |
| 160 // Show standard footer, hide dynamic footer. |
| 161 table_footer.removeClass("hidden"); |
| 162 table_dynamic_footer.addClass("hidden"); |
| 163 } |
| 164 } |
| 165 })); |
| 166 |
| 167 // Trigger change event on setup, to force filter on page refresh |
| 168 // (filter value may still be present). |
| 169 $("#filter").trigger("change"); |
| 170 }; |
| 171 |
38 // Loaded on index.html | 172 // Loaded on index.html |
39 coverage.index_ready = function ($) { | 173 coverage.index_ready = function ($) { |
40 // Look for a cookie containing previous sort settings: | 174 // Look for a cookie containing previous sort settings: |
41 var sort_list = []; | 175 var sort_list = []; |
42 var cookie_name = "COVERAGE_INDEX_SORT"; | 176 var cookie_name = "COVERAGE_INDEX_SORT"; |
43 var i; | 177 var i; |
44 | 178 |
45 // This almost makes it worth installing the jQuery cookie plugin: | 179 // This almost makes it worth installing the jQuery cookie plugin: |
46 if (document.cookie.indexOf(cookie_name) > -1) { | 180 if (document.cookie.indexOf(cookie_name) > -1) { |
47 var cookies = document.cookie.split(";"); | 181 var cookies = document.cookie.split(";"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 headers[col_count-1] = { sorter: 'percent' }; | 222 headers[col_count-1] = { sorter: 'percent' }; |
89 | 223 |
90 // Enable the table sorter: | 224 // Enable the table sorter: |
91 $("table.index").tablesorter({ | 225 $("table.index").tablesorter({ |
92 widgets: ['persistentSort'], | 226 widgets: ['persistentSort'], |
93 headers: headers | 227 headers: headers |
94 }); | 228 }); |
95 | 229 |
96 coverage.assign_shortkeys(); | 230 coverage.assign_shortkeys(); |
97 coverage.wire_up_help_panel(); | 231 coverage.wire_up_help_panel(); |
| 232 coverage.wire_up_filter(); |
98 | 233 |
99 // Watch for page unload events so we can save the final sort settings: | 234 // Watch for page unload events so we can save the final sort settings: |
100 $(window).unload(function () { | 235 $(window).unload(function () { |
101 document.cookie = cookie_name + "=" + sort_list.toString() + "; path=/"; | 236 document.cookie = cookie_name + "=" + sort_list.toString() + "; path=/"; |
102 }); | 237 }); |
103 }; | 238 }; |
104 | 239 |
105 // -- pyfile stuff -- | 240 // -- pyfile stuff -- |
106 | 241 |
107 coverage.pyfile_ready = function ($) { | 242 coverage.pyfile_ready = function ($) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 coverage.is_transparent = function (color) { | 315 coverage.is_transparent = function (color) { |
181 // Different browsers return different colors for "none". | 316 // Different browsers return different colors for "none". |
182 return color === "transparent" || color === "rgba(0, 0, 0, 0)"; | 317 return color === "transparent" || color === "rgba(0, 0, 0, 0)"; |
183 }; | 318 }; |
184 | 319 |
185 coverage.to_next_chunk = function () { | 320 coverage.to_next_chunk = function () { |
186 var c = coverage; | 321 var c = coverage; |
187 | 322 |
188 // Find the start of the next colored chunk. | 323 // Find the start of the next colored chunk. |
189 var probe = c.sel_end; | 324 var probe = c.sel_end; |
| 325 var color, probe_line; |
190 while (true) { | 326 while (true) { |
191 var probe_line = c.line_elt(probe); | 327 probe_line = c.line_elt(probe); |
192 if (probe_line.length === 0) { | 328 if (probe_line.length === 0) { |
193 return; | 329 return; |
194 } | 330 } |
195 var color = probe_line.css("background-color"); | 331 color = probe_line.css("background-color"); |
196 if (!c.is_transparent(color)) { | 332 if (!c.is_transparent(color)) { |
197 break; | 333 break; |
198 } | 334 } |
199 probe++; | 335 probe++; |
200 } | 336 } |
201 | 337 |
202 // There's a next chunk, `probe` points to it. | 338 // There's a next chunk, `probe` points to it. |
203 var begin = probe; | 339 var begin = probe; |
204 | 340 |
205 // Find the end of this chunk. | 341 // Find the end of this chunk. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 } | 503 } |
368 }; | 504 }; |
369 | 505 |
370 coverage.scroll_window = function (to_pos) { | 506 coverage.scroll_window = function (to_pos) { |
371 $("html,body").animate({scrollTop: to_pos}, 200); | 507 $("html,body").animate({scrollTop: to_pos}, 200); |
372 }; | 508 }; |
373 | 509 |
374 coverage.finish_scrolling = function () { | 510 coverage.finish_scrolling = function () { |
375 $("html,body").stop(true, true); | 511 $("html,body").stop(true, true); |
376 }; | 512 }; |
OLD | NEW |