4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 var each = tinymce.each;
14 tinymce.create('tinymce.plugins.AdvListPlugin', {
15 init : function(ed, url) {
20 function buildFormats(str) {
23 each(str.split(/,/), function(type) {
25 title : 'advlist.' + (type == 'default' ? 'def' : type.replace(/-/g, '_')),
27 listStyleType : type == 'default' ? '' : type
35 // Setup number formats from config or default
36 t.numlist = ed.getParam("advlist_number_styles") || buildFormats("default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman");
37 t.bullist = ed.getParam("advlist_bullet_styles") || buildFormats("default,circle,disc,square");
39 if (tinymce.isIE && /MSIE [2-7]/.test(navigator.userAgent))
43 createControl: function(name, cm) {
44 var t = this, btn, format;
46 if (name == 'numlist' || name == 'bullist') {
47 // Default to first item if it's a default item
48 if (t[name][0].title == 'advlist.def')
51 function hasFormat(node, format) {
54 each(format.styles, function(value, name) {
55 // Format doesn't match
56 if (t.editor.dom.getStyle(node, name) != value) {
65 function applyListFormat() {
66 var list, ed = t.editor, dom = ed.dom, sel = ed.selection;
68 // Check for existing list element
69 list = dom.getParent(sel.getNode(), 'ol,ul');
71 // Switch/add list type if needed
72 if (!list || list.nodeName == (name == 'bullist' ? 'OL' : 'UL') || hasFormat(list, format))
73 ed.execCommand(name == 'bullist' ? 'InsertUnorderedList' : 'InsertOrderedList');
75 // Append styles to new list element
77 list = dom.getParent(sel.getNode(), 'ol,ul');
79 dom.setStyles(list, format.styles);
80 list.removeAttribute('data-mce-style');
86 btn = cm.createSplitButton(name, {
87 title : 'advanced.' + name + '_desc',
88 'class' : 'mce_' + name,
89 onclick : function() {
94 btn.onRenderMenu.add(function(btn, menu) {
95 menu.onShowMenu.add(function() {
96 var dom = t.editor.dom, list = dom.getParent(t.editor.selection.getNode(), 'ol,ul'), fmtList;
101 // Unselect existing items
102 each(menu.items, function(item) {
107 if (list && !item.isDisabled()) {
108 each(fmtList, function(fmt) {
109 if (fmt.id == item.id) {
110 if (!hasFormat(list, fmt)) {
122 // Select the current format
124 menu.items[format.id].setSelected(1);
128 menu.add({id : t.editor.dom.uniqueId(), title : 'advlist.types', 'class' : 'mceMenuItemTitle', titleItem: true}).setDisabled(1);
130 each(t[name], function(item) {
131 // IE<8 doesn't support lower-greek, skip it
132 if (t.isIE7 && item.styles.listStyleType == 'lower-greek')
135 item.id = t.editor.dom.uniqueId();
137 menu.add({id : item.id, title : item.title, onclick : function() {
148 getInfo : function() {
150 longname : 'Advanced lists',
151 author : 'Moxiecode Systems AB',
152 authorurl : 'http://tinymce.moxiecode.com',
153 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlist',
154 version : tinymce.majorVersion + "." + tinymce.minorVersion
160 tinymce.PluginManager.add('advlist', tinymce.plugins.AdvListPlugin);