mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
223 lines
36 KiB
HTML
223 lines
36 KiB
HTML
<!DOCTYPE html><html lang="en"><head><title>shortcuts</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="shortcuts"><meta name="groc-project-path" content="core/admin/assets/js/shortcuts.js"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><script type="text/javascript" src="assets/behavior.js"></script><body><div id="meta"><div class="file-path">core/admin/assets/js/shortcuts.js</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="cm">/**</span>
|
|
<span class="cm"> * http://www.openjs.com/scripts/events/keyboard_shortcuts/</span>
|
|
<span class="cm"> * Version : 2.01.B</span>
|
|
<span class="cm"> * By Binny V A</span>
|
|
<span class="cm"> * License : BSD</span>
|
|
<span class="cm"> */</span>
|
|
<span class="nx">shortcut</span> <span class="o">=</span> <span class="p">{</span>
|
|
<span class="s1">'all_shortcuts'</span><span class="o">:</span><span class="p">{},</span><span class="c1">//All the shortcuts are stored in this array</span>
|
|
<span class="s1">'add'</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">shortcut_combination</span><span class="p">,</span><span class="nx">callback</span><span class="p">,</span><span class="nx">opt</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="c1">//Provide a set of default options</span>
|
|
<span class="kd">var</span> <span class="nx">default_options</span> <span class="o">=</span> <span class="p">{</span>
|
|
<span class="s1">'type'</span><span class="o">:</span><span class="s1">'keydown'</span><span class="p">,</span>
|
|
<span class="s1">'propagate'</span><span class="o">:</span><span class="kc">false</span><span class="p">,</span>
|
|
<span class="s1">'disable_in_input'</span><span class="o">:</span><span class="kc">false</span><span class="p">,</span>
|
|
<span class="s1">'target'</span><span class="o">:</span><span class="nb">document</span><span class="p">,</span>
|
|
<span class="s1">'keycode'</span><span class="o">:</span><span class="kc">false</span>
|
|
<span class="p">}</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">opt</span><span class="p">)</span> <span class="nx">opt</span> <span class="o">=</span> <span class="nx">default_options</span><span class="p">;</span>
|
|
<span class="k">else</span> <span class="p">{</span>
|
|
<span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">dfo</span> <span class="k">in</span> <span class="nx">default_options</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="k">typeof</span> <span class="nx">opt</span><span class="p">[</span><span class="nx">dfo</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'undefined'</span><span class="p">)</span> <span class="nx">opt</span><span class="p">[</span><span class="nx">dfo</span><span class="p">]</span> <span class="o">=</span> <span class="nx">default_options</span><span class="p">[</span><span class="nx">dfo</span><span class="p">];</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="kd">var</span> <span class="nx">ele</span> <span class="o">=</span> <span class="nx">opt</span><span class="p">.</span><span class="nx">target</span><span class="p">;</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="k">typeof</span> <span class="nx">opt</span><span class="p">.</span><span class="nx">target</span> <span class="o">==</span> <span class="s1">'string'</span><span class="p">)</span> <span class="nx">ele</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="nx">opt</span><span class="p">.</span><span class="nx">target</span><span class="p">);</span>
|
|
<span class="kd">var</span> <span class="nx">ths</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
|
|
<span class="nx">shortcut_combination</span> <span class="o">=</span> <span class="nx">shortcut_combination</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">();</span>
|
|
|
|
<span class="c1">//The function to be called at keypress</span>
|
|
<span class="kd">var</span> <span class="nx">func</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">e</span> <span class="o">=</span> <span class="nx">e</span> <span class="o">||</span> <span class="nb">window</span><span class="p">.</span><span class="nx">event</span><span class="p">;</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">opt</span><span class="p">[</span><span class="s1">'disable_in_input'</span><span class="p">])</span> <span class="p">{</span> <span class="c1">//Don't enable shortcut keys in Input, Textarea fields</span>
|
|
<span class="kd">var</span> <span class="nx">element</span><span class="p">;</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">)</span> <span class="nx">element</span><span class="o">=</span><span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">;</span>
|
|
<span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">srcElement</span><span class="p">)</span> <span class="nx">element</span><span class="o">=</span><span class="nx">e</span><span class="p">.</span><span class="nx">srcElement</span><span class="p">;</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">element</span><span class="p">.</span><span class="nx">nodeType</span><span class="o">==</span><span class="mi">3</span><span class="p">)</span> <span class="nx">element</span><span class="o">=</span><span class="nx">element</span><span class="p">.</span><span class="nx">parentNode</span><span class="p">;</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">element</span><span class="p">.</span><span class="nx">tagName</span> <span class="o">==</span> <span class="s1">'INPUT'</span> <span class="o">||</span> <span class="nx">element</span><span class="p">.</span><span class="nx">tagName</span> <span class="o">==</span> <span class="s1">'TEXTAREA'</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="c1">//Find Which key is pressed</span>
|
|
<span class="k">if</span> <span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">keyCode</span><span class="p">)</span> <span class="nx">code</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">keyCode</span><span class="p">;</span>
|
|
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">which</span><span class="p">)</span> <span class="nx">code</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">which</span><span class="p">;</span>
|
|
<span class="kd">var</span> <span class="nx">character</span> <span class="o">=</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">).</span><span class="nx">toLowerCase</span><span class="p">();</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">code</span> <span class="o">==</span> <span class="mi">188</span><span class="p">)</span> <span class="nx">character</span><span class="o">=</span><span class="s2">","</span><span class="p">;</span> <span class="c1">//If the user presses , when the type is onkeydown</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">code</span> <span class="o">==</span> <span class="mi">190</span><span class="p">)</span> <span class="nx">character</span><span class="o">=</span><span class="s2">"."</span><span class="p">;</span> <span class="c1">//If the user presses , when the type is onkeydown</span>
|
|
|
|
<span class="kd">var</span> <span class="nx">keys</span> <span class="o">=</span> <span class="nx">shortcut_combination</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"+"</span><span class="p">);</span>
|
|
<span class="c1">//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked</span>
|
|
<span class="kd">var</span> <span class="nx">kp</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
|
|
|
<span class="c1">//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken</span>
|
|
<span class="kd">var</span> <span class="nx">shift_nums</span> <span class="o">=</span> <span class="p">{</span>
|
|
<span class="s2">"`"</span><span class="o">:</span><span class="s2">"~"</span><span class="p">,</span>
|
|
<span class="s2">"1"</span><span class="o">:</span><span class="s2">"!"</span><span class="p">,</span>
|
|
<span class="s2">"2"</span><span class="o">:</span><span class="s2">"@"</span><span class="p">,</span>
|
|
<span class="s2">"3"</span><span class="o">:</span><span class="s2">"#"</span><span class="p">,</span>
|
|
<span class="s2">"4"</span><span class="o">:</span><span class="s2">"$"</span><span class="p">,</span>
|
|
<span class="s2">"5"</span><span class="o">:</span><span class="s2">"%"</span><span class="p">,</span>
|
|
<span class="s2">"6"</span><span class="o">:</span><span class="s2">"^"</span><span class="p">,</span>
|
|
<span class="s2">"7"</span><span class="o">:</span><span class="s2">"&"</span><span class="p">,</span>
|
|
<span class="s2">"8"</span><span class="o">:</span><span class="s2">"*"</span><span class="p">,</span>
|
|
<span class="s2">"9"</span><span class="o">:</span><span class="s2">"("</span><span class="p">,</span>
|
|
<span class="s2">"0"</span><span class="o">:</span><span class="s2">")"</span><span class="p">,</span>
|
|
<span class="s2">"-"</span><span class="o">:</span><span class="s2">"_"</span><span class="p">,</span>
|
|
<span class="s2">"="</span><span class="o">:</span><span class="s2">"+"</span><span class="p">,</span>
|
|
<span class="s2">";"</span><span class="o">:</span><span class="s2">":"</span><span class="p">,</span>
|
|
<span class="s2">"'"</span><span class="o">:</span><span class="s2">"\""</span><span class="p">,</span>
|
|
<span class="s2">","</span><span class="o">:</span><span class="s2">"<"</span><span class="p">,</span>
|
|
<span class="s2">"."</span><span class="o">:</span><span class="s2">">"</span><span class="p">,</span>
|
|
<span class="s2">"/"</span><span class="o">:</span><span class="s2">"?"</span><span class="p">,</span>
|
|
<span class="s2">"\\"</span><span class="o">:</span><span class="s2">"|"</span>
|
|
<span class="p">}</span>
|
|
<span class="c1">//Special Keys - and their codes</span>
|
|
<span class="kd">var</span> <span class="nx">special_keys</span> <span class="o">=</span> <span class="p">{</span>
|
|
<span class="s1">'esc'</span><span class="o">:</span><span class="mi">27</span><span class="p">,</span>
|
|
<span class="s1">'escape'</span><span class="o">:</span><span class="mi">27</span><span class="p">,</span>
|
|
<span class="s1">'tab'</span><span class="o">:</span><span class="mi">9</span><span class="p">,</span>
|
|
<span class="s1">'space'</span><span class="o">:</span><span class="mi">32</span><span class="p">,</span>
|
|
<span class="s1">'return'</span><span class="o">:</span><span class="mi">13</span><span class="p">,</span>
|
|
<span class="s1">'enter'</span><span class="o">:</span><span class="mi">13</span><span class="p">,</span>
|
|
<span class="s1">'backspace'</span><span class="o">:</span><span class="mi">8</span><span class="p">,</span>
|
|
|
|
<span class="s1">'scrolllock'</span><span class="o">:</span><span class="mi">145</span><span class="p">,</span>
|
|
<span class="s1">'scroll_lock'</span><span class="o">:</span><span class="mi">145</span><span class="p">,</span>
|
|
<span class="s1">'scroll'</span><span class="o">:</span><span class="mi">145</span><span class="p">,</span>
|
|
<span class="s1">'capslock'</span><span class="o">:</span><span class="mi">20</span><span class="p">,</span>
|
|
<span class="s1">'caps_lock'</span><span class="o">:</span><span class="mi">20</span><span class="p">,</span>
|
|
<span class="s1">'caps'</span><span class="o">:</span><span class="mi">20</span><span class="p">,</span>
|
|
<span class="s1">'numlock'</span><span class="o">:</span><span class="mi">144</span><span class="p">,</span>
|
|
<span class="s1">'num_lock'</span><span class="o">:</span><span class="mi">144</span><span class="p">,</span>
|
|
<span class="s1">'num'</span><span class="o">:</span><span class="mi">144</span><span class="p">,</span>
|
|
|
|
<span class="s1">'pause'</span><span class="o">:</span><span class="mi">19</span><span class="p">,</span>
|
|
<span class="s1">'break'</span><span class="o">:</span><span class="mi">19</span><span class="p">,</span>
|
|
|
|
<span class="s1">'insert'</span><span class="o">:</span><span class="mi">45</span><span class="p">,</span>
|
|
<span class="s1">'home'</span><span class="o">:</span><span class="mi">36</span><span class="p">,</span>
|
|
<span class="s1">'delete'</span><span class="o">:</span><span class="mi">46</span><span class="p">,</span>
|
|
<span class="s1">'end'</span><span class="o">:</span><span class="mi">35</span><span class="p">,</span>
|
|
|
|
<span class="s1">'pageup'</span><span class="o">:</span><span class="mi">33</span><span class="p">,</span>
|
|
<span class="s1">'page_up'</span><span class="o">:</span><span class="mi">33</span><span class="p">,</span>
|
|
<span class="s1">'pu'</span><span class="o">:</span><span class="mi">33</span><span class="p">,</span>
|
|
|
|
<span class="s1">'pagedown'</span><span class="o">:</span><span class="mi">34</span><span class="p">,</span>
|
|
<span class="s1">'page_down'</span><span class="o">:</span><span class="mi">34</span><span class="p">,</span>
|
|
<span class="s1">'pd'</span><span class="o">:</span><span class="mi">34</span><span class="p">,</span>
|
|
|
|
<span class="s1">'left'</span><span class="o">:</span><span class="mi">37</span><span class="p">,</span>
|
|
<span class="s1">'up'</span><span class="o">:</span><span class="mi">38</span><span class="p">,</span>
|
|
<span class="s1">'right'</span><span class="o">:</span><span class="mi">39</span><span class="p">,</span>
|
|
<span class="s1">'down'</span><span class="o">:</span><span class="mi">40</span><span class="p">,</span>
|
|
|
|
<span class="s1">'f1'</span><span class="o">:</span><span class="mi">112</span><span class="p">,</span>
|
|
<span class="s1">'f2'</span><span class="o">:</span><span class="mi">113</span><span class="p">,</span>
|
|
<span class="s1">'f3'</span><span class="o">:</span><span class="mi">114</span><span class="p">,</span>
|
|
<span class="s1">'f4'</span><span class="o">:</span><span class="mi">115</span><span class="p">,</span>
|
|
<span class="s1">'f5'</span><span class="o">:</span><span class="mi">116</span><span class="p">,</span>
|
|
<span class="s1">'f6'</span><span class="o">:</span><span class="mi">117</span><span class="p">,</span>
|
|
<span class="s1">'f7'</span><span class="o">:</span><span class="mi">118</span><span class="p">,</span>
|
|
<span class="s1">'f8'</span><span class="o">:</span><span class="mi">119</span><span class="p">,</span>
|
|
<span class="s1">'f9'</span><span class="o">:</span><span class="mi">120</span><span class="p">,</span>
|
|
<span class="s1">'f10'</span><span class="o">:</span><span class="mi">121</span><span class="p">,</span>
|
|
<span class="s1">'f11'</span><span class="o">:</span><span class="mi">122</span><span class="p">,</span>
|
|
<span class="s1">'f12'</span><span class="o">:</span><span class="mi">123</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="kd">var</span> <span class="nx">modifiers</span> <span class="o">=</span> <span class="p">{</span>
|
|
<span class="nx">shift</span><span class="o">:</span> <span class="p">{</span> <span class="nx">wanted</span><span class="o">:</span><span class="kc">false</span><span class="p">,</span> <span class="nx">pressed</span><span class="o">:</span><span class="kc">false</span><span class="p">},</span>
|
|
<span class="nx">ctrl</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">wanted</span><span class="o">:</span><span class="kc">false</span><span class="p">,</span> <span class="nx">pressed</span><span class="o">:</span><span class="kc">false</span><span class="p">},</span>
|
|
<span class="nx">alt</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">wanted</span><span class="o">:</span><span class="kc">false</span><span class="p">,</span> <span class="nx">pressed</span><span class="o">:</span><span class="kc">false</span><span class="p">},</span>
|
|
<span class="nx">meta</span> <span class="o">:</span> <span class="p">{</span> <span class="nx">wanted</span><span class="o">:</span><span class="kc">false</span><span class="p">,</span> <span class="nx">pressed</span><span class="o">:</span><span class="kc">false</span><span class="p">}</span> <span class="c1">//Meta is Mac specific</span>
|
|
<span class="p">};</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">ctrlKey</span><span class="p">)</span> <span class="nx">modifiers</span><span class="p">.</span><span class="nx">ctrl</span><span class="p">.</span><span class="nx">pressed</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">shiftKey</span><span class="p">)</span> <span class="nx">modifiers</span><span class="p">.</span><span class="nx">shift</span><span class="p">.</span><span class="nx">pressed</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">altKey</span><span class="p">)</span> <span class="nx">modifiers</span><span class="p">.</span><span class="nx">alt</span><span class="p">.</span><span class="nx">pressed</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">metaKey</span><span class="p">)</span> <span class="nx">modifiers</span><span class="p">.</span><span class="nx">meta</span><span class="p">.</span><span class="nx">pressed</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
|
|
<span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="nx">k</span><span class="o">=</span><span class="nx">keys</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span><span class="nx">i</span><span class="o"><</span><span class="nx">keys</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="c1">//Modifiers</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">k</span> <span class="o">==</span> <span class="s1">'ctrl'</span> <span class="o">||</span> <span class="nx">k</span> <span class="o">==</span> <span class="s1">'control'</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">kp</span><span class="o">++</span><span class="p">;</span>
|
|
<span class="nx">modifiers</span><span class="p">.</span><span class="nx">ctrl</span><span class="p">.</span><span class="nx">wanted</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
|
|
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">k</span> <span class="o">==</span> <span class="s1">'shift'</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">kp</span><span class="o">++</span><span class="p">;</span>
|
|
<span class="nx">modifiers</span><span class="p">.</span><span class="nx">shift</span><span class="p">.</span><span class="nx">wanted</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
|
|
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">k</span> <span class="o">==</span> <span class="s1">'alt'</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">kp</span><span class="o">++</span><span class="p">;</span>
|
|
<span class="nx">modifiers</span><span class="p">.</span><span class="nx">alt</span><span class="p">.</span><span class="nx">wanted</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">k</span> <span class="o">==</span> <span class="s1">'meta'</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">kp</span><span class="o">++</span><span class="p">;</span>
|
|
<span class="nx">modifiers</span><span class="p">.</span><span class="nx">meta</span><span class="p">.</span><span class="nx">wanted</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">k</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//If it is a special key</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">special_keys</span><span class="p">[</span><span class="nx">k</span><span class="p">]</span> <span class="o">==</span> <span class="nx">code</span><span class="p">)</span> <span class="nx">kp</span><span class="o">++</span><span class="p">;</span>
|
|
|
|
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">opt</span><span class="p">[</span><span class="s1">'keycode'</span><span class="p">])</span> <span class="p">{</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">opt</span><span class="p">[</span><span class="s1">'keycode'</span><span class="p">]</span> <span class="o">==</span> <span class="nx">code</span><span class="p">)</span> <span class="nx">kp</span><span class="o">++</span><span class="p">;</span>
|
|
|
|
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//The special keys did not match</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">character</span> <span class="o">==</span> <span class="nx">k</span><span class="p">)</span> <span class="nx">kp</span><span class="o">++</span><span class="p">;</span>
|
|
<span class="k">else</span> <span class="p">{</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">shift_nums</span><span class="p">[</span><span class="nx">character</span><span class="p">]</span> <span class="o">&&</span> <span class="nx">e</span><span class="p">.</span><span class="nx">shiftKey</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//Stupid Shift key bug created by using lowercase</span>
|
|
<span class="nx">character</span> <span class="o">=</span> <span class="nx">shift_nums</span><span class="p">[</span><span class="nx">character</span><span class="p">];</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">character</span> <span class="o">==</span> <span class="nx">k</span><span class="p">)</span> <span class="nx">kp</span><span class="o">++</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">kp</span> <span class="o">==</span> <span class="nx">keys</span><span class="p">.</span><span class="nx">length</span> <span class="o">&&</span>
|
|
<span class="nx">modifiers</span><span class="p">.</span><span class="nx">ctrl</span><span class="p">.</span><span class="nx">pressed</span> <span class="o">==</span> <span class="nx">modifiers</span><span class="p">.</span><span class="nx">ctrl</span><span class="p">.</span><span class="nx">wanted</span> <span class="o">&&</span>
|
|
<span class="nx">modifiers</span><span class="p">.</span><span class="nx">shift</span><span class="p">.</span><span class="nx">pressed</span> <span class="o">==</span> <span class="nx">modifiers</span><span class="p">.</span><span class="nx">shift</span><span class="p">.</span><span class="nx">wanted</span> <span class="o">&&</span>
|
|
<span class="nx">modifiers</span><span class="p">.</span><span class="nx">alt</span><span class="p">.</span><span class="nx">pressed</span> <span class="o">==</span> <span class="nx">modifiers</span><span class="p">.</span><span class="nx">alt</span><span class="p">.</span><span class="nx">wanted</span> <span class="o">&&</span>
|
|
<span class="nx">modifiers</span><span class="p">.</span><span class="nx">meta</span><span class="p">.</span><span class="nx">pressed</span> <span class="o">==</span> <span class="nx">modifiers</span><span class="p">.</span><span class="nx">meta</span><span class="p">.</span><span class="nx">wanted</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">callback</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">opt</span><span class="p">[</span><span class="s1">'propagate'</span><span class="p">])</span> <span class="p">{</span> <span class="c1">//Stop the event</span>
|
|
<span class="c1">//e.cancelBubble is supported by IE - this will kill the bubbling process.</span>
|
|
<span class="nx">e</span><span class="p">.</span><span class="nx">cancelBubble</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
|
|
<span class="nx">e</span><span class="p">.</span><span class="nx">returnValue</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
|
|
|
|
<span class="c1">//e.stopPropagation works in Firefox.</span>
|
|
<span class="k">if</span> <span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">stopPropagation</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">e</span><span class="p">.</span><span class="nx">stopPropagation</span><span class="p">();</span>
|
|
<span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span>
|
|
<span class="p">}</span>
|
|
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span>
|
|
<span class="k">this</span><span class="p">.</span><span class="nx">all_shortcuts</span><span class="p">[</span><span class="nx">shortcut_combination</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
|
|
<span class="s1">'callback'</span><span class="o">:</span><span class="nx">func</span><span class="p">,</span>
|
|
<span class="s1">'target'</span><span class="o">:</span><span class="nx">ele</span><span class="p">,</span>
|
|
<span class="s1">'event'</span><span class="o">:</span> <span class="nx">opt</span><span class="p">[</span><span class="s1">'type'</span><span class="p">]</span>
|
|
<span class="p">};</span>
|
|
<span class="c1">//Attach the function with the event</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">ele</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">)</span> <span class="nx">ele</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="nx">opt</span><span class="p">[</span><span class="s1">'type'</span><span class="p">],</span> <span class="nx">func</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span>
|
|
<span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">ele</span><span class="p">.</span><span class="nx">attachEvent</span><span class="p">)</span> <span class="nx">ele</span><span class="p">.</span><span class="nx">attachEvent</span><span class="p">(</span><span class="s1">'on'</span><span class="o">+</span><span class="nx">opt</span><span class="p">[</span><span class="s1">'type'</span><span class="p">],</span> <span class="nx">func</span><span class="p">);</span>
|
|
<span class="k">else</span> <span class="nx">ele</span><span class="p">[</span><span class="s1">'on'</span><span class="o">+</span><span class="nx">opt</span><span class="p">[</span><span class="s1">'type'</span><span class="p">]]</span> <span class="o">=</span> <span class="nx">func</span><span class="p">;</span>
|
|
<span class="p">},</span>
|
|
|
|
<span class="c1">//Remove the shortcut - just specify the shortcut and I will remove the binding</span>
|
|
<span class="s1">'remove'</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">shortcut_combination</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">shortcut_combination</span> <span class="o">=</span> <span class="nx">shortcut_combination</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">();</span>
|
|
<span class="kd">var</span> <span class="nx">binding</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">all_shortcuts</span><span class="p">[</span><span class="nx">shortcut_combination</span><span class="p">];</span>
|
|
<span class="k">delete</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">all_shortcuts</span><span class="p">[</span><span class="nx">shortcut_combination</span><span class="p">])</span>
|
|
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">binding</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
|
|
<span class="kd">var</span> <span class="nx">type</span> <span class="o">=</span> <span class="nx">binding</span><span class="p">[</span><span class="s1">'event'</span><span class="p">];</span>
|
|
<span class="kd">var</span> <span class="nx">ele</span> <span class="o">=</span> <span class="nx">binding</span><span class="p">[</span><span class="s1">'target'</span><span class="p">];</span>
|
|
<span class="kd">var</span> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">binding</span><span class="p">[</span><span class="s1">'callback'</span><span class="p">];</span>
|
|
|
|
<span class="k">if</span><span class="p">(</span><span class="nx">ele</span><span class="p">.</span><span class="nx">detachEvent</span><span class="p">)</span> <span class="nx">ele</span><span class="p">.</span><span class="nx">detachEvent</span><span class="p">(</span><span class="s1">'on'</span><span class="o">+</span><span class="nx">type</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
|
|
<span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">ele</span><span class="p">.</span><span class="nx">removeEventListener</span><span class="p">)</span> <span class="nx">ele</span><span class="p">.</span><span class="nx">removeEventListener</span><span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">callback</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span>
|
|
<span class="k">else</span> <span class="nx">ele</span><span class="p">[</span><span class="s1">'on'</span><span class="o">+</span><span class="nx">type</span><span class="p">]</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
|
|
<span class="p">}</span>
|
|
<span class="p">}</span></div></div></div></div></body></html> |