1// Restricts input for the set of matched elements to the given inputFilter function.
2(function($) {
3 $.fn.inputFilter = function(inputFilter) {
4 return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() {
5 if (inputFilter(this.value)) {
6 this.oldValue = this.value;
7 this.oldSelectionStart = this.selectionStart;
8 this.oldSelectionEnd = this.selectionEnd;
9 } else if (this.hasOwnProperty("oldValue")) {
10 this.value = this.oldValue;
11 this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
12 } else {
13 this.value = "";
14 }
15 });
16 };
17}(jQuery));
18