import MarkdowneditorVersions from "./markdowneditor.versions";
import tippy from "tippy.js";
import 'tippy.js/dist/tippy.css';
+
window.$ = window.jQuery = require('jquery');
+window.key = require('keymaster-reloaded');
+
+window.key.filter = function (event) {
+ return keyfilter(event);
+};
+
+function keyfilter(event, disable = false) {
+ if (disable) {
+ return false
+ }
+ let tagName = (event.target || event.srcElement).tagName;
+ //let field=tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA';
+ if (tagName === 'TEXTAREA' && event.keyCode === 13) {
+ return false;
+ }
+
+ return true;
+}
$.ajaxSetup({
headers: {
this.open = false
$("#linkeditor-icon-versions").removeClass("active")
}
- }
+ },
+
+ isfocusOnFormItem: function () {
+ return $(document.activeElement).is('input[type="text"],input[type="email"],input[type="number"],input[type="tel"],input[type="search"],textarea,select');
+ },
+
+ focusPageField: function () {
+ let i = $("#markdowneditor-page-field input").get(0);
+ i.focus();
+ i.select();
+ },
/*isSpecialPage: function (page) {
if (page === undefined) {
$this.markdowneditor.runAction($(this).data('action'), $(this).is('[data-action-args]') ? $(this).data('action-args') : []);
return false;
});
- }
+
+ $("[data-key]").each(function () {
+ let e = $(this);
+ key($(this).data('key'), function () {
+ if ($(e).is('[data-key-skipintextfields]') && $this.markdowneditor.isfocusOnFormItem()) {
+ return true;
+ }
+ $(e).addClass('hover');
+ $this.markdowneditor.runAction($(e).data('action'));
+ setTimeout(function () {
+ $(e).removeClass('hover')
+ }, 150);
+ return false;
+ });
+ });
+
+ this.key('enter', function () {
+ if ($(document.activeElement).is('input[type="number"]')) {
+ $this.markdowneditor.changePage($(document.activeElement).val());
+ return false;
+ }
+ });
+ },
+
+ key: function (shortcut, scope) {
+ var $this = this;
+ key(shortcut, function (event, handler) {
+ if ($this.allowsKeyboardShortcut(shortcut)) {
+ var res = scope(event, handler);
+ return res;
+ }
+ });
+ },
+
+ allowsKeyboardShortcut: function (shortcut) {
+ if (shortcut === 'pageup' || shortcut === 'pagedown' || shortcut === 'enter') {
+ return true;
+ }
+ return !this.markdowneditor.isfocusOnFormItem();
+ },
};
export default MarkdowneditorToolbar;