plugin.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.0.1 (2019-02-21)
  8. */
  9. (function () {
  10. var nonbreaking = (function () {
  11. 'use strict';
  12. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  13. var stringRepeat = function (string, repeats) {
  14. var str = '';
  15. for (var index = 0; index < repeats; index++) {
  16. str += string;
  17. }
  18. return str;
  19. };
  20. var isVisualCharsEnabled = function (editor) {
  21. return editor.plugins.visualchars ? editor.plugins.visualchars.isEnabled() : false;
  22. };
  23. var insertNbsp = function (editor, times) {
  24. var nbsp = isVisualCharsEnabled(editor) ? '<span class="mce-nbsp">&nbsp;</span>' : '&nbsp;';
  25. editor.insertContent(stringRepeat(nbsp, times));
  26. editor.dom.setAttrib(editor.dom.select('span.mce-nbsp'), 'data-mce-bogus', '1');
  27. };
  28. var Actions = { insertNbsp: insertNbsp };
  29. var register = function (editor) {
  30. editor.addCommand('mceNonBreaking', function () {
  31. Actions.insertNbsp(editor, 1);
  32. });
  33. };
  34. var Commands = { register: register };
  35. var global$1 = tinymce.util.Tools.resolve('tinymce.util.VK');
  36. var getKeyboardSpaces = function (editor) {
  37. var spaces = editor.getParam('nonbreaking_force_tab', 0);
  38. if (typeof spaces === 'boolean') {
  39. return spaces === true ? 3 : 0;
  40. } else {
  41. return spaces;
  42. }
  43. };
  44. var Settings = { getKeyboardSpaces: getKeyboardSpaces };
  45. var setup = function (editor) {
  46. var spaces = Settings.getKeyboardSpaces(editor);
  47. if (spaces > 0) {
  48. editor.on('keydown', function (e) {
  49. if (e.keyCode === global$1.TAB && !e.isDefaultPrevented()) {
  50. if (e.shiftKey) {
  51. return;
  52. }
  53. e.preventDefault();
  54. e.stopImmediatePropagation();
  55. Actions.insertNbsp(editor, spaces);
  56. }
  57. });
  58. }
  59. };
  60. var Keyboard = { setup: setup };
  61. var register$1 = function (editor) {
  62. editor.ui.registry.addButton('nonbreaking', {
  63. icon: 'non-breaking',
  64. tooltip: 'Nonbreaking space',
  65. onAction: function () {
  66. return editor.execCommand('mceNonBreaking');
  67. }
  68. });
  69. editor.ui.registry.addMenuItem('nonbreaking', {
  70. icon: 'non-breaking',
  71. text: 'Nonbreaking space',
  72. onAction: function () {
  73. return editor.execCommand('mceNonBreaking');
  74. }
  75. });
  76. };
  77. var Buttons = { register: register$1 };
  78. global.add('nonbreaking', function (editor) {
  79. Commands.register(editor);
  80. Buttons.register(editor);
  81. Keyboard.setup(editor);
  82. });
  83. function Plugin () {
  84. }
  85. return Plugin;
  86. }());
  87. })();