plugin.js 3.6 KB

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