summaryrefslogtreecommitdiffstats
path: root/assets/js
diff options
context:
space:
mode:
authorAilin Nemui2015-11-27 13:29:37 +0100
committerAilin Nemui2015-11-28 13:08:48 +0100
commit2c3a506f9f91356decf4a27f5419e5916c72a1cc (patch)
tree67578f522cdb9edc2e3644a4b306658e98dceb3f /assets/js
parent15f2aee17b1f6d4613072e52a3d281395c936855 (diff)
downloadscripts.irssi.org-2c3a506f9f91356decf4a27f5419e5916c72a1cc.tar.bz2
add javascript filter box
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/filtertable.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/assets/js/filtertable.js b/assets/js/filtertable.js
new file mode 100644
index 0000000..ecee7ab
--- /dev/null
+++ b/assets/js/filtertable.js
@@ -0,0 +1,53 @@
+/*
+ LightTableFilter by Chris Coyier
+ http://codepen.io/chriscoyier/pen/tIuBL
+ */
+(function(document) {
+ 'use strict';
+
+ var LightTableFilter = (function(Arr) {
+
+ var _input;
+
+ function _onInputEvent(e) {
+ _input = e.target;
+ var tables = document.getElementsByClassName(_input.getAttribute('data-table'));
+ Arr.forEach.call(tables, function(table) {
+ Arr.forEach.call(table.tBodies, function(tbody) {
+ Arr.forEach.call(tbody.rows, _filter);
+ });
+ });
+ }
+
+ function _filterExpr(val, text) {
+ return !val.split(' ').every(function(word) {
+ if (word.charAt(0) === '-') {
+ return text.indexOf(word.substring(1)) === -1;
+ } else {
+ return text.indexOf(word) !== -1;
+ }
+ });
+ }
+
+ function _filter(row) {
+ var text = row.textContent.toLowerCase(), val = _input.value.toLowerCase();
+ row.style.display = _filterExpr(val, text) ? 'none' : 'table-row';
+ }
+
+ return {
+ init: function() {
+ var inputs = document.getElementsByClassName('light-table-filter');
+ Arr.forEach.call(inputs, function(input) {
+ input.oninput = _onInputEvent;
+ });
+ }
+ };
+ })(Array.prototype);
+
+ document.addEventListener('readystatechange', function() {
+ if (document.readyState === 'complete') {
+ LightTableFilter.init();
+ }
+ });
+
+})(document);