~ubuntu-branches/ubuntu/saucy/horde3/saucy

« back to all changes in this revision

Viewing changes to services/editor/htmlarea/plugins/ListType/list-type.js

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-05-04 23:08:08 UTC
  • Revision ID: james.westby@ubuntu.com-20050504230808-p4hf3hk28o3v7wir
Tags: upstream-3.0.4
ImportĀ upstreamĀ versionĀ 3.0.4

Show diffs side-by-side

added added

removed removed

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