From 51022e79bd65cccc8f5757803cdce4ededfebcc9 Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Wed, 30 Nov 2022 12:52:46 +0100 Subject: [PATCH 1/3] made url not contain part id when part view closed --- parts/static/script.js | 16 +++++++++++++--- parts/templates/partsearch.html | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/parts/static/script.js b/parts/static/script.js index b32f549..64eaa02 100755 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -215,8 +215,19 @@ function show_part_info(partID) { }); // update URL and history + update_url(partID); +} + +function update_url(partID){ + params = {} var query = $('.search-bar').val(); - window.history.pushState('searching', '', 'parts?q=' + query + '&p=' + partID) + if(len(query)>0){ + params['q'] = query + } + if(partID != 0){ + params['p'] = partID + } + window.history.pushState('searching', '', 'parts?' + jQuery.param(params)); } function perform_query() { @@ -250,8 +261,7 @@ function perform_query() { console.log( "Query failed" ); }); - // update URL and history - window.history.pushState('searching', '', 'parts?q=' + query) + update_url(0); } function container_onchange() { diff --git a/parts/templates/partsearch.html b/parts/templates/partsearch.html index 30f087c..12f0a05 100755 --- a/parts/templates/partsearch.html +++ b/parts/templates/partsearch.html @@ -37,7 +37,7 @@

No results.

-
+

Part Details

@@ -73,7 +73,7 @@
-
+
-- 2.39.5 From 807c1361431c93858ec39a0f487f3ec4a57d5c40 Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Wed, 30 Nov 2022 13:01:47 +0100 Subject: [PATCH 2/3] fixed previous commit by writing javascript not in python --- parts/static/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parts/static/script.js b/parts/static/script.js index 64eaa02..267e7fb 100755 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -220,9 +220,9 @@ function show_part_info(partID) { function update_url(partID){ params = {} - var query = $('.search-bar').val(); - if(len(query)>0){ - params['q'] = query + // If there is a seach bar, take its content + if($('.search-bar').length){ + params['q'] = $('.search-bar').val(); } if(partID != 0){ params['p'] = partID -- 2.39.5 From 6998c7eff24e105ceeb3f5b468932a9a8c8f0be7 Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Wed, 30 Nov 2022 13:05:15 +0100 Subject: [PATCH 3/3] clicking away the overlay by clicking outside of it also works with url --- parts/templates/partsearch.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parts/templates/partsearch.html b/parts/templates/partsearch.html index 12f0a05..41f55c3 100755 --- a/parts/templates/partsearch.html +++ b/parts/templates/partsearch.html @@ -37,7 +37,7 @@

No results.

-
+

Part Details

-- 2.39.5