vendor: 2,947 bytes, lines 1-104
1/* 2* TypeWatch 3 3* 4* Examples/Docs: github.com/dennyferra/TypeWatch 5* 6* Dual licensed under the MIT and GPL licenses: 7* http://www.opensource.org/licenses/mit-license.php 8* http://www.gnu.org/licenses/gpl.html 9*/ 10 11!function(root, factory) { 12 if (typeof define === 'function' && define.amd) { 13 define(['jquery'], factory); 14 } else if (typeof exports === 'object') { 15 factory(require('jquery')); 16 } else { 17 factory(root.jQuery); 18 } 19}(this, function($) { 20 'use strict'; 21 $.fn.typeWatch = function(o) { 22 // The default input types that are supported 23 var _supportedInputTypes = 24 ['TEXT', 'TEXTAREA', 'PASSWORD', 'TEL', 'SEARCH', 'URL', 'EMAIL', 'DATETIME', 'DATE', 'MONTH', 'WEEK', 'TIME', 'DATETIME-LOCAL', 'NUMBER', 'RANGE', 'DIV']; 25 26 // Options 27 var options = $.extend({ 28 wait: 750, 29 callback: function() { }, 30 highlight: true, 31 captureLength: 2, 32 allowSubmit: false, 33 inputTypes: _supportedInputTypes 34 }, o); 35 36 function checkElement(timer, override) { 37 var value = timer.type === 'DIV' 38 ? jQuery(timer.el).html() 39 : jQuery(timer.el).val(); 40 41 // If has capture length and has changed value 42 // Or override and has capture length or allowSubmit option is true 43 // Or capture length is zero and changed value 44 if ((value.length >= options.captureLength && value != timer.text) 45 || (override && (value.length >= options.captureLength || options.allowSubmit)) 46 || (value.length == 0 && timer.text)) 47 { 48 timer.text = value; 49 timer.cb.call(timer.el, value); 50 } 51 }; 52 53 function watchElement(elem) { 54 var elementType = (elem.type || elem.nodeName).toUpperCase(); 55 if (jQuery.inArray(elementType, options.inputTypes) >= 0) { 56 57 // Allocate timer element 58 var timer = { 59 timer: null, 60 text: (elementType === 'DIV') ? jQuery(elem).html() : jQuery(elem).val(), 61 cb: options.callback, 62 el: elem, 63 type: elementType, 64 wait: options.wait 65 }; 66 67 // Set focus action (highlight) 68 if (options.highlight && elementType !== 'DIV') 69 jQuery(elem).focus(function() { this.select(); }); 70 71 // Key watcher / clear and reset the timer 72 var startWatch = function(evt) { 73 var timerWait = timer.wait; 74 var overrideBool = false; 75 var evtElementType = elementType; 76 77 // If enter key is pressed and not a TEXTAREA or DIV 78 if (typeof evt.keyCode != 'undefined' && evt.keyCode == 13 79 && evtElementType !== 'TEXTAREA' && elementType !== 'DIV') 80 { 81 console.log('OVERRIDE'); 82 timerWait = 1; 83 overrideBool = true; 84 } 85 86 var timerCallbackFx = function() { 87 checkElement(timer, overrideBool) 88 } 89 90 // Clear timer 91 clearTimeout(timer.timer); 92 timer.timer = setTimeout(timerCallbackFx, timerWait); 93 }; 94 95 jQuery(elem).on('keydown paste cut input', startWatch); 96 } 97 }; 98 99 // Watch each element 100 return this.each(function() { 101 watchElement(this); 102 }); 103 }; 104});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.