Refactoring

This commit is contained in:
gamonoid
2017-09-03 20:39:22 +02:00
parent af40881847
commit a7274d3cfd
5075 changed files with 238202 additions and 16291 deletions

View File

@@ -0,0 +1,7 @@
// Exports the "contextmenu" plugin for usage with module loaders
// Usage:
// CommonJS:
// require('tinymce/plugins/contextmenu')
// ES2015:
// import 'tinymce/plugins/contextmenu'
require('./plugin.js');

View File

@@ -0,0 +1,116 @@
/**
* plugin.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/*global tinymce:true */
tinymce.PluginManager.add('contextmenu', function(editor) {
var menu, visibleState, contextmenuNeverUseNative = editor.settings.contextmenu_never_use_native;
var isNativeOverrideKeyEvent = function (e) {
return e.ctrlKey && !contextmenuNeverUseNative;
};
var isMacWebKit = function () {
return tinymce.Env.mac && tinymce.Env.webkit;
};
var isContextMenuVisible = function () {
return visibleState === true;
};
/**
* This takes care of a os x native issue where it expands the selection
* to the word at the caret position to do "lookups". Since we are overriding
* the context menu we also need to override this expanding so the behavior becomes
* normalized. Firefox on os x doesn't expand to the word when using the context menu.
*/
editor.on('mousedown', function (e) {
if (isMacWebKit() && e.button === 2 && !isNativeOverrideKeyEvent(e)) {
if (editor.selection.isCollapsed()) {
editor.once('contextmenu', function (e) {
editor.selection.placeCaretAt(e.clientX, e.clientY);
});
}
}
});
editor.on('contextmenu', function(e) {
var contextmenu;
if (isNativeOverrideKeyEvent(e)) {
return;
}
e.preventDefault();
contextmenu = editor.settings.contextmenu || 'link openlink image inserttable | cell row column deletetable';
// Render menu
if (!menu) {
var items = [];
tinymce.each(contextmenu.split(/[ ,]/), function(name) {
var item = editor.menuItems[name];
if (name == '|') {
item = {text: name};
}
if (item) {
item.shortcut = ''; // Hide shortcuts
items.push(item);
}
});
for (var i = 0; i < items.length; i++) {
if (items[i].text == '|') {
if (i === 0 || i == items.length - 1) {
items.splice(i, 1);
}
}
}
menu = new tinymce.ui.Menu({
items: items,
context: 'contextmenu',
classes: 'contextmenu'
}).renderTo();
menu.on('hide', function (e) {
if (e.control === this) {
visibleState = false;
}
});
editor.on('remove', function() {
menu.remove();
menu = null;
});
} else {
menu.show();
}
// Position menu
var pos = {x: e.pageX, y: e.pageY};
if (!editor.inline) {
pos = tinymce.DOM.getPos(editor.getContentAreaContainer());
pos.x += e.clientX;
pos.y += e.clientY;
}
menu.moveTo(pos.x, pos.y);
visibleState = true;
});
return {
isContextMenuVisible: isContextMenuVisible
};
});

View File

@@ -0,0 +1 @@
tinymce.PluginManager.add("contextmenu",function(e){var t,n,r=e.settings.contextmenu_never_use_native,i=function(e){return e.ctrlKey&&!r},o=function(){return tinymce.Env.mac&&tinymce.Env.webkit},a=function(){return n===!0};return e.on("mousedown",function(t){o()&&2===t.button&&!i(t)&&e.selection.isCollapsed()&&e.once("contextmenu",function(t){e.selection.placeCaretAt(t.clientX,t.clientY)})}),e.on("contextmenu",function(r){var o;if(!i(r)){if(r.preventDefault(),o=e.settings.contextmenu||"link openlink image inserttable | cell row column deletetable",t)t.show();else{var a=[];tinymce.each(o.split(/[ ,]/),function(t){var n=e.menuItems[t];"|"==t&&(n={text:t}),n&&(n.shortcut="",a.push(n))});for(var s=0;s<a.length;s++)"|"==a[s].text&&(0!==s&&s!=a.length-1||a.splice(s,1));t=new tinymce.ui.Menu({items:a,context:"contextmenu",classes:"contextmenu"}).renderTo(),t.on("hide",function(e){e.control===this&&(n=!1)}),e.on("remove",function(){t.remove(),t=null})}var l={x:r.pageX,y:r.pageY};e.inline||(l=tinymce.DOM.getPos(e.getContentAreaContainer()),l.x+=r.clientX,l.y+=r.clientY),t.moveTo(l.x,l.y),n=!0}}),{isContextMenuVisible:a}});