wp/wp-includes/js/jquery/jquery.hotkeys.js
author ymh <ymh.work@gmail.com>
Wed, 21 Sep 2022 18:19:35 +0200
changeset 18 be944660c56a
parent 5 5e2f62d02dcd
permissions -rw-r--r--
Site enmi version 09/2022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
/******************************************************************************************************************************
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     3
 * @ Original idea by by Binny V A, Original version: 2.00.A
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 * @ http://www.openjs.com/scripts/events/keyboard_shortcuts/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @ Original License : BSD
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     6
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     7
 * @ jQuery Plugin by Tzury Bar Yochay
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
        mail: tzury.by@gmail.com
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
        blog: evalinux.wordpress.com
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
        face: facebook.com/profile.php?id=513676303
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
        (c) Copyrights 2007
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @ jQuery Plugin version Beta (0.0.2)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @ License: jQuery-License.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
TODO:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    add queue support (as in gmail) e.g. 'x' then 'y', etc.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    add mouse + mouse wheel events.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
USAGE:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    $.hotkeys.add('Ctrl+c', function(){ alert('copy anyone?');});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    $.hotkeys.add('Ctrl+c', {target:'div#editor', type:'keyup', propagate: true},function(){ alert('copy anyone?');});>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
    $.hotkeys.remove('Ctrl+c');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
    $.hotkeys.remove('Ctrl+c', {target:'div#editor', type:'keypress'});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
******************************************************************************************************************************/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
(function (jQuery){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    this.version = '(beta)(0.0.3)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	this.all = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    this.special_keys = {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
        27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll', 20: 'capslock',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
        144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',35:'end', 33: 'pageup',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
        34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down', 112:'f1',113:'f2', 114:'f3',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8', 120:'f9', 121:'f10', 122:'f11', 123:'f12'};
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
    this.shift_nums = { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
        "8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        ".":">",  "/":"?",  "\\":"|" };
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    this.add = function(combi, options, callback) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    42
        if ( typeof options === 'function' ){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
            callback = options;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
            options = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
        var opt = {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
            defaults = {type: 'keydown', propagate: false, disableInInput: false, target: jQuery('html')[0]},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
            that = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
        opt = jQuery.extend( opt , defaults, options || {} );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
        combi = combi.toLowerCase();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        // inspect if keystroke matches
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
        var inspector = function(event) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
            // WP: not needed with newer jQuery
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
            // event = jQuery.event.fix(event); // jQuery event normalization.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
            var element = event.target;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
            // @ TextNode -> nodeType == 3
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
            // WP: not needed with newer jQuery
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
            // element = (element.nodeType==3) ? element.parentNode : element;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
            if ( opt['disableInInput'] ) { // Disable shortcut keys in Input, Textarea fields
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
                var target = jQuery(element);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
				if ( ( target.is('input') || target.is('textarea') ) &&
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
					( ! opt.noDisable || ! target.is( opt.noDisable ) ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
					return;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
                }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
            }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
            var code = event.which,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
                type = event.type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
                character = String.fromCharCode(code).toLowerCase(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
                special = that.special_keys[code],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
                shift = event.shiftKey,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
                ctrl = event.ctrlKey,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
                alt= event.altKey,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
                meta = event.metaKey,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
                propagate = true, // default behaivour
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
                mapPoint = null;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
            // in opera + safari, the event.target is unpredictable.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
            // for example: 'keydown' might be associated with HtmlBodyElement
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
            // or the element where you last clicked with your mouse.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
            // WP: needed for all browsers
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
            // if (jQuery.browser.opera || jQuery.browser.safari){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
                while (!that.all[element] && element.parentNode){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
                    element = element.parentNode;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
                }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
            // }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
            var cbMap = that.all[element].events[type].callbackMap;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
            if(!shift && !ctrl && !alt && !meta) { // No Modifiers
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
                mapPoint = cbMap[special] ||  cbMap[character]
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
            // deals with combinaitons (alt|ctrl|shift+anything)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
            else{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
                var modif = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
                if(alt) modif +='alt+';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
                if(ctrl) modif+= 'ctrl+';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
                if(shift) modif += 'shift+';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
                if(meta) modif += 'meta+';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
                // modifiers + special keys or modifiers + characters or modifiers + shift characters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
                mapPoint = cbMap[modif+special] || cbMap[modif+character] || cbMap[modif+that.shift_nums[character]]
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
            }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
            if (mapPoint){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
                mapPoint.cb(event);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
                if(!mapPoint.propagate) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
                    event.stopPropagation();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
                    event.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
                    return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
                }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
            }
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
		};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
        // first hook for this element
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
        if (!this.all[opt.target]){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
            this.all[opt.target] = {events:{}};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
        }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
        if (!this.all[opt.target].events[opt.type]){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
            this.all[opt.target].events[opt.type] = {callbackMap: {}}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
            jQuery.event.add(opt.target, opt.type, inspector);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
        }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
        this.all[opt.target].events[opt.type].callbackMap[combi] =  {cb: callback, propagate:opt.propagate};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
        return jQuery;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
    this.remove = function(exp, opt) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
        opt = opt || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
        target = opt.target || jQuery('html')[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
        type = opt.type || 'keydown';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
		exp = exp.toLowerCase();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
        delete this.all[target].events[type].callbackMap[exp]
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
        return jQuery;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
    jQuery.hotkeys = this;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
    return jQuery;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
})(jQuery);