Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('editor-para-base', function (Y, NAME) {
2
 
3
 
4
    /**
5
     * Base Plugin for Editor to paragraph auto wrapping and correction.
6
     * @class Plugin.EditorParaBase
7
     * @extends Base
8
     * @constructor
9
     * @module editor
10
     * @submodule editor-para-base
11
     */
12
 
13
 
14
    var EditorParaBase = function() {
15
        EditorParaBase.superclass.constructor.apply(this, arguments);
16
    }, HOST = 'host',
17
    FIRST_P = '> p', P = 'p', BR = '<br>';
18
 
19
 
20
    Y.extend(EditorParaBase, Y.Base, {
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
        * Utility method to create an empty paragraph when the document is empty.
32
        * @private
33
        * @method _fixFirstPara
34
        */
35
        _fixFirstPara: function() {
36
            var host = this.get(HOST), inst = host.getInstance(), sel, n,
37
                root = this._getRoot(),
38
                html = root.getHTML(),
39
                col = ((html.length) ? true : false);
40
 
41
            if (html === BR) {
42
                html = '';
43
                col = false;
44
            }
45
 
46
            root.setHTML('<' + P + '>' + html + inst.EditorSelection.CURSOR + '</' + P + '>');
47
 
48
            n = root.one(FIRST_P);
49
            sel = new inst.EditorSelection();
50
 
51
            sel.selectNode(n, true, col);
52
        },
53
        /**
54
        * Performs a block element filter when the Editor is first ready
55
        * @private
56
        * @method _afterEditorReady
57
        */
58
        _afterEditorReady: function() {
59
            var host = this.get(HOST), inst = host.getInstance(), btag;
60
            if (inst) {
61
                inst.EditorSelection.filterBlocks();
62
                btag = inst.EditorSelection.DEFAULT_BLOCK_TAG;
63
                FIRST_P = '> ' + btag;
64
                P = btag;
65
            }
66
        },
67
        /**
68
        * Performs a block element filter when the Editor after an content change
69
        * @private
70
        * @method _afterContentChange
71
        */
72
        _afterContentChange: function() {
73
            var host = this.get(HOST), inst = host.getInstance();
74
            if (inst && inst.EditorSelection) {
75
                inst.EditorSelection.filterBlocks();
76
            }
77
        },
78
        /**
79
        * Performs block/paste filtering after paste.
80
        * @private
81
        * @method _afterPaste
82
        */
83
        _afterPaste: function() {
84
            var host = this.get(HOST), inst = host.getInstance();
85
 
86
            Y.later(50, host, function() {
87
                inst.EditorSelection.filterBlocks();
88
            });
89
 
90
        },
91
        initializer: function() {
92
            var host = this.get(HOST);
93
            if (host.editorBR) {
94
                Y.error('Can not plug EditorPara and EditorBR at the same time.');
95
                return;
96
            }
97
 
98
            host.after('ready', Y.bind(this._afterEditorReady, this));
99
            host.after('contentChange', Y.bind(this._afterContentChange, this));
100
            if (Y.Env.webkit) {
101
                host.after('dom:paste', Y.bind(this._afterPaste, this));
102
            }
103
        }
104
    }, {
105
        /**
106
        * editorPara
107
        * @static
108
        * @property NAME
109
        */
110
        NAME: 'editorParaBase',
111
        /**
112
        * editorPara
113
        * @static
114
        * @property NS
115
        */
116
        NS: 'editorParaBase',
117
        ATTRS: {
118
            host: {
119
                value: false
120
            }
121
        }
122
    });
123
 
124
    Y.namespace('Plugin');
125
 
126
    Y.Plugin.EditorParaBase = EditorParaBase;
127
 
128
 
129
 
130
 
131
}, '3.18.1', {"requires": ["editor-base"]});