PageRenderTime 34ms CodeModel.GetById 18ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://bitbucket.org/carloskikea/helpet
JavaScript | 135 lines | 121 code | 14 blank | 0 comment | 3 complexity | 91cd92e83e3138e1da39d2c6d567f1a4 MD5 | raw file
  1(function () {
  2var visualblocks = (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 fireVisualBlocks = function (editor, state) {
 26    editor.fire('VisualBlocks', { state: state });
 27  };
 28  var $_8ve51drljfuvizyc = { fireVisualBlocks: fireVisualBlocks };
 29
 30  var isEnabledByDefault = function (editor) {
 31    return editor.getParam('visualblocks_default_state', false);
 32  };
 33  var getContentCss = function (editor) {
 34    return editor.settings.visualblocks_content_css;
 35  };
 36  var $_3mx2zgrmjfuvizyc = {
 37    isEnabledByDefault: isEnabledByDefault,
 38    getContentCss: getContentCss
 39  };
 40
 41  var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
 42
 43  var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
 44
 45  var cssId = global$1.DOM.uniqueId();
 46  var load = function (doc, url) {
 47    var linkElements = global$2.toArray(doc.getElementsByTagName('link'));
 48    var matchingLinkElms = global$2.grep(linkElements, function (head) {
 49      return head.id === cssId;
 50    });
 51    if (matchingLinkElms.length === 0) {
 52      var linkElm = global$1.DOM.create('link', {
 53        id: cssId,
 54        rel: 'stylesheet',
 55        href: url
 56      });
 57      doc.getElementsByTagName('head')[0].appendChild(linkElm);
 58    }
 59  };
 60  var $_c3ie7zrnjfuvizyd = { load: load };
 61
 62  var toggleVisualBlocks = function (editor, pluginUrl, enabledState) {
 63    var dom = editor.dom;
 64    var contentCss = $_3mx2zgrmjfuvizyc.getContentCss(editor);
 65    $_c3ie7zrnjfuvizyd.load(editor.getDoc(), contentCss ? contentCss : pluginUrl + '/css/visualblocks.css');
 66    dom.toggleClass(editor.getBody(), 'mce-visualblocks');
 67    enabledState.set(!enabledState.get());
 68    $_8ve51drljfuvizyc.fireVisualBlocks(editor, enabledState.get());
 69  };
 70  var $_g5w5f0rkjfuvizyb = { toggleVisualBlocks: toggleVisualBlocks };
 71
 72  var register = function (editor, pluginUrl, enabledState) {
 73    editor.addCommand('mceVisualBlocks', function () {
 74      $_g5w5f0rkjfuvizyb.toggleVisualBlocks(editor, pluginUrl, enabledState);
 75    });
 76  };
 77  var $_1xej9srjjfuvizya = { register: register };
 78
 79  var setup = function (editor, pluginUrl, enabledState) {
 80    editor.on('PreviewFormats AfterPreviewFormats', function (e) {
 81      if (enabledState.get()) {
 82        editor.dom.toggleClass(editor.getBody(), 'mce-visualblocks', e.type === 'afterpreviewformats');
 83      }
 84    });
 85    editor.on('init', function () {
 86      if ($_3mx2zgrmjfuvizyc.isEnabledByDefault(editor)) {
 87        $_g5w5f0rkjfuvizyb.toggleVisualBlocks(editor, pluginUrl, enabledState);
 88      }
 89    });
 90    editor.on('remove', function () {
 91      editor.dom.removeClass(editor.getBody(), 'mce-visualblocks');
 92    });
 93  };
 94  var $_2btmdwrqjfuvizyg = { setup: setup };
 95
 96  var toggleActiveState = function (editor, enabledState) {
 97    return function (e) {
 98      var ctrl = e.control;
 99      ctrl.active(enabledState.get());
100      editor.on('VisualBlocks', function (e) {
101        ctrl.active(e.state);
102      });
103    };
104  };
105  var register$1 = function (editor, enabledState) {
106    editor.addButton('visualblocks', {
107      active: false,
108      title: 'Show blocks',
109      cmd: 'mceVisualBlocks',
110      onPostRender: toggleActiveState(editor, enabledState)
111    });
112    editor.addMenuItem('visualblocks', {
113      text: 'Show blocks',
114      cmd: 'mceVisualBlocks',
115      onPostRender: toggleActiveState(editor, enabledState),
116      selectable: true,
117      context: 'view',
118      prependToContext: true
119    });
120  };
121  var $_cll8zkrrjfuvizyh = { register: register$1 };
122
123  global.add('visualblocks', function (editor, pluginUrl) {
124    var enabledState = Cell(false);
125    $_1xej9srjjfuvizya.register(editor, pluginUrl, enabledState);
126    $_cll8zkrrjfuvizyh.register(editor, enabledState);
127    $_2btmdwrqjfuvizyg.setup(editor, pluginUrl, enabledState);
128  });
129  function Plugin () {
130  }
131
132  return Plugin;
133
134}());
135})();