1(function (jQuery) { 2 var _ = require('underscore'); 3 4 /** 5 * 6 * A way to handle duplicate access keys in forms. So for instance using accesskey="s" does not submit a different form 7 * to the one you have focus in. 8 * 9 * @example 10 * jQuery("form").handleAccessKeys(); 11 * 12 * @function external:"jQuery.fn".handleAccessKeys 13 * @param {Boolean} options.selective - Remove all access keys or just the ones that exist elsewhere 14 */ 15 jQuery.fn.handleAccessKeys = function (options) { 16 var accessKeyAttr = "accesskey"; 17 if (jQuery.browser.msie && jQuery.browser.version == "7.0") { 18 accessKeyAttr = "accessKey"; 19 } 20 options = options || {}; 21 this.each(function () { 22 var $form = jQuery(this), 23 accesskeyElements = { 24 getBlackList: _.once(function getBlackList() { 25 var blacklist = []; 26 this.getMyAccesskeyElems().each(function () { 27 if (this.hasAttribute(accessKeyAttr)) { 28 blacklist.push(this.getAttribute(accessKeyAttr).toLowerCase()); 29 } 30 }); 31 return blacklist; 32 }), 33 getMyAccesskeyElems: _.once(function getMyAccesskeyElems() { 34 return jQuery(":input[" + accessKeyAttr + "], a[" + accessKeyAttr + "]", $form); 35 }), 36 getOtherAccesskeyElems: _.once(function getOtherAccesskeyElems() { 37 return jQuery("form").not($form).find(":input[" + accessKeyAttr + "], a[" + accessKeyAttr + "]"); 38 }) 39 }; 40 if (!$form.is("form")) { 41 console.warn("jQuery.fn.handleAccessKeys: node type [" + $form.prop("nodeName") + "] is not valid. " + "Only <form> supported"); 42 return this; 43 } 44 if ($form.data("handleAccessKeys.applied")) { 45 return; 46 } 47 $form.data("handleAccessKeys.applied", true); 48 $form.delegate(":input, a", "focus", function () { 49 removeAccessKeys(accesskeyElements.getOtherAccesskeyElems(), accesskeyElements.getBlackList()); 50 attachAccessKeys(accesskeyElements.getMyAccesskeyElems()); 51 }).delegate(":input, a", "blur", function () { 52 attachAccessKeys(accesskeyElements.getOtherAccesskeyElems()); 53 }); 54 }); 55 function isInvalid(key, blackList) { 56 if (key) { 57 if (options.selective === false) { 58 return true; 59 } 60 if (/[a-z]/i.test(key)) { 61 key = key.toLowerCase(); 62 } 63 return jQuery.inArray(key, blackList) !== -1; 64 } 65 } 66 function attachAccessKeys($accessKeyElems) { 67 $accessKeyElems.each(function () { 68 var $this = jQuery(this); 69 if ($this.data(accessKeyAttr)) { 70 $this.attr(accessKeyAttr, $this.data(accessKeyAttr)); 71 } 72 }); 73 } 74 function removeAccessKeys($accessKeyElems, blackList) { 75 $accessKeyElems.each(function () { 76 var $this = jQuery(this); 77 if (isInvalid($this.attr(accessKeyAttr), blackList)) { 78 $this.data(accessKeyAttr, $this.attr(accessKeyAttr)); 79 $this.removeAttr(accessKeyAttr); 80 } 81 }); 82 } 83 return this; 84 }; 85})(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.