[2] | 1 | // ListType Plugin for HTMLArea-3.0 |
---|
| 2 | // Sponsored by MEdTech Unit - Queen's University |
---|
| 3 | // Implementation by Mihai Bazon, http://dynarch.com/mishoo/ |
---|
| 4 | // |
---|
| 5 | // (c) dynarch.com 2003. |
---|
| 6 | // Distributed under the same terms as HTMLArea itself. |
---|
| 7 | // This notice MUST stay intact for use (see license.txt). |
---|
| 8 | // |
---|
| 9 | |
---|
| 10 | function ListType(editor) { |
---|
| 11 | this.editor = editor; |
---|
| 12 | var cfg = editor.config; |
---|
| 13 | var toolbar = cfg.toolbar; |
---|
| 14 | var self = this; |
---|
| 15 | var i18n = ListType.I18N; |
---|
| 16 | var options = {}; |
---|
| 17 | options[i18n["Decimal"]] = "decimal"; |
---|
| 18 | options[i18n["Lower roman"]] = "lower-roman"; |
---|
| 19 | options[i18n["Upper roman"]] = "upper-roman"; |
---|
| 20 | options[i18n["Lower latin"]] = "lower-alpha"; |
---|
| 21 | options[i18n["Upper latin"]] = "upper-alpha"; |
---|
| 22 | if (!HTMLArea.is_ie) |
---|
| 23 | // IE doesn't support this property; even worse, it complains |
---|
| 24 | // with a gross error message when we tried to select it, |
---|
| 25 | // therefore let's hide it from the damn "browser". |
---|
| 26 | options[i18n["Lower greek"]] = "lower-greek"; |
---|
| 27 | var obj = { |
---|
| 28 | id : "ListType", |
---|
| 29 | tooltip : i18n["ListStyleTooltip"], |
---|
| 30 | options : options, |
---|
| 31 | action : function(editor) { self.onSelect(editor, this); }, |
---|
| 32 | refresh : function(editor) { self.updateValue(editor, this); }, |
---|
| 33 | context : "ol" |
---|
| 34 | }; |
---|
| 35 | cfg.registerDropdown(obj); |
---|
| 36 | var a, i, j, found = false; |
---|
| 37 | for (i = 0; !found && i < toolbar.length; ++i) { |
---|
| 38 | a = toolbar[i]; |
---|
| 39 | for (j = 0; j < a.length; ++j) { |
---|
| 40 | if (a[j] == "unorderedlist") { |
---|
| 41 | found = true; |
---|
| 42 | break; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | if (found) |
---|
| 47 | a.splice(j, 0, "space", "ListType", "space"); |
---|
| 48 | }; |
---|
| 49 | |
---|
| 50 | ListType._pluginInfo = { |
---|
| 51 | name : "ListType", |
---|
| 52 | version : "1.0", |
---|
| 53 | developer : "Mihai Bazon", |
---|
| 54 | developer_url : "http://dynarch.com/mishoo/", |
---|
| 55 | c_owner : "dynarch.com", |
---|
| 56 | sponsor : "MEdTech Unit - Queen's University", |
---|
| 57 | sponsor_url : "http://www.queensu.ca/", |
---|
| 58 | license : "htmlArea" |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | ListType.prototype.onSelect = function(editor, combo) { |
---|
| 62 | var tbobj = editor._toolbarObjects[combo.id].element; |
---|
| 63 | var parent = editor.getParentElement(); |
---|
| 64 | while (!/^ol$/i.test(parent.tagName)) { |
---|
| 65 | parent = parent.parentNode; |
---|
| 66 | } |
---|
| 67 | parent.style.listStyleType = tbobj.value; |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | ListType.prototype.updateValue = function(editor, combo) { |
---|
| 71 | var tbobj = editor._toolbarObjects[combo.id].element; |
---|
| 72 | var parent = editor.getParentElement(); |
---|
| 73 | while (parent && !/^ol$/i.test(parent.tagName)) { |
---|
| 74 | parent = parent.parentNode; |
---|
| 75 | } |
---|
| 76 | if (!parent) { |
---|
| 77 | tbobj.selectedIndex = 0; |
---|
| 78 | return; |
---|
| 79 | } |
---|
| 80 | var type = parent.style.listStyleType; |
---|
| 81 | if (!type) { |
---|
| 82 | tbobj.selectedIndex = 0; |
---|
| 83 | } else { |
---|
| 84 | for (var i = tbobj.firstChild; i; i = i.nextSibling) { |
---|
| 85 | i.selected = (type.indexOf(i.value) != -1); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | }; |
---|