From 5f465276a1bfcee84490b321102ec7a383784416 Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Mon, 8 Jan 2018 15:29:22 +0100 Subject: [PATCH] =?UTF-8?q?window.history.pushState=20=E2=86=92=20replaceS?= =?UTF-8?q?tate.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No longer floods the history. --- CHANGELOG.txt | 1 + docs/releases/2.0.rst | 1 + .../admin/static_src/wagtailadmin/js/core.js | 23 ++++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 229e2a9e12..87a516a870 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -55,6 +55,7 @@ Changelog * Fix: Using RGBA images no longer crashes with Pillow >= 4.2.0 (Karl Hobley) * Fix: Copying a page with PostgreSQL search enabled no longer crashes (Bertrand Bordage) * Fix: Style of the page unlock button was broken (Bertrand Bordage) + * Fix: Admin search no longer floods browser history (Bertrand Bordage) 1.13.1 (17.11.2017) diff --git a/docs/releases/2.0.rst b/docs/releases/2.0.rst index eec7f1787e..40612a31b1 100644 --- a/docs/releases/2.0.rst +++ b/docs/releases/2.0.rst @@ -73,6 +73,7 @@ Bug fixes * Using RGBA images no longer crashes with Pillow >= 4.2.0 (Karl Hobley) * Copying a page with PostgreSQL search enabled no longer crashes (Bertrand Bordage) * Style of the page unlock button was broken (Bertrand Bordage) + * Admin search no longer floods browser history (Bertrand Bordage) Upgrade considerations diff --git a/wagtail/admin/static_src/wagtailadmin/js/core.js b/wagtail/admin/static_src/wagtailadmin/js/core.js index 4e9886460b..eef2672bf4 100644 --- a/wagtail/admin/static_src/wagtailadmin/js/core.js +++ b/wagtail/admin/static_src/wagtailadmin/js/core.js @@ -218,25 +218,26 @@ $(function() { if (window.headerSearch) { var searchCurrentIndex = 0; var searchNextIndex = 0; + var $input = $(window.headerSearch.termInput); + var $inputContainer = $input.parent(); - $(window.headerSearch.termInput).on('keyup cut paste change', function() { - clearTimeout($.data(this, 'timer')); - var wait = setTimeout(search, 200); - $(this).data('timer', wait); + $input.on('keyup cut paste change', function() { + clearTimeout($input.data('timer')); + $input.data('timer', setTimeout(search, 200)); }); // auto focus on search box - $(window.headerSearch.termInput).trigger('focus'); + $input.trigger('focus'); function search() { var workingClasses = 'icon-spinner'; - var newQuery = $(window.headerSearch.termInput).val(); + var newQuery = $input.val(); var currentQuery = getURLParam('q'); // only do the query if it has changed for trimmed queries // eg. " " === "" and "firstword " ==== "firstword" if (currentQuery.trim() !== newQuery.trim()) { - $(window.headerSearch.termInput).parent().addClass(workingClasses); + $inputContainer.addClass(workingClasses); searchNextIndex++; var index = searchNextIndex; $.ajax({ @@ -246,17 +247,17 @@ $(function() { if (index > searchCurrentIndex) { searchCurrentIndex = index; $(window.headerSearch.targetOutput).html(data).slideDown(800); - window.history.pushState(null, 'Search results', '?q=' + newQuery); + window.history.replaceState(null, null, '?q=' + newQuery); } }, complete: function() { - $(window.headerSearch.termInput).parent().removeClass(workingClasses); + $inputContainer.removeClass(workingClasses); } }); } - }; + } - getURLParam = function(name) { + function getURLParam(name) { var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.search); if (results) { return results[1];