PageRenderTime 27ms CodeModel.GetById 9ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/tinymce-advanced/mce/contextmenu/plugin.js

https://bitbucket.org/carloskikea/helpet
JavaScript | 168 lines | 154 code | 14 blank | 0 comment | 16 complexity | 83b39a4f0eb41130710d8e8faa830c68 MD5 | raw file
  1(function () {
  2var contextmenu = (function () {
  3  'use strict';
  4
  5  var Cell = function (initial) {
  6    var value = initial;
  7    var get = function () {
  8      return value;
  9    };
 10    var set = function (v) {
 11      value = v;
 12    };
 13    var clone = function () {
 14      return Cell(get());
 15    };
 16    return {
 17      get: get,
 18      set: set,
 19      clone: clone
 20    };
 21  };
 22
 23  var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
 24
 25  var get = function (visibleState) {
 26    var isContextMenuVisible = function () {
 27      return visibleState.get();
 28    };
 29    return { isContextMenuVisible: isContextMenuVisible };
 30  };
 31  var $_e8837ea6jfuviwq2 = { get: get };
 32
 33  var shouldNeverUseNative = function (editor) {
 34    return editor.settings.contextmenu_never_use_native;
 35  };
 36  var getContextMenu = function (editor) {
 37    return editor.getParam('contextmenu', 'link openlink image inserttable | cell row column deletetable');
 38  };
 39  var $_4c31s3a8jfuviwq5 = {
 40    shouldNeverUseNative: shouldNeverUseNative,
 41    getContextMenu: getContextMenu
 42  };
 43
 44  var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
 45
 46  var getUiContainer = function (editor) {
 47    return global$1.DOM.select(editor.settings.ui_container)[0];
 48  };
 49
 50  var nu = function (x, y) {
 51    return {
 52      x: x,
 53      y: y
 54    };
 55  };
 56  var transpose = function (pos, dx, dy) {
 57    return nu(pos.x + dx, pos.y + dy);
 58  };
 59  var fromPageXY = function (e) {
 60    return nu(e.pageX, e.pageY);
 61  };
 62  var fromClientXY = function (e) {
 63    return nu(e.clientX, e.clientY);
 64  };
 65  var transposeUiContainer = function (element, pos) {
 66    if (element && global$1.DOM.getStyle(element, 'position', true) !== 'static') {
 67      var containerPos = global$1.DOM.getPos(element);
 68      var dx = containerPos.x - element.scrollLeft;
 69      var dy = containerPos.y - element.scrollTop;
 70      return transpose(pos, -dx, -dy);
 71    } else {
 72      return transpose(pos, 0, 0);
 73    }
 74  };
 75  var transposeContentAreaContainer = function (element, pos) {
 76    var containerPos = global$1.DOM.getPos(element);
 77    return transpose(pos, containerPos.x, containerPos.y);
 78  };
 79  var getPos = function (editor, e) {
 80    if (editor.inline) {
 81      return transposeUiContainer(getUiContainer(editor), fromPageXY(e));
 82    } else {
 83      var iframePos = transposeContentAreaContainer(editor.getContentAreaContainer(), fromClientXY(e));
 84      return transposeUiContainer(getUiContainer(editor), iframePos);
 85    }
 86  };
 87  var $_dmx61la9jfuviwq6 = { getPos: getPos };
 88
 89  var global$2 = tinymce.util.Tools.resolve('tinymce.ui.Factory');
 90
 91  var global$3 = tinymce.util.Tools.resolve('tinymce.util.Tools');
 92
 93  var renderMenu = function (editor, visibleState) {
 94    var menu, contextmenu;
 95    var items = [];
 96    contextmenu = $_4c31s3a8jfuviwq5.getContextMenu(editor);
 97    global$3.each(contextmenu.split(/[ ,]/), function (name) {
 98      var item = editor.menuItems[name];
 99      if (name === '|') {
100        item = { text: name };
101      }
102      if (item) {
103        item.shortcut = '';
104        items.push(item);
105      }
106    });
107    for (var i = 0; i < items.length; i++) {
108      if (items[i].text === '|') {
109        if (i === 0 || i === items.length - 1) {
110          items.splice(i, 1);
111        }
112      }
113    }
114    menu = global$2.create('menu', {
115      items: items,
116      context: 'contextmenu',
117      classes: 'contextmenu'
118    });
119    menu.uiContainer = getUiContainer(editor);
120    menu.renderTo(getUiContainer(editor));
121    menu.on('hide', function (e) {
122      if (e.control === this) {
123        visibleState.set(false);
124      }
125    });
126    editor.on('remove', function () {
127      menu.remove();
128      menu = null;
129    });
130    return menu;
131  };
132  var show = function (editor, pos, visibleState, menu) {
133    if (menu.get() === null) {
134      menu.set(renderMenu(editor, visibleState));
135    } else {
136      menu.get().show();
137    }
138    menu.get().moveTo(pos.x, pos.y);
139    visibleState.set(true);
140  };
141  var $_brl8zkacjfuviwqa = { show: show };
142
143  var isNativeOverrideKeyEvent = function (editor, e) {
144    return e.ctrlKey && !$_4c31s3a8jfuviwq5.shouldNeverUseNative(editor);
145  };
146  var setup = function (editor, visibleState, menu) {
147    editor.on('contextmenu', function (e) {
148      if (isNativeOverrideKeyEvent(editor, e)) {
149        return;
150      }
151      e.preventDefault();
152      $_brl8zkacjfuviwqa.show(editor, $_dmx61la9jfuviwq6.getPos(editor, e), visibleState, menu);
153    });
154  };
155  var $_8an0yta7jfuviwq3 = { setup: setup };
156
157  global.add('contextmenu', function (editor) {
158    var menu = Cell(null), visibleState = Cell(false);
159    $_8an0yta7jfuviwq3.setup(editor, visibleState, menu);
160    return $_e8837ea6jfuviwq2.get(visibleState);
161  });
162  function Plugin () {
163  }
164
165  return Plugin;
166
167}());
168})();