diff options
author | Federico Bond <federicobond@gmail.com> | 2018-08-08 11:45:14 -0300 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2018-08-30 18:42:34 -0400 |
commit | e60e9e0e6f3c2c74a4bae8d3ff10de070e350a98 (patch) | |
tree | 1aca5bd258dd6bb5afe63c7b52fcdd96788ddd32 /coverage/htmlfiles/coverage_html.js | |
parent | 17724b9930224f772f3d2a2ebdbf154f15014be1 (diff) | |
download | python-coveragepy-git-e60e9e0e6f3c2c74a4bae8d3ff10de070e350a98.tar.gz |
Persist html sort order in localStorage instead of cookie
Diffstat (limited to 'coverage/htmlfiles/coverage_html.js')
-rw-r--r-- | coverage/htmlfiles/coverage_html.js | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js index 7fc2963c..2b32c391 100644 --- a/coverage/htmlfiles/coverage_html.js +++ b/coverage/htmlfiles/coverage_html.js @@ -169,22 +169,13 @@ coverage.wire_up_filter = function () { // Loaded on index.html coverage.index_ready = function ($) { - // Look for a cookie containing previous sort settings: + // Look for a localStorage item containing previous sort settings: var sort_list = []; - var cookie_name = "COVERAGE_INDEX_SORT"; - var i; + var storage_name = "COVERAGE_INDEX_SORT"; + var stored_list = localStorage.getItem(storage_name); - // This almost makes it worth installing the jQuery cookie plugin: - if (document.cookie.indexOf(cookie_name) > -1) { - var cookies = document.cookie.split(";"); - for (i = 0; i < cookies.length; i++) { - var parts = cookies[i].split("="); - - if ($.trim(parts[0]) === cookie_name && parts[1]) { - sort_list = eval("[[" + parts[1] + "]]"); - break; - } - } + if (stored_list) { + sort_list = JSON.parse('[[' + stored_list + ']]'); } // Create a new widget which exists only to save and restore @@ -231,7 +222,7 @@ coverage.index_ready = function ($) { // Watch for page unload events so we can save the final sort settings: $(window).unload(function () { - document.cookie = cookie_name + "=" + sort_list.toString() + "; path=/"; + localStorage.setItem(storage_name, sort_list.toString()) }); }; |