From 85a957bb47f24a7b92dc5b63249458dec92f07e6 Mon Sep 17 00:00:00 2001 From: Philip Kirkbride Date: Tue, 7 Nov 2017 13:09:21 -0500 Subject: [PATCH 1/2] Record sort order in URL for auto-refreshing --- puppetboard/static/js/lists.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/puppetboard/static/js/lists.js b/puppetboard/static/js/lists.js index 9f8d4552..41eb4fdb 100644 --- a/puppetboard/static/js/lists.js +++ b/puppetboard/static/js/lists.js @@ -40,3 +40,26 @@ }); }).call(this); + +// Add function to easily get URL params +$.urlParam = function(name){ + var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); + if (results==null){ + return null; + } + else{ + return decodeURI(results[1]) || 0; + } +} + +// On startup if url param sort is set replace default sort +if($.urlParam('sort')) { + $('.default-sort').removeClass('default-sort'); + $("th:contains('"+$.urlParam('sort')+"')").addClass('default-sort'); +} + +// When a table header is clicked update the URL without refreshing page +$( "th" ).click(function() { + var newUrl = location.origin + location.pathname + "?sort=" + $(this).text(); + history.pushState({}, null, newUrl); +}); From aa891298971106d0eec5782e6d9a5020b90705a3 Mon Sep 17 00:00:00 2001 From: Philip Kirkbride Date: Tue, 7 Nov 2017 13:15:32 -0500 Subject: [PATCH 2/2] NIT: spacing and use " instead of ' --- puppetboard/static/js/lists.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/puppetboard/static/js/lists.js b/puppetboard/static/js/lists.js index 41eb4fdb..f80298ca 100644 --- a/puppetboard/static/js/lists.js +++ b/puppetboard/static/js/lists.js @@ -43,7 +43,7 @@ // Add function to easily get URL params $.urlParam = function(name){ - var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); + var results = new RegExp("[\?&]" + name + "=([^&#]*)").exec(window.location.href); if (results==null){ return null; } @@ -53,13 +53,13 @@ $.urlParam = function(name){ } // On startup if url param sort is set replace default sort -if($.urlParam('sort')) { - $('.default-sort').removeClass('default-sort'); - $("th:contains('"+$.urlParam('sort')+"')").addClass('default-sort'); +if($.urlParam("sort")) { + $(".default-sort").removeClass("default-sort"); + $("th:contains('"+$.urlParam("sort")+"')").addClass("default-sort"); } // When a table header is clicked update the URL without refreshing page -$( "th" ).click(function() { +$("th").click(function() { var newUrl = location.origin + location.pathname + "?sort=" + $(this).text(); history.pushState({}, null, newUrl); });