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
                    Y.log('Overriding TAB to move lists around', 'info', 'editorLists');
33
                    e.changedEvent.halt();
34
                    e.preventDefault();
35
                    li = e.changedNode;
36
                    sTab = e.changedEvent.shiftKey;
37
                    par = li.ancestor(OL + ',' + UL);
38
                    tag = UL;
39
 
40
                    if (par.get('tagName').toLowerCase() === OL) {
41
                        tag = OL;
42
                    }
43
                    Y.log('ShiftKey: ' + sTab, 'info', 'editorLists');
44
 
45
                    if (!li.test(LI)) {
46
                        li = li.ancestor(LI);
47
                    }
48
                    if (sTab) {
49
                        if (li.ancestor(LI)) {
50
                            Y.log('Shifting list up one level', 'info', 'editorLists');
51
                            li.ancestor(LI).insert(li, 'after');
52
                            moved = true;
53
                            focusEnd = true;
54
                        }
55
                    } else {
56
                        //li.setStyle('border', '1px solid red');
57
                        if (li.previous(LI)) {
58
                            Y.log('Shifting list down one level', 'info', 'editorLists');
59
                            newList = inst.Node.create('<' + tag + '></' + tag + '>');
60
                            li.previous(LI).append(newList);
61
                            newList.append(li);
62
                            moved = true;
63
                        }
64
                    }
65
                }
66
                if (moved) {
67
                    if (!li.test(LI)) {
68
                        li = li.ancestor(LI);
69
                    }
70
                    li.all(EditorLists.REMOVE).remove();
71
                    if (Y.UA.ie) {
72
                        li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
73
                    }
74
                    //Selection here..
75
                    Y.log('Selecting the new node', 'info', 'editorLists');
76
                    (new inst.EditorSelection()).selectNode(li, true, focusEnd);
77
                }
78
            }
79
        },
80
        initializer: function() {
81
            this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
82
        }
83
    }, {
84
        /**
85
        * The non element placeholder, used for positioning the cursor and filling empty items
86
        * @property NON
87
        * @static
88
        */
89
        NON: '<span class="yui-non">&nbsp;</span>',
90
        /**
91
        * The selector query to get all non elements
92
        * @property NONSEL
93
        * @static
94
        */
95
        NON_SEL: 'span.yui-non',
96
        /**
97
        * The items to removed from a list when a list item is moved, currently removes BR nodes
98
        * @property REMOVE
99
        * @static
100
        */
101
        REMOVE: 'br',
102
        /**
103
        * editorLists
104
        * @property NAME
105
        * @static
106
        */
107
        NAME: 'editorLists',
108
        /**
109
        * lists
110
        * @property NS
111
        * @static
112
        */
113
        NS: 'lists',
114
        ATTRS: {
115
            host: {
116
                value: false
117
            }
118
        }
119
    });
120
 
121
    Y.namespace('Plugin');
122
 
123
    Y.Plugin.EditorLists = EditorLists;
124
 
125
 
126
 
127
}, '3.18.1', {"requires": ["editor-base"]});