diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-25 09:51:51 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-25 09:51:51 -0500 |
commit | 0ecc4917ff57918eefb7a90e163fd4bfa9b923d4 (patch) | |
tree | bcf7c78fdc4ff6fdacb5de7260cbdb95f3896406 /coverage/htmlfiles | |
parent | 19cf94d2af6f79cb5995f124bce3fe213823dac0 (diff) | |
download | python-coveragepy-git-0ecc4917ff57918eefb7a90e163fd4bfa9b923d4.tar.gz |
Move the javascript code for click-to-sort columns into its own file. It helps keep the HTML tests from changing when the code changes. Also, don't compare non-HTML files in the tests.
Diffstat (limited to 'coverage/htmlfiles')
-rw-r--r-- | coverage/htmlfiles/coverage_html.js | 64 | ||||
-rw-r--r-- | coverage/htmlfiles/index.html | 68 |
2 files changed, 68 insertions, 64 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js new file mode 100644 index 00000000..c0abab81 --- /dev/null +++ b/coverage/htmlfiles/coverage_html.js @@ -0,0 +1,64 @@ +// Coverage.py HTML report browser code. + +// Loaded on index.html +function index_page_ready($) { + // Look for a cookie containing previous sort settings: + sort_list = []; + cookie_name = "COVERAGE_INDEX_SORT"; + + // This almost makes it worth installing the jQuery cookie plugin: + if (document.cookie.indexOf(cookie_name) > -1) { + cookies = document.cookie.split(";"); + for (var i=0; i < cookies.length; i++) { + parts = cookies[i].split("=") + + if ($.trim(parts[0]) == cookie_name && parts[1]) { + sort_list = eval("[[" + parts[1] + "]]"); + break; + } + } + } + + // Create a new widget which exists only to save and restore + // the sort order: + $.tablesorter.addWidget({ + id: "persistentSort", + + // Format is called by the widget before displaying: + format: function(table) { + if (table.config.sortList.length == 0 && sort_list.length > 0) { + // This table hasn't been sorted before - we'll use + // our stored settings: + jQuery(table).trigger('sorton', [sort_list]); + } + else { + // This is not the first load - something has + // already defined sorting so we'll just update + // our stored value to match: + sort_list = table.config.sortList; + } + } + }); + + // Configure our tablesorter to handle the variable number of + // columns produced depending on report options: + var headers = {}; + var col_count = jQuery("table.index > thead > tr > th").length; + + headers[0] = { sorter: 'text' }; + for (var i = 1; i < col_count-1; i++) { + headers[i] = { sorter: 'digit' }; + } + headers[col_count-1] = { sorter: 'percent' }; + + // Enable the table sorter: + $("table.index").tablesorter({ + widgets: ['persistentSort'], + headers: headers + }); + + // Watch for page unload events so we can save the final sort settings: + $(window).unload(function() { + document.cookie = cookie_name + "=" + sort_list.toString() + "; path=/" + }); +} diff --git a/coverage/htmlfiles/index.html b/coverage/htmlfiles/index.html index 4443349a..0f387644 100644 --- a/coverage/htmlfiles/index.html +++ b/coverage/htmlfiles/index.html @@ -6,6 +6,10 @@ <link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='jquery.tablesorter.min.js'></script>
+ <script type='text/javascript' src='coverage_html.js'></script>
+ <script type="text/javascript" charset="utf-8">
+ jQuery(document).ready(index_page_ready);
+ </script>
</head>
<body>
@@ -72,69 +76,5 @@ </p>
</div>
</div>
-
- <script type="text/javascript" charset="utf-8">
- jQuery(function($) {
- // Look for a cookie containing previous sort settings:
- sort_list = [];
- cookie_name = "COVERAGE_INDEX_SORT";
-
- // This almost makes it worth installing the jQuery cookie plugin:
- if (document.cookie.indexOf(cookie_name) > -1) {
- cookies = document.cookie.split(";");
- for (var i=0; i < cookies.length; i++) {
- parts = cookies[i].split("=")
-
- if ($.trim(parts[0]) == cookie_name && parts[1]) {
- sort_list = eval("[[" + parts[1] + "]]");
- break;
- }
- }
- }
-
- // Create a new widget which exists only to save and restore
- // the sort order:
- $.tablesorter.addWidget({
- id: "persistentSort",
-
- // Format is called by the widget before displaying:
- format: function(table) {
- if (table.config.sortList.length == 0 && sort_list.length > 0) {
- // This table hasn't been sorted before - we'll use
- // our stored settings:
- jQuery(table).trigger('sorton', [sort_list]);
- }
- else {
- // This is not the first load - something has
- // already defined sorting so we'll just update
- // our stored value to match:
- sort_list = table.config.sortList;
- }
- }
- });
-
- // Configure our tablesorter to handle the variable number of
- // columns produced depending on report options:
- var headers = {};
- var col_count = jQuery("table.index > thead > tr > th").length;
-
- headers[0] = { sorter: 'text' };
- for (var i = 1; i < col_count-1; i++) {
- headers[i] = { sorter: 'digit' };
- }
- headers[col_count-1] = { sorter:'percent' };
-
- // Enable the table sorter:
- $("table.index").tablesorter({
- widgets: ['persistentSort'],
- headers: headers
- });
-
- // Watch for page unload events so we can save the final sort settings:
- $(window).unload(function() {
- document.cookie = cookie_name + "=" + sort_list.toString() + "; path=/"
- });
- });
- </script>
</body>
</html>
|