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, editor = t.editor;
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 (editor.dom.getStyle(node, name) != value) {
65 function applyListFormat() {
66 var list, dom = editor.dom, sel = editor.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 editor.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');
87 btn = cm.createSplitButton(name, {
88 title : 'advanced.' + name + '_desc',
89 'class' : 'mce_' + name,
90 onclick : function() {
95 btn.onRenderMenu.add(function(btn, menu) {
96 menu.onHideMenu.add(function() {
98 editor.selection.moveToBookmark(t.bookmark);
103 menu.onShowMenu.add(function() {
104 var dom = editor.dom, list = dom.getParent(editor.selection.getNode(), 'ol,ul'), fmtList;
106 if (list || format) {
109 // Unselect existing items
110 each(menu.items, function(item) {
115 if (list && !item.isDisabled()) {
116 each(fmtList, function(fmt) {
117 if (fmt.id == item.id) {
118 if (!hasFormat(list, fmt)) {
130 // Select the current format
132 menu.items[format.id].setSelected(1);
137 // IE looses it's selection so store it away and restore it later
139 t.bookmark = editor.selection.getBookmark(1);
143 menu.add({id : editor.dom.uniqueId(), title : 'advlist.types', 'class' : 'mceMenuItemTitle', titleItem: true}).setDisabled(1);
145 each(t[name], function(item) {
146 // IE<8 doesn't support lower-greek, skip it
147 if (t.isIE7 && item.styles.listStyleType == 'lower-greek')
150 item.id = editor.dom.uniqueId();
152 menu.add({id : item.id, title : item.title, onclick : function() {
163 getInfo : function() {
165 longname : 'Advanced lists',
166 author : 'Moxiecode Systems AB',
167 authorurl : 'http://tinymce.moxiecode.com',
168 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlist',
169 version : tinymce.majorVersion + "." + tinymce.minorVersion
175 tinymce.PluginManager.add('advlist', tinymce.plugins.AdvListPlugin);