1/* 2 * Capslock 0.2 - jQuery plugin to detect if a user's caps lock is on or not. 3 * 4 * Provides events, "caps_lock_on" and "caps_lock_off", that custom functions can be bound to. 5 * The capslock function can be called on a specific element, a set of elements, or globally: 6 * $("#my_textarea").capslock(options); // One textarea 7 * $("textarea").capslock(options); // All textareas 8 * $().capslock(options); // Globally 9 * 10 * Copyright (c) 2009 Arthur McLean 11 * 12 * Dual licensed under the MIT and GPL licenses: 13 * http://www.opensource.org/licenses/mit-license.php 14 * http://www.gnu.org/licenses/gpl.html 15 * 16 */ 17 18; // Just in case the previously included plug-in failed to close with a semi-colon. 19(function($) { 20 21 $.fn.capslock = function(options) { 22 23 if (options) $.extend($.fn.capslock.defaults, options); 24 25 this.each(function() { 26 $(this).bind("caps_lock_on", $.fn.capslock.defaults.caps_lock_on); 27 $(this).bind("caps_lock_off", $.fn.capslock.defaults.caps_lock_off); 28 29 $(this).keypress(function(e){ 30 check_caps_lock(e); 31 }); 32 }); 33 34 return this; 35 }; 36 37 38 39 // The actual check: 40 function check_caps_lock(e) 41 { 42 var ascii_code = e.which; 43 var shift_key = e.shiftKey; 44 if( (65 <= ascii_code) && (ascii_code <= 90) && !shift_key) 45 { 46 $(e.target).trigger("caps_lock_on"); 47 } 48 else 49 { 50 $(e.target).trigger("caps_lock_off"); 51 } 52 53 } 54 55 // Public definition of defaults for easy overriding: 56 $.fn.capslock.defaults = { 57 caps_lock_on: function() {}, 58 caps_lock_off: function() {} 59 }; 60 61})(jQuery); 62
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.