Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

jquery.key.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*!
  2. * jquery.key.js 0.2 - https://github.com/yckart/jquery.key.js
  3. * The certainly simpliest shortcut key event handler ever
  4. *
  5. * Copyright (c) 2013 Yannick Albert (http://yckart.com)
  6. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
  7. * 2013/02/09
  8. */
  9. ;(function ($, document) {
  10. var keys = {a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,"0":48,"1":49,"2":50,"3":51,"4":52,"5":53,"6":54,"7":55,"8":56,"9":57,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,shift:16,ctrl:17,control:17,alt:18,option:18,opt:18,cmd:224,command:224,fn:255,"function":255,backspace:8,osxdelete:8,enter:13,"return":13,space:32,spacebar:32,esc:27,escape:27,tab:9,capslock:20,capslk:20,"super":91,windows:91,insert:45,"delete":46,home:36,end:35,pgup:33,pageup:33,pgdn:34,pagedown:34,left:37,up:38,right:39,down:40,"!":49,"@":50,"#":51,"$":52,"%":53,"^":54,"&":55,"*":56,"(":57,")":48,"`":96,"~":96,"-":45,_:45,"=":187,"+":187,"[":219,"{":219,"]":221,"}":221,"\\":220,"|":220,";":59,":":59,"'":222,'"':222,",":188,"<":188,".":190,">":190,"/":191,"?":191};
  11. $.key = $.fn.key = function (code, fn) {
  12. if (!(this instanceof $)) { return $.fn.key.apply($(document), arguments); }
  13. var i = 0,
  14. cache = [];
  15. return this.on({
  16. keydown: function (e) {
  17. var key = e.which;
  18. if (cache[cache.length - 1] === key) return;
  19. cache.push(key);
  20. i = key === code[i] || ( typeof code === 'string' && key === keys[code.split("+")[i]] ) ? i + 1 : 0;
  21. if ( i === code.length || ( typeof code === 'string' && code.split('+').length === i ) ) {
  22. fn(e, cache);
  23. i = 0;
  24. }
  25. },
  26. keyup: function () {
  27. i = 0;
  28. cache = [];
  29. }
  30. });
  31. };
  32. })(jQuery, document);