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