PageRenderTime 33ms CodeModel.GetById 17ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/carloskikea/helpet
JavaScript | 160 lines | 149 code | 11 blank | 0 comment | 10 complexity | 30f12597d4c87fec2a1ea7b29132815c MD5 | raw file
  1(function () {
  2var advlist = (function () {
  3  'use strict';
  4
  5  var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  6
  7  var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  8
  9  var applyListFormat = function (editor, listName, styleValue) {
 10    var cmd = listName === 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList';
 11    editor.execCommand(cmd, false, styleValue === false ? null : { 'list-style-type': styleValue });
 12  };
 13  var $_2gx00q7vjfuviwh8 = { applyListFormat: applyListFormat };
 14
 15  var register = function (editor) {
 16    editor.addCommand('ApplyUnorderedListStyle', function (ui, value) {
 17      $_2gx00q7vjfuviwh8.applyListFormat(editor, 'UL', value['list-style-type']);
 18    });
 19    editor.addCommand('ApplyOrderedListStyle', function (ui, value) {
 20      $_2gx00q7vjfuviwh8.applyListFormat(editor, 'OL', value['list-style-type']);
 21    });
 22  };
 23  var $_djjlld7ujfuviwh7 = { register: register };
 24
 25  var getNumberStyles = function (editor) {
 26    var styles = editor.getParam('advlist_number_styles', 'default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman');
 27    return styles ? styles.split(/[ ,]/) : [];
 28  };
 29  var getBulletStyles = function (editor) {
 30    var styles = editor.getParam('advlist_bullet_styles', 'default,circle,disc,square');
 31    return styles ? styles.split(/[ ,]/) : [];
 32  };
 33  var $_24vhad7xjfuviwhc = {
 34    getNumberStyles: getNumberStyles,
 35    getBulletStyles: getBulletStyles
 36  };
 37
 38  var isChildOfBody = function (editor, elm) {
 39    return editor.$.contains(editor.getBody(), elm);
 40  };
 41  var isTableCellNode = function (node) {
 42    return node && /^(TH|TD)$/.test(node.nodeName);
 43  };
 44  var isListNode = function (editor) {
 45    return function (node) {
 46      return node && /^(OL|UL|DL)$/.test(node.nodeName) && isChildOfBody(editor, node);
 47    };
 48  };
 49  var getSelectedStyleType = function (editor) {
 50    var listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul');
 51    return editor.dom.getStyle(listElm, 'listStyleType') || '';
 52  };
 53  var $_6puoap7yjfuviwhd = {
 54    isTableCellNode: isTableCellNode,
 55    isListNode: isListNode,
 56    getSelectedStyleType: getSelectedStyleType
 57  };
 58
 59  var styleValueToText = function (styleValue) {
 60    return styleValue.replace(/\-/g, ' ').replace(/\b\w/g, function (chr) {
 61      return chr.toUpperCase();
 62    });
 63  };
 64  var toMenuItems = function (styles) {
 65    return global$1.map(styles, function (styleValue) {
 66      var text = styleValueToText(styleValue);
 67      var data = styleValue === 'default' ? '' : styleValue;
 68      return {
 69        text: text,
 70        data: data
 71      };
 72    });
 73  };
 74  var $_dq1tfe7zjfuviwhe = { toMenuItems: toMenuItems };
 75
 76  var findIndex = function (list, predicate) {
 77    for (var index = 0; index < list.length; index++) {
 78      var element = list[index];
 79      if (predicate(element)) {
 80        return index;
 81      }
 82    }
 83    return -1;
 84  };
 85  var listState = function (editor, listName) {
 86    return function (e) {
 87      var ctrl = e.control;
 88      editor.on('NodeChange', function (e) {
 89        var tableCellIndex = findIndex(e.parents, $_6puoap7yjfuviwhd.isTableCellNode);
 90        var parents = tableCellIndex !== -1 ? e.parents.slice(0, tableCellIndex) : e.parents;
 91        var lists = global$1.grep(parents, $_6puoap7yjfuviwhd.isListNode(editor));
 92        ctrl.active(lists.length > 0 && lists[0].nodeName === listName);
 93      });
 94    };
 95  };
 96  var updateSelection = function (editor) {
 97    return function (e) {
 98      var listStyleType = $_6puoap7yjfuviwhd.getSelectedStyleType(editor);
 99      e.control.items().each(function (ctrl) {
100        ctrl.active(ctrl.settings.data === listStyleType);
101      });
102    };
103  };
104  var addSplitButton = function (editor, id, tooltip, cmd, nodeName, styles) {
105    editor.addButton(id, {
106      active: false,
107      type: 'splitbutton',
108      tooltip: tooltip,
109      menu: $_dq1tfe7zjfuviwhe.toMenuItems(styles),
110      onPostRender: listState(editor, nodeName),
111      onshow: updateSelection(editor),
112      onselect: function (e) {
113        $_2gx00q7vjfuviwh8.applyListFormat(editor, nodeName, e.control.settings.data);
114      },
115      onclick: function () {
116        editor.execCommand(cmd);
117      }
118    });
119  };
120  var addButton = function (editor, id, tooltip, cmd, nodeName, styles) {
121    editor.addButton(id, {
122      active: false,
123      type: 'button',
124      tooltip: tooltip,
125      onPostRender: listState(editor, nodeName),
126      onclick: function () {
127        editor.execCommand(cmd);
128      }
129    });
130  };
131  var addControl = function (editor, id, tooltip, cmd, nodeName, styles) {
132    if (styles.length > 0) {
133      addSplitButton(editor, id, tooltip, cmd, nodeName, styles);
134    } else {
135      addButton(editor, id, tooltip, cmd, nodeName, styles);
136    }
137  };
138  var register$1 = function (editor) {
139    addControl(editor, 'numlist', 'Numbered list', 'InsertOrderedList', 'OL', $_24vhad7xjfuviwhc.getNumberStyles(editor));
140    addControl(editor, 'bullist', 'Bullet list', 'InsertUnorderedList', 'UL', $_24vhad7xjfuviwhc.getBulletStyles(editor));
141  };
142  var $_esepsw7wjfuviwha = { register: register$1 };
143
144  global.add('advlist', function (editor) {
145    var hasPlugin = function (editor, plugin) {
146      var plugins = editor.settings.plugins ? editor.settings.plugins : '';
147      return global$1.inArray(plugins.split(/[ ,]/), plugin) !== -1;
148    };
149    if (hasPlugin(editor, 'lists')) {
150      $_esepsw7wjfuviwha.register(editor);
151      $_djjlld7ujfuviwh7.register(editor);
152    }
153  });
154  function Plugin () {
155  }
156
157  return Plugin;
158
159}());
160})();