1/* 2 * TypeWatch 3.0 3 * 4 * Original by Denny Ferrassoli 5 * Refactored by Charles Christolini 6 * Revised by Kai Schlamp 7 * 8 * Examples/Docs: www.dennydotnet.com 9 * 10 * Copyright(c) 2007 Denny Ferrassoli - DennyDotNet.com 11 * Copyright(c) 2008 Charles Christolini - BinaryPie.com 12 * Copyright(c) 2010 Kai Schlamp - medihack.org 13 * 14 * Dual licensed under the MIT and GPL licenses: 15 * http://www.opensource.org/licenses/mit-license.php 16 * http://www.gnu.org/licenses/gpl.html 17*/ 18 19(function(jQuery) { 20 jQuery.fn.typeWatch = function(o){ 21 // Options 22 var options = jQuery.extend({ 23 wait : 500, 24 callback : function() { }, 25 highlight : true, 26 captureLength : 2 27 }, o); 28 29 function checkElement(timer, override) { 30 var elTxt = jQuery(timer.el).val(); 31 32 if ((elTxt.length >= options.captureLength && elTxt.toUpperCase() != timer.text) 33 || (override && elTxt.length >= options.captureLength)) { 34 timer.text = elTxt.toUpperCase(); 35 timer.cb(elTxt); 36 } 37 } 38 39 function watchElement(elem) { 40 // Must be text or textarea 41 if (elem.type.toUpperCase() == "TEXT" || elem.nodeName.toUpperCase() == "TEXTAREA") { 42 43 // Allocate timer element 44 var timer = { 45 timer : null, 46 text : jQuery(elem).val().toUpperCase(), 47 cb : options.callback, 48 el : elem, 49 wait : options.wait 50 }; 51 52 // Set focus action (highlight) 53 if (options.highlight) { 54 jQuery(elem).focus( 55 function() { 56 this.select(); 57 }); 58 } 59 60 // Key watcher / clear and reset the timer 61 var startWatch = function(evt) { 62 var timerWait = timer.wait; 63 var overrideBool = false; 64 65 // If enter is pressed then diretly execute the callback 66 if (evt.keyCode == 13 && this.type.toUpperCase() == "TEXT") { 67 timerWait = 1; 68 overrideBool = true; 69 } 70 71 var timerCallbackFx = function() 72 { 73 checkElement(timer, overrideBool) 74 } 75 76 // Clear timer 77 clearTimeout(timer.timer); 78 timer.timer = setTimeout(timerCallbackFx, timerWait); 79 }; 80 81 jQuery(elem).keyup(startWatch); 82 } 83 } 84 85 // Watch Each Element 86 return this.each(function(index){ 87 watchElement(this); 88 }); 89 }; 90})(jQuery);
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.