1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-22 14:49:42 +02:00
documize/gui/public/tinymce/plugins/advlist/plugin.js

161 lines
5.4 KiB
JavaScript
Raw Normal View History

2017-12-09 12:42:35 +00:00
(function () {
2018-01-19 11:36:38 +00:00
var advlist = (function () {
'use strict';
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
var PluginManager = tinymce.util.Tools.resolve('tinymce.PluginManager');
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
var Tools = tinymce.util.Tools.resolve('tinymce.util.Tools');
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
var applyListFormat = function (editor, listName, styleValue) {
var cmd = listName === 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList';
editor.execCommand(cmd, false, styleValue === false ? null : { 'list-style-type': styleValue });
2017-12-09 12:42:35 +00:00
};
2018-01-19 11:36:38 +00:00
var $_fgd6b27ejcg89bwx = { applyListFormat: applyListFormat };
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
var register = function (editor) {
editor.addCommand('ApplyUnorderedListStyle', function (ui, value) {
$_fgd6b27ejcg89bwx.applyListFormat(editor, 'UL', value['list-style-type']);
});
editor.addCommand('ApplyOrderedListStyle', function (ui, value) {
$_fgd6b27ejcg89bwx.applyListFormat(editor, 'OL', value['list-style-type']);
});
};
var $_fabi5n7djcg89bww = { register: register };
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
var getNumberStyles = function (editor) {
var styles = editor.getParam('advlist_number_styles', 'default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman');
return styles ? styles.split(/[ ,]/) : [];
};
var getBulletStyles = function (editor) {
var styles = editor.getParam('advlist_bullet_styles', 'default,circle,disc,square');
return styles ? styles.split(/[ ,]/) : [];
};
var $_9ljaou7gjcg89bx3 = {
getNumberStyles: getNumberStyles,
getBulletStyles: getBulletStyles
};
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
var isChildOfBody = function (editor, elm) {
return editor.$.contains(editor.getBody(), elm);
};
var isTableCellNode = function (node) {
return node && /^(TH|TD)$/.test(node.nodeName);
};
var isListNode = function (editor) {
return function (node) {
return node && /^(OL|UL|DL)$/.test(node.nodeName) && isChildOfBody(editor, node);
2017-12-09 12:42:35 +00:00
};
2018-01-19 11:36:38 +00:00
};
var getSelectedStyleType = function (editor) {
var listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul');
return editor.dom.getStyle(listElm, 'listStyleType') || '';
};
var $_38j4eu7hjcg89bx5 = {
isTableCellNode: isTableCellNode,
isListNode: isListNode,
getSelectedStyleType: getSelectedStyleType
};
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
var styleValueToText = function (styleValue) {
return styleValue.replace(/\-/g, ' ').replace(/\b\w/g, function (chr) {
return chr.toUpperCase();
});
};
var toMenuItems = function (styles) {
return Tools.map(styles, function (styleValue) {
var text = styleValueToText(styleValue);
var data = styleValue === 'default' ? '' : styleValue;
return {
text: text,
data: data
2017-12-09 12:42:35 +00:00
};
2018-01-19 11:36:38 +00:00
});
};
var $_eoq93e7ijcg89bx7 = { toMenuItems: toMenuItems };
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
var findIndex = function (list, predicate) {
for (var index = 0; index < list.length; index++) {
var element = list[index];
if (predicate(element)) {
return index;
2017-12-09 12:42:35 +00:00
}
2018-01-19 11:36:38 +00:00
}
return -1;
};
var listState = function (editor, listName) {
return function (e) {
var ctrl = e.control;
editor.on('NodeChange', function (e) {
var tableCellIndex = findIndex(e.parents, $_38j4eu7hjcg89bx5.isTableCellNode);
var parents = tableCellIndex !== -1 ? e.parents.slice(0, tableCellIndex) : e.parents;
var lists = Tools.grep(parents, $_38j4eu7hjcg89bx5.isListNode(editor));
ctrl.active(lists.length > 0 && lists[0].nodeName === listName);
2017-12-09 12:42:35 +00:00
});
};
2018-01-19 11:36:38 +00:00
};
var updateSelection = function (editor) {
return function (e) {
var listStyleType = $_38j4eu7hjcg89bx5.getSelectedStyleType(editor);
e.control.items().each(function (ctrl) {
ctrl.active(ctrl.settings.data === listStyleType);
2017-12-09 12:42:35 +00:00
});
};
2018-01-19 11:36:38 +00:00
};
var addSplitButton = function (editor, id, tooltip, cmd, nodeName, styles) {
editor.addButton(id, {
active: false,
type: 'splitbutton',
tooltip: tooltip,
menu: $_eoq93e7ijcg89bx7.toMenuItems(styles),
onPostRender: listState(editor, nodeName),
onshow: updateSelection(editor),
onselect: function (e) {
$_fgd6b27ejcg89bwx.applyListFormat(editor, nodeName, e.control.settings.data);
},
onclick: function () {
editor.execCommand(cmd);
2017-12-09 12:42:35 +00:00
}
2018-01-19 11:36:38 +00:00
});
};
var addButton = function (editor, id, tooltip, cmd, nodeName, styles) {
editor.addButton(id, {
active: false,
type: 'button',
tooltip: tooltip,
onPostRender: listState(editor, nodeName),
onclick: function () {
editor.execCommand(cmd);
}
});
};
var addControl = function (editor, id, tooltip, cmd, nodeName, styles) {
if (styles.length > 0) {
addSplitButton(editor, id, tooltip, cmd, nodeName, styles);
} else {
addButton(editor, id, tooltip, cmd, nodeName, styles);
}
};
var register$1 = function (editor) {
addControl(editor, 'numlist', 'Numbered list', 'InsertOrderedList', 'OL', $_9ljaou7gjcg89bx3.getNumberStyles(editor));
addControl(editor, 'bullist', 'Bullet list', 'InsertUnorderedList', 'UL', $_9ljaou7gjcg89bx3.getBulletStyles(editor));
};
var $_awfr1d7fjcg89bwz = { register: register$1 };
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
PluginManager.add('advlist', function (editor) {
var hasPlugin = function (editor, plugin) {
var plugins = editor.settings.plugins ? editor.settings.plugins : '';
return Tools.inArray(plugins.split(/[ ,]/), plugin) !== -1;
2017-12-09 12:42:35 +00:00
};
2018-01-19 11:36:38 +00:00
if (hasPlugin(editor, 'lists')) {
$_awfr1d7fjcg89bwz.register(editor);
$_fabi5n7djcg89bww.register(editor);
}
});
var Plugin = function () {
};
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
return Plugin;
2017-12-09 12:42:35 +00:00
2018-01-19 11:36:38 +00:00
}());
})()