1 /** |
1 (function () { |
2 * plugin.js |
2 var tabfocus = (function () { |
3 * |
3 'use strict'; |
4 * Copyright, Moxiecode Systems AB |
|
5 * Released under LGPL License. |
|
6 * |
|
7 * License: http://www.tinymce.com/license |
|
8 * Contributing: http://www.tinymce.com/contributing |
|
9 */ |
|
10 |
4 |
11 /*global tinymce:true */ |
5 var global = tinymce.util.Tools.resolve('tinymce.PluginManager'); |
12 |
6 |
13 tinymce.PluginManager.add('tabfocus', function(editor) { |
7 var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils'); |
14 var DOM = tinymce.DOM, each = tinymce.each, explode = tinymce.explode; |
|
15 |
8 |
16 function tabCancel(e) { |
9 var global$2 = tinymce.util.Tools.resolve('tinymce.EditorManager'); |
17 if (e.keyCode === 9 && !e.ctrlKey && !e.altKey && !e.metaKey) { |
|
18 e.preventDefault(); |
|
19 } |
|
20 } |
|
21 |
10 |
22 function tabHandler(e) { |
11 var global$3 = tinymce.util.Tools.resolve('tinymce.Env'); |
23 var x, el, v, i; |
|
24 |
12 |
25 if (e.keyCode !== 9 || e.ctrlKey || e.altKey || e.metaKey || e.isDefaultPrevented()) { |
13 var global$4 = tinymce.util.Tools.resolve('tinymce.util.Delay'); |
26 return; |
|
27 } |
|
28 |
14 |
29 function find(direction) { |
15 var global$5 = tinymce.util.Tools.resolve('tinymce.util.Tools'); |
30 el = DOM.select(':input:enabled,*[tabindex]:not(iframe)'); |
|
31 |
16 |
32 function canSelectRecursive(e) { |
17 var global$6 = tinymce.util.Tools.resolve('tinymce.util.VK'); |
33 return e.nodeName === "BODY" || (e.type != 'hidden' && |
|
34 e.style.display != "none" && |
|
35 e.style.visibility != "hidden" && canSelectRecursive(e.parentNode)); |
|
36 } |
|
37 |
18 |
38 function canSelect(el) { |
19 var getTabFocusElements = function (editor) { |
39 return /INPUT|TEXTAREA|BUTTON/.test(el.tagName) && tinymce.get(e.id) && el.tabIndex != -1 && canSelectRecursive(el); |
20 return editor.getParam('tabfocus_elements', ':prev,:next'); |
40 } |
21 }; |
|
22 var getTabFocus = function (editor) { |
|
23 return editor.getParam('tab_focus', getTabFocusElements(editor)); |
|
24 }; |
|
25 var $_8rita4kwjjgwed4m = { getTabFocus: getTabFocus }; |
41 |
26 |
42 each(el, function(e, i) { |
27 var DOM = global$1.DOM; |
43 if (e.id == editor.id) { |
28 var tabCancel = function (e) { |
44 x = i; |
29 if (e.keyCode === global$6.TAB && !e.ctrlKey && !e.altKey && !e.metaKey) { |
45 return false; |
30 e.preventDefault(); |
46 } |
31 } |
47 }); |
32 }; |
48 if (direction > 0) { |
33 var setup = function (editor) { |
49 for (i = x + 1; i < el.length; i++) { |
34 function tabHandler(e) { |
50 if (canSelect(el[i])) { |
35 var x, el, v, i; |
51 return el[i]; |
36 if (e.keyCode !== global$6.TAB || e.ctrlKey || e.altKey || e.metaKey || e.isDefaultPrevented()) { |
52 } |
37 return; |
53 } |
38 } |
54 } else { |
39 function find(direction) { |
55 for (i = x - 1; i >= 0; i--) { |
40 el = DOM.select(':input:enabled,*[tabindex]:not(iframe)'); |
56 if (canSelect(el[i])) { |
41 function canSelectRecursive(e) { |
57 return el[i]; |
42 return e.nodeName === 'BODY' || e.type !== 'hidden' && e.style.display !== 'none' && e.style.visibility !== 'hidden' && canSelectRecursive(e.parentNode); |
58 } |
43 } |
59 } |
44 function canSelect(el) { |
60 } |
45 return /INPUT|TEXTAREA|BUTTON/.test(el.tagName) && global$2.get(e.id) && el.tabIndex !== -1 && canSelectRecursive(el); |
|
46 } |
|
47 global$5.each(el, function (e, i) { |
|
48 if (e.id === editor.id) { |
|
49 x = i; |
|
50 return false; |
|
51 } |
|
52 }); |
|
53 if (direction > 0) { |
|
54 for (i = x + 1; i < el.length; i++) { |
|
55 if (canSelect(el[i])) { |
|
56 return el[i]; |
|
57 } |
|
58 } |
|
59 } else { |
|
60 for (i = x - 1; i >= 0; i--) { |
|
61 if (canSelect(el[i])) { |
|
62 return el[i]; |
|
63 } |
|
64 } |
|
65 } |
|
66 return null; |
|
67 } |
|
68 v = global$5.explode($_8rita4kwjjgwed4m.getTabFocus(editor)); |
|
69 if (v.length === 1) { |
|
70 v[1] = v[0]; |
|
71 v[0] = ':prev'; |
|
72 } |
|
73 if (e.shiftKey) { |
|
74 if (v[0] === ':prev') { |
|
75 el = find(-1); |
|
76 } else { |
|
77 el = DOM.get(v[0]); |
|
78 } |
|
79 } else { |
|
80 if (v[1] === ':next') { |
|
81 el = find(1); |
|
82 } else { |
|
83 el = DOM.get(v[1]); |
|
84 } |
|
85 } |
|
86 if (el) { |
|
87 var focusEditor = global$2.get(el.id || el.name); |
|
88 if (el.id && focusEditor) { |
|
89 focusEditor.focus(); |
|
90 } else { |
|
91 global$4.setTimeout(function () { |
|
92 if (!global$3.webkit) { |
|
93 window.focus(); |
|
94 } |
|
95 el.focus(); |
|
96 }, 10); |
|
97 } |
|
98 e.preventDefault(); |
|
99 } |
|
100 } |
|
101 editor.on('init', function () { |
|
102 if (editor.inline) { |
|
103 DOM.setAttrib(editor.getBody(), 'tabIndex', null); |
|
104 } |
|
105 editor.on('keyup', tabCancel); |
|
106 if (global$3.gecko) { |
|
107 editor.on('keypress keydown', tabHandler); |
|
108 } else { |
|
109 editor.on('keydown', tabHandler); |
|
110 } |
|
111 }); |
|
112 }; |
|
113 var $_6zogdykpjjgwed4h = { setup: setup }; |
61 |
114 |
62 return null; |
115 global.add('tabfocus', function (editor) { |
63 } |
116 $_6zogdykpjjgwed4h.setup(editor); |
|
117 }); |
|
118 function Plugin () { |
|
119 } |
64 |
120 |
65 v = explode(editor.getParam('tab_focus', editor.getParam('tabfocus_elements', ':prev,:next'))); |
121 return Plugin; |
66 |
122 |
67 if (v.length == 1) { |
123 }()); |
68 v[1] = v[0]; |
124 })(); |
69 v[0] = ':prev'; |
|
70 } |
|
71 |
|
72 // Find element to focus |
|
73 if (e.shiftKey) { |
|
74 if (v[0] == ':prev') { |
|
75 el = find(-1); |
|
76 } else { |
|
77 el = DOM.get(v[0]); |
|
78 } |
|
79 } else { |
|
80 if (v[1] == ':next') { |
|
81 el = find(1); |
|
82 } else { |
|
83 el = DOM.get(v[1]); |
|
84 } |
|
85 } |
|
86 |
|
87 if (el) { |
|
88 var focusEditor = tinymce.get(el.id || el.name); |
|
89 |
|
90 if (el.id && focusEditor) { |
|
91 focusEditor.focus(); |
|
92 } else { |
|
93 window.setTimeout(function() { |
|
94 if (!tinymce.Env.webkit) { |
|
95 window.focus(); |
|
96 } |
|
97 |
|
98 el.focus(); |
|
99 }, 10); |
|
100 } |
|
101 |
|
102 e.preventDefault(); |
|
103 } |
|
104 } |
|
105 |
|
106 editor.on('init', function() { |
|
107 if (editor.inline) { |
|
108 // Remove default tabIndex in inline mode |
|
109 tinymce.DOM.setAttrib(editor.getBody(), 'tabIndex', null); |
|
110 } |
|
111 |
|
112 editor.on('keyup', tabCancel); |
|
113 |
|
114 if (tinymce.Env.gecko) { |
|
115 editor.on('keypress keydown', tabHandler); |
|
116 } else { |
|
117 editor.on('keydown', tabHandler); |
|
118 } |
|
119 }); |
|
120 }); |
|