Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('editor-para-ie', function (Y, NAME) {
2
 
3
 
4
    /**
5
     * Extends EditorParaBase with IE support
6
     * @class Plugin.EditorParaIE
7
     * @extends Plugin.EditorParaBase
8
     * @constructor
9
     * @module editor
10
     * @submodule editor-para-ie
11
     */
12
 
13
 
14
    var EditorParaIE = function() {
15
        EditorParaIE.superclass.constructor.apply(this, arguments);
16
    }, HOST = 'host', NODE_CHANGE = 'nodeChange',
17
    P = 'p';
18
 
19
 
20
    Y.extend(EditorParaIE, Y.Plugin.EditorParaBase, {
21
        /**
22
        * Resolves the ROOT editor element.
23
        * @method _getRoot
24
        * @private
25
        */
26
        _getRoot: function() {
27
            return this.get(HOST).getInstance().EditorSelection.ROOT;
28
        },
29
 
30
        /**
31
        * nodeChange handler to handle fixing an empty document.
32
        * @private
33
        * @method _onNodeChange
34
        */
35
        _onNodeChange: function(e) {
36
            var host = this.get(HOST), inst = host.getInstance(),
37
                btag = inst.EditorSelection.DEFAULT_BLOCK_TAG,
38
                prev, LAST_CHILD = ':last-child', para, b, para2,
39
                lc, lc2, found = false;
40
 
41
            switch (e.changedType) {
42
                case 'enter-up':
43
                    para = ((this._lastPara) ? this._lastPara : e.changedNode);
44
                    b = para.one('br.yui-cursor');
45
 
46
                    if (this._lastPara) {
47
                        delete this._lastPara;
48
                    }
49
 
50
                    if (b) {
51
                        if (b.previous() || b.next()) {
52
                            if (b.ancestor(P)) {
53
                                b.remove();
54
                            }
55
                        }
56
                    }
57
                    if (!para.test(btag)) {
58
                        para2 = para.ancestor(btag);
59
                        if (para2) {
60
                            para = para2;
61
                            para2 = null;
62
                        }
63
                    }
64
                    if (para.test(btag)) {
65
                        prev = para.previous();
66
                        if (prev) {
67
                            lc = prev.one(LAST_CHILD);
68
                            while (!found) {
69
                                if (lc) {
70
                                    lc2 = lc.one(LAST_CHILD);
71
                                    if (lc2) {
72
                                        lc = lc2;
73
                                    } else {
74
                                        found = true;
75
                                    }
76
                                } else {
77
                                    found = true;
78
                                }
79
                            }
80
                            if (lc) {
81
                                host.copyStyles(lc, para);
82
                            }
83
                        }
84
                    }
85
                    break;
86
                case 'enter':
87
                    if (e.changedNode.test('br')) {
88
                        e.changedNode.remove();
89
                    } else if (e.changedNode.test('p, span')) {
90
                        b = e.changedNode.one('br.yui-cursor');
91
                        if (b) {
92
                            b.remove();
93
                        }
94
                    }
95
                    break;
96
            }
97
        },
98
        initializer: function() {
99
            var host = this.get(HOST);
100
            if (host.editorBR) {
101
                Y.error('Can not plug EditorPara and EditorBR at the same time.');
102
                return;
103
            }
104
 
105
            host.on(NODE_CHANGE, Y.bind(this._onNodeChange, this));
106
        }
107
    }, {
108
        /**
109
        * editorPara
110
        * @static
111
        * @property NAME
112
        */
113
        NAME: 'editorPara',
114
        /**
115
        * editorPara
116
        * @static
117
        * @property NS
118
        */
119
        NS: 'editorPara',
120
        ATTRS: {
121
            host: {
122
                value: false
123
            }
124
        }
125
    });
126
 
127
    Y.namespace('Plugin');
128
 
129
    Y.Plugin.EditorPara = EditorParaIE;
130
 
131
 
132
 
133
 
134
}, '3.18.1', {"requires": ["editor-para-base"]});