4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
11 /*global tinymce:true */
13 tinymce.PluginManager.add('advlist', function(editor) {
14 var olMenuItems, ulMenuItems, lastStyles = {};
16 function buildMenuItems(listName, styleValues) {
19 tinymce.each(styleValues.split(/[ ,]/), function(styleValue) {
21 text: styleValue.replace(/\-/g, ' ').replace(/\b\w/g, function(chr) {return chr.toUpperCase();}),
22 data: styleValue == 'default' ? '' : styleValue
29 olMenuItems = buildMenuItems('OL', editor.getParam(
30 "advlist_number_styles",
31 "default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman"
34 ulMenuItems = buildMenuItems('UL', editor.getParam("advlist_bullet_styles", "default,circle,disc,square"));
36 function applyListFormat(listName, styleValue) {
37 var list, dom = editor.dom, sel = editor.selection;
39 // Check for existing list element
40 list = dom.getParent(sel.getNode(), 'ol,ul');
42 // Switch/add list type if needed
43 if (!list || list.nodeName != listName || styleValue === false) {
44 editor.execCommand(listName == 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList');
48 styleValue = styleValue === false ? lastStyles[listName] : styleValue;
49 lastStyles[listName] = styleValue;
51 list = dom.getParent(sel.getNode(), 'ol,ul');
53 dom.setStyle(list, 'listStyleType', styleValue);
54 list.removeAttribute('data-mce-style');
60 function updateSelection(e) {
61 var listStyleType = editor.dom.getStyle(editor.dom.getParent(editor.selection.getNode(), 'ol,ul'), 'listStyleType') || '';
63 e.control.items().each(function(ctrl) {
64 ctrl.active(ctrl.settings.data === listStyleType);
68 editor.addButton('numlist', {
70 tooltip: 'Numbered list',
72 onshow: updateSelection,
73 onselect: function(e) {
74 applyListFormat('OL', e.control.settings.data);
77 applyListFormat('OL', false);
81 editor.addButton('bullist', {
83 tooltip: 'Bullet list',
85 onshow: updateSelection,
86 onselect: function(e) {
87 applyListFormat('UL', e.control.settings.data);
90 applyListFormat('UL', false);