From 4e1c25b1de13cb58a1cc7317860bc18c8a3feaae Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 23 Sep 2023 22:44:51 +0200 Subject: [PATCH] v 0.5.1 Filter : - Add a timeout to filter watch. - Handle hashtag in URL. --- assets/back.js | 45 ++++++++++++++++++++++++++++++++++++---- wpu_override_gettext.php | 4 ++-- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/assets/back.js b/assets/back.js index ea38974..70c3f46 100644 --- a/assets/back.js +++ b/assets/back.js @@ -5,19 +5,57 @@ document.addEventListener("DOMContentLoaded", function() { return; } var $table_lines = $table.querySelectorAll('tr[data-filter-text]'), - $filter = document.getElementById('wpu_override_gettext__filter_results'); + $filter = document.getElementById('wpu_override_gettext__filter_results'), + _current_filter = ''; + + /* ---------------------------------------------------------- + Init + ---------------------------------------------------------- */ + + check_current_hash(); + + window.addEventListener("hashchange", function(e) { + check_current_hash(); + }); + + function check_current_hash() { + var _hash = location.hash.split(':'); + if (!_hash[0] || !_hash[1] || _hash[0] != '#filter') { + return; + } + if (_hash[1] == _current_filter) { + return; + } + _hash[1] = decodeURI(_hash[1]); + filter_table(_hash[1]); + $filter.value = _hash[1]; + } + + /* ---------------------------------------------------------- + Filter + ---------------------------------------------------------- */ + + var _timeout_keyup; $filter.addEventListener('keyup', function() { - filter_table($filter.value); + clearTimeout(_timeout_keyup); + _timeout_keyup = setTimeout(function(){ + filter_table($filter.value); + },200); }, 1); function filter_table(filter_value) { + if (filter_value == _current_filter) { + return; + } if (!filter_value) { Array.prototype.forEach.call($table_lines, function(el) { el.setAttribute('data-visible', '1'); }); return; } - filter_value = filter_value.toLowerCase(); + filter_value = filter_value.toLowerCase().trim(); + _current_filter = filter_value; + location.hash = 'filter:' + filter_value; var value_words = filter_value.split(' '); Array.prototype.forEach.call($table_lines, function(el) { var _search_string = el.getAttribute('data-filter-text'); @@ -31,7 +69,6 @@ document.addEventListener("DOMContentLoaded", function() { } /* Hide if a part is not present */ if (_search_string.indexOf(value_words[i]) < 0) { - console.log(value_words[i]); el.setAttribute('data-visible', '0'); return; } diff --git a/wpu_override_gettext.php b/wpu_override_gettext.php index 398f1f8..20a2273 100644 --- a/wpu_override_gettext.php +++ b/wpu_override_gettext.php @@ -4,7 +4,7 @@ Plugin URI: https://github.com/WordPressUtilities/wpu_override_gettext Update URI: https://github.com/WordPressUtilities/wpu_override_gettext Description: Override gettext strings -Version: 0.5.0 +Version: 0.5.1 Author: darklg Author URI: https://darklg.me/ Text Domain: wpu_override_gettext @@ -18,7 +18,7 @@ class WPUOverrideGettext { public $plugin_description; public $adminpages; - private $plugin_version = '0.5.0'; + private $plugin_version = '0.5.1'; private $plugin_settings = array( 'id' => 'wpu_override_gettext', 'name' => 'WPU Override gettext'