ldc-sbv/wp-content/plugins/tinymce-advanced/mce/nonbreaking/plugin.js

86 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-09-21 15:01:08 +02:00
(function () {
2021-09-21 15:04:09 +02:00
var nonbreaking = (function () {
'use strict';
2021-09-21 15:01:08 +02:00
2021-09-21 15:04:09 +02:00
var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
2021-09-21 15:01:08 +02:00
2021-09-21 15:04:09 +02:00
var stringRepeat = function (string, repeats) {
var str = '';
for (var index = 0; index < repeats; index++) {
str += string;
}
return str;
};
var isVisualCharsEnabled = function (editor) {
return editor.plugins.visualchars ? editor.plugins.visualchars.isEnabled() : false;
};
var insertNbsp = function (editor, times) {
var nbsp = isVisualCharsEnabled(editor) ? '<span class="mce-nbsp">&nbsp;</span>' : '&nbsp;';
editor.insertContent(stringRepeat(nbsp, times));
editor.dom.setAttrib(editor.dom.select('span.mce-nbsp'), 'data-mce-bogus', '1');
};
var Actions = { insertNbsp: insertNbsp };
var register = function (editor) {
editor.addCommand('mceNonBreaking', function () {
Actions.insertNbsp(editor, 1);
});
};
var Commands = { register: register };
2021-09-21 15:01:08 +02:00
2021-09-21 15:04:09 +02:00
var global$1 = tinymce.util.Tools.resolve('tinymce.util.VK');
2021-09-21 15:01:08 +02:00
2021-09-21 15:04:09 +02:00
var getKeyboardSpaces = function (editor) {
var spaces = editor.getParam('nonbreaking_force_tab', 0);
if (typeof spaces === 'boolean') {
return spaces === true ? 3 : 0;
} else {
return spaces;
}
};
var Settings = { getKeyboardSpaces: getKeyboardSpaces };
2021-09-21 15:01:08 +02:00
2021-09-21 15:04:09 +02:00
var setup = function (editor) {
var spaces = Settings.getKeyboardSpaces(editor);
if (spaces > 0) {
editor.on('keydown', function (e) {
if (e.keyCode === global$1.TAB && !e.isDefaultPrevented()) {
if (e.shiftKey) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
Actions.insertNbsp(editor, spaces);
}
});
}
};
var Keyboard = { setup: setup };
2021-09-21 15:01:08 +02:00
2021-09-21 15:04:09 +02:00
var register$1 = function (editor) {
2021-09-21 15:01:08 +02:00
editor.addButton('nonbreaking', {
title: 'Nonbreaking space',
cmd: 'mceNonBreaking'
});
editor.addMenuItem('nonbreaking', {
2021-09-21 15:04:09 +02:00
icon: 'nonbreaking',
2021-09-21 15:01:08 +02:00
text: 'Nonbreaking space',
cmd: 'mceNonBreaking',
context: 'insert'
});
2021-09-21 15:04:09 +02:00
};
var Buttons = { register: register$1 };
2021-09-21 15:01:08 +02:00
2021-09-21 15:04:09 +02:00
global.add('nonbreaking', function (editor) {
Commands.register(editor);
Buttons.register(editor);
Keyboard.setup(editor);
2021-09-21 15:01:08 +02:00
});
2021-09-21 15:04:09 +02:00
function Plugin () {
}
return Plugin;
2021-09-21 15:01:08 +02:00
2021-09-21 15:04:09 +02:00
}());
2021-09-21 15:01:08 +02:00
})();