Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('editor-lists', function (Y, NAME) {
2
 
3
 
4
    /**
5
     * Handles list manipulation inside the Editor. Adds keyboard manipulation and execCommand support.
6
     * Adds overrides for the <a href="Plugin.ExecCommand.html#method_COMMANDS.insertorderedlist">insertorderedlist</a>
7
     * and <a href="Plugin.ExecCommand.html#method_COMMANDS.insertunorderedlist">insertunorderedlist</a> execCommands.
8
     * @class Plugin.EditorLists
9
     * @constructor
10
     * @extends Base
11
     * @module editor
12
     * @submodule editor-lists
13
     */
14
 
15
    var EditorLists = function() {
16
        EditorLists.superclass.constructor.apply(this, arguments);
17
    }, LI = 'li', OL = 'ol', UL = 'ul', HOST = 'host';
18
 
19
    Y.extend(EditorLists, Y.Base, {
20
        /**
21
        * Listener for host's nodeChange event and captures the tabkey interaction only when inside a list node.
22
        * @private
23
        * @method _onNodeChange
24
        * @param {Event} e The Event facade passed from the host.
25
        */
26
        _onNodeChange: function(e) {
27
            var inst = this.get(HOST).getInstance(), li,
28
                newList, sTab, par, moved = false, tag, focusEnd = false;
29
 
30
            if (e.changedType === 'tab') {
31
                if (e.changedNode.test(LI + ', ' + LI + ' *')) {
32
                    e.changedEvent.halt();
33
                    e.preventDefault();
34
                    li = e.changedNode;
35
                    sTab = e.changedEvent.shiftKey;
36
                    par = li.ancestor(OL + ',' + UL);
37
                    tag = UL;
38
 
39
                    if (par.get('tagName').toLowerCase() === OL) {
40
                        tag = OL;
41
                    }
42
 
43
                    if (!li.test(LI)) {
44
                        li = li.ancestor(LI);
45
                    }
46
                    if (sTab) {
47
                        if (li.ancestor(LI)) {
48
                            li.ancestor(LI).insert(li, 'after');
49
                            moved = true;
50
                            focusEnd = true;
51
                        }
52
                    } else {
53
                        //li.setStyle('border', '1px solid red');
54
                        if (li.previous(LI)) {
55
                            newList = inst.Node.create('<' + tag + '></' + tag + '>');
56
                            li.previous(LI).append(newList);
57
                            newList.append(li);
58
                            moved = true;
59
                        }
60
                    }
61
                }
62
                if (moved) {
63
                    if (!li.test(LI)) {
64
                        li = li.ancestor(LI);
65
                    }
66
                    li.all(EditorLists.REMOVE).remove();
67
                    if (Y.UA.ie) {
68
                        li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
69
                    }
70
                    //Selection here..
71
                    (new inst.EditorSelection()).selectNode(li, true, focusEnd);
72
                }
73
            }
74
        },
75
        initializer: function() {
76
            this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
77
        }
78
    }, {
79
        /**
80
        * The non element placeholder, used for positioning the cursor and filling empty items
81
        * @property NON
82
        * @static
83
        */
84
        NON: '<span class="yui-non">&nbsp;</span>',
85
        /**
86
        * The selector query to get all non elements
87
        * @property NONSEL
88
        * @static
89
        */
90
        NON_SEL: 'span.yui-non',
91
        /**
92
        * The items to removed from a list when a list item is moved, currently removes BR nodes
93
        * @property REMOVE
94
        * @static
95
        */
96
        REMOVE: 'br',
97
        /**
98
        * editorLists
99
        * @property NAME
100
        * @static
101
        */
102
        NAME: 'editorLists',
103
        /**
104
        * lists
105
        * @property NS
106
        * @static
107
        */
108
        NS: 'lists',
109
        ATTRS: {
110
            host: {
111
                value: false
112
            }
113
        }
114
    });
115
 
116
    Y.namespace('Plugin');
117
 
118
    Y.Plugin.EditorLists = EditorLists;
119
 
120
 
121
 
122
}, '3.18.1', {"requires": ["editor-base"]});