plugin.js 3.9 KB

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