Created
March 28, 2017 21:41
-
-
Save rebekahmonson/80c3f32d9b3d04bc038a2d5f77aad467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 _filter(row) { | |
var text = row.textContent.toLowerCase(), | |
val = _input.value.toLowerCase(); | |
row.style.display = text.indexOf(val) === -1 ? '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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment