Skip to content

Commit

Permalink
v 0.5.1
Browse files Browse the repository at this point in the history
Filter :
- Add a timeout to filter watch.
- Handle hashtag in URL.
  • Loading branch information
Darklg committed Sep 23, 2023
1 parent ac690bf commit 4e1c25b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
45 changes: 41 additions & 4 deletions assets/back.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions wpu_override_gettext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down

0 comments on commit 4e1c25b

Please sign in to comment.