| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,116 @@ |
| 1 |
+/** |
|
| 2 |
+ * plugin.js |
|
| 3 |
+ * |
|
| 4 |
+ * Released under LGPL License. |
|
| 5 |
+ * Copyright (c) 1999-2015 Ephox Corp. All rights reserved |
|
| 6 |
+ * |
|
| 7 |
+ * License: http://www.tinymce.com/license |
|
| 8 |
+ * Contributing: http://www.tinymce.com/contributing |
|
| 9 |
+ */ |
|
| 10 |
+ |
|
| 11 |
+/*global tinymce:true */ |
|
| 12 |
+ |
|
| 13 |
+tinymce.PluginManager.add('contextmenu', function(editor) {
|
|
| 14 |
+ var menu, visibleState, contextmenuNeverUseNative = editor.settings.contextmenu_never_use_native; |
|
| 15 |
+ |
|
| 16 |
+ var isNativeOverrideKeyEvent = function (e) {
|
|
| 17 |
+ return e.ctrlKey && !contextmenuNeverUseNative; |
|
| 18 |
+ }; |
|
| 19 |
+ |
|
| 20 |
+ var isMacWebKit = function () {
|
|
| 21 |
+ return tinymce.Env.mac && tinymce.Env.webkit; |
|
| 22 |
+ }; |
|
| 23 |
+ |
|
| 24 |
+ var isContextMenuVisible = function () {
|
|
| 25 |
+ return visibleState === true; |
|
| 26 |
+ }; |
|
| 27 |
+ |
|
| 28 |
+ /** |
|
| 29 |
+ * This takes care of a os x native issue where it expands the selection |
|
| 30 |
+ * to the word at the caret position to do "lookups". Since we are overriding |
|
| 31 |
+ * the context menu we also need to override this expanding so the behavior becomes |
|
| 32 |
+ * normalized. Firefox on os x doesn't expand to the word when using the context menu. |
|
| 33 |
+ */ |
|
| 34 |
+ editor.on('mousedown', function (e) {
|
|
| 35 |
+ if (isMacWebKit() && e.button === 2 && !isNativeOverrideKeyEvent(e)) {
|
|
| 36 |
+ if (editor.selection.isCollapsed()) {
|
|
| 37 |
+ editor.once('contextmenu', function (e) {
|
|
| 38 |
+ editor.selection.placeCaretAt(e.clientX, e.clientY); |
|
| 39 |
+ }); |
|
| 40 |
+ } |
|
| 41 |
+ } |
|
| 42 |
+ }); |
|
| 43 |
+ |
|
| 44 |
+ editor.on('contextmenu', function(e) {
|
|
| 45 |
+ var contextmenu; |
|
| 46 |
+ |
|
| 47 |
+ if (isNativeOverrideKeyEvent(e)) {
|
|
| 48 |
+ return; |
|
| 49 |
+ } |
|
| 50 |
+ |
|
| 51 |
+ e.preventDefault(); |
|
| 52 |
+ contextmenu = editor.settings.contextmenu || 'link openlink image inserttable | cell row column deletetable'; |
|
| 53 |
+ |
|
| 54 |
+ // Render menu |
|
| 55 |
+ if (!menu) {
|
|
| 56 |
+ var items = []; |
|
| 57 |
+ |
|
| 58 |
+ tinymce.each(contextmenu.split(/[ ,]/), function(name) {
|
|
| 59 |
+ var item = editor.menuItems[name]; |
|
| 60 |
+ |
|
| 61 |
+ if (name == '|') {
|
|
| 62 |
+ item = {text: name};
|
|
| 63 |
+ } |
|
| 64 |
+ |
|
| 65 |
+ if (item) {
|
|
| 66 |
+ item.shortcut = ''; // Hide shortcuts |
|
| 67 |
+ items.push(item); |
|
| 68 |
+ } |
|
| 69 |
+ }); |
|
| 70 |
+ |
|
| 71 |
+ for (var i = 0; i < items.length; i++) {
|
|
| 72 |
+ if (items[i].text == '|') {
|
|
| 73 |
+ if (i === 0 || i == items.length - 1) {
|
|
| 74 |
+ items.splice(i, 1); |
|
| 75 |
+ } |
|
| 76 |
+ } |
|
| 77 |
+ } |
|
| 78 |
+ |
|
| 79 |
+ menu = new tinymce.ui.Menu({
|
|
| 80 |
+ items: items, |
|
| 81 |
+ context: 'contextmenu', |
|
| 82 |
+ classes: 'contextmenu' |
|
| 83 |
+ }).renderTo(); |
|
| 84 |
+ |
|
| 85 |
+ menu.on('hide', function (e) {
|
|
| 86 |
+ if (e.control === this) {
|
|
| 87 |
+ visibleState = false; |
|
| 88 |
+ } |
|
| 89 |
+ }); |
|
| 90 |
+ |
|
| 91 |
+ editor.on('remove', function() {
|
|
| 92 |
+ menu.remove(); |
|
| 93 |
+ menu = null; |
|
| 94 |
+ }); |
|
| 95 |
+ |
|
| 96 |
+ } else {
|
|
| 97 |
+ menu.show(); |
|
| 98 |
+ } |
|
| 99 |
+ |
|
| 100 |
+ // Position menu |
|
| 101 |
+ var pos = {x: e.pageX, y: e.pageY};
|
|
| 102 |
+ |
|
| 103 |
+ if (!editor.inline) {
|
|
| 104 |
+ pos = tinymce.DOM.getPos(editor.getContentAreaContainer()); |
|
| 105 |
+ pos.x += e.clientX; |
|
| 106 |
+ pos.y += e.clientY; |
|
| 107 |
+ } |
|
| 108 |
+ |
|
| 109 |
+ menu.moveTo(pos.x, pos.y); |
|
| 110 |
+ visibleState = true; |
|
| 111 |
+ }); |
|
| 112 |
+ |
|
| 113 |
+ return {
|
|
| 114 |
+ isContextMenuVisible: isContextMenuVisible |
|
| 115 |
+ }; |
|
| 116 |
+}); |
|
| 0 | 117 |
\ No newline at end of file |