Rev 1422 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
597 | daniel-mar | 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 | * |
||
1434 | daniel-mar | 7 | * Version: 5.10.9 (2023-11-15) |
597 | daniel-mar | 8 | */ |
9 | (function () { |
||
10 | 'use strict'; |
||
11 | |||
637 | daniel-mar | 12 | var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager'); |
597 | daniel-mar | 13 | |
14 | var getKeyboardSpaces = function (editor) { |
||
15 | var spaces = editor.getParam('nonbreaking_force_tab', 0); |
||
16 | if (typeof spaces === 'boolean') { |
||
17 | return spaces === true ? 3 : 0; |
||
18 | } else { |
||
19 | return spaces; |
||
20 | } |
||
21 | }; |
||
22 | var wrapNbsps = function (editor) { |
||
23 | return editor.getParam('nonbreaking_wrap', true, 'boolean'); |
||
24 | }; |
||
25 | |||
26 | var stringRepeat = function (string, repeats) { |
||
27 | var str = ''; |
||
28 | for (var index = 0; index < repeats; index++) { |
||
29 | str += string; |
||
30 | } |
||
31 | return str; |
||
32 | }; |
||
33 | var isVisualCharsEnabled = function (editor) { |
||
34 | return editor.plugins.visualchars ? editor.plugins.visualchars.isEnabled() : false; |
||
35 | }; |
||
36 | var insertNbsp = function (editor, times) { |
||
37 | var classes = function () { |
||
38 | return isVisualCharsEnabled(editor) ? 'mce-nbsp-wrap mce-nbsp' : 'mce-nbsp-wrap'; |
||
39 | }; |
||
40 | var nbspSpan = function () { |
||
41 | return '<span class="' + classes() + '" contenteditable="false">' + stringRepeat(' ', times) + '</span>'; |
||
42 | }; |
||
43 | var shouldWrap = wrapNbsps(editor); |
||
44 | var html = shouldWrap || editor.plugins.visualchars ? nbspSpan() : stringRepeat(' ', times); |
||
45 | editor.undoManager.transact(function () { |
||
46 | return editor.insertContent(html); |
||
47 | }); |
||
48 | }; |
||
49 | |||
637 | daniel-mar | 50 | var register$1 = function (editor) { |
597 | daniel-mar | 51 | editor.addCommand('mceNonBreaking', function () { |
52 | insertNbsp(editor, 1); |
||
53 | }); |
||
54 | }; |
||
55 | |||
637 | daniel-mar | 56 | var global = tinymce.util.Tools.resolve('tinymce.util.VK'); |
597 | daniel-mar | 57 | |
58 | var setup = function (editor) { |
||
59 | var spaces = getKeyboardSpaces(editor); |
||
60 | if (spaces > 0) { |
||
61 | editor.on('keydown', function (e) { |
||
637 | daniel-mar | 62 | if (e.keyCode === global.TAB && !e.isDefaultPrevented()) { |
597 | daniel-mar | 63 | if (e.shiftKey) { |
64 | return; |
||
65 | } |
||
66 | e.preventDefault(); |
||
67 | e.stopImmediatePropagation(); |
||
68 | insertNbsp(editor, spaces); |
||
69 | } |
||
70 | }); |
||
71 | } |
||
72 | }; |
||
73 | |||
637 | daniel-mar | 74 | var register = function (editor) { |
75 | var onAction = function () { |
||
76 | return editor.execCommand('mceNonBreaking'); |
||
77 | }; |
||
597 | daniel-mar | 78 | editor.ui.registry.addButton('nonbreaking', { |
79 | icon: 'non-breaking', |
||
80 | tooltip: 'Nonbreaking space', |
||
637 | daniel-mar | 81 | onAction: onAction |
597 | daniel-mar | 82 | }); |
83 | editor.ui.registry.addMenuItem('nonbreaking', { |
||
84 | icon: 'non-breaking', |
||
85 | text: 'Nonbreaking space', |
||
637 | daniel-mar | 86 | onAction: onAction |
597 | daniel-mar | 87 | }); |
88 | }; |
||
89 | |||
90 | function Plugin () { |
||
637 | daniel-mar | 91 | global$1.add('nonbreaking', function (editor) { |
92 | register$1(editor); |
||
597 | daniel-mar | 93 | register(editor); |
94 | setup(editor); |
||
95 | }); |
||
96 | } |
||
97 | |||
98 | Plugin(); |
||
99 | |||
100 | }()); |