[4829] | 1 | /**
|
---|
| 2 | * editor_plugin_src.js
|
---|
| 3 | *
|
---|
| 4 | * Copyright 2009, Moxiecode Systems AB
|
---|
| 5 | * Released under LGPL License.
|
---|
| 6 | *
|
---|
| 7 | * License: http://tinymce.moxiecode.com/license
|
---|
| 8 | * Contributing: http://tinymce.moxiecode.com/contributing
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | (function() {
|
---|
| 12 | var each = tinymce.each;
|
---|
| 13 |
|
---|
| 14 | tinymce.create('tinymce.plugins.AdvListPlugin', {
|
---|
| 15 | init : function(ed, url) {
|
---|
| 16 | var t = this;
|
---|
| 17 |
|
---|
| 18 | t.editor = ed;
|
---|
| 19 |
|
---|
| 20 | function buildFormats(str) {
|
---|
| 21 | var formats = [];
|
---|
| 22 |
|
---|
| 23 | each(str.split(/,/), function(type) {
|
---|
| 24 | formats.push({
|
---|
| 25 | title : 'advlist.' + (type == 'default' ? 'def' : type.replace(/-/g, '_')),
|
---|
| 26 | styles : {
|
---|
| 27 | listStyleType : type == 'default' ? '' : type
|
---|
| 28 | }
|
---|
| 29 | });
|
---|
| 30 | });
|
---|
| 31 |
|
---|
| 32 | return formats;
|
---|
| 33 | };
|
---|
| 34 |
|
---|
| 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");
|
---|
| 38 |
|
---|
| 39 | if (tinymce.isIE && /MSIE [2-7]/.test(navigator.userAgent))
|
---|
| 40 | t.isIE7 = true;
|
---|
| 41 | },
|
---|
| 42 |
|
---|
| 43 | createControl: function(name, cm) {
|
---|
| 44 | var t = this, btn, format;
|
---|
| 45 |
|
---|
| 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')
|
---|
| 49 | format = t[name][0];
|
---|
| 50 |
|
---|
| 51 | function hasFormat(node, format) {
|
---|
| 52 | var state = true;
|
---|
| 53 |
|
---|
| 54 | each(format.styles, function(value, name) {
|
---|
| 55 | // Format doesn't match
|
---|
| 56 | if (t.editor.dom.getStyle(node, name) != value) {
|
---|
| 57 | state = false;
|
---|
| 58 | return false;
|
---|
| 59 | }
|
---|
| 60 | });
|
---|
| 61 |
|
---|
| 62 | return state;
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | function applyListFormat() {
|
---|
| 66 | var list, ed = t.editor, dom = ed.dom, sel = ed.selection;
|
---|
| 67 |
|
---|
| 68 | // Check for existing list element
|
---|
| 69 | list = dom.getParent(sel.getNode(), 'ol,ul');
|
---|
| 70 |
|
---|
| 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');
|
---|
| 74 |
|
---|
| 75 | // Append styles to new list element
|
---|
| 76 | if (format) {
|
---|
| 77 | list = dom.getParent(sel.getNode(), 'ol,ul');
|
---|
| 78 | if (list) {
|
---|
| 79 | dom.setStyles(list, format.styles);
|
---|
| 80 | list.removeAttribute('data-mce-style');
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | ed.focus();
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | btn = cm.createSplitButton(name, {
|
---|
| 87 | title : 'advanced.' + name + '_desc',
|
---|
| 88 | 'class' : 'mce_' + name,
|
---|
| 89 | onclick : function() {
|
---|
| 90 | applyListFormat();
|
---|
| 91 | }
|
---|
| 92 | });
|
---|
| 93 |
|
---|
| 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;
|
---|
| 97 |
|
---|
| 98 | if (list || format) {
|
---|
| 99 | fmtList = t[name];
|
---|
| 100 |
|
---|
| 101 | // Unselect existing items
|
---|
| 102 | each(menu.items, function(item) {
|
---|
| 103 | var state = true;
|
---|
| 104 |
|
---|
| 105 | item.setSelected(0);
|
---|
| 106 |
|
---|
| 107 | if (list && !item.isDisabled()) {
|
---|
| 108 | each(fmtList, function(fmt) {
|
---|
| 109 | if (fmt.id == item.id) {
|
---|
| 110 | if (!hasFormat(list, fmt)) {
|
---|
| 111 | state = false;
|
---|
| 112 | return false;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | });
|
---|
| 116 |
|
---|
| 117 | if (state)
|
---|
| 118 | item.setSelected(1);
|
---|
| 119 | }
|
---|
| 120 | });
|
---|
| 121 |
|
---|
| 122 | // Select the current format
|
---|
| 123 | if (!list)
|
---|
| 124 | menu.items[format.id].setSelected(1);
|
---|
| 125 | }
|
---|
| 126 | });
|
---|
| 127 |
|
---|
| 128 | menu.add({id : t.editor.dom.uniqueId(), title : 'advlist.types', 'class' : 'mceMenuItemTitle', titleItem: true}).setDisabled(1);
|
---|
| 129 |
|
---|
| 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')
|
---|
| 133 | return;
|
---|
| 134 |
|
---|
| 135 | item.id = t.editor.dom.uniqueId();
|
---|
| 136 |
|
---|
| 137 | menu.add({id : item.id, title : item.title, onclick : function() {
|
---|
| 138 | format = item;
|
---|
| 139 | applyListFormat();
|
---|
| 140 | }});
|
---|
| 141 | });
|
---|
| 142 | });
|
---|
| 143 |
|
---|
| 144 | return btn;
|
---|
| 145 | }
|
---|
| 146 | },
|
---|
| 147 |
|
---|
| 148 | getInfo : function() {
|
---|
| 149 | return {
|
---|
| 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
|
---|
| 155 | };
|
---|
| 156 | }
|
---|
| 157 | });
|
---|
| 158 |
|
---|
| 159 | // Register plugin
|
---|
| 160 | tinymce.PluginManager.add('advlist', tinymce.plugins.AdvListPlugin);
|
---|
| 161 | })(); |
---|