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
            Y.log('Fix First Paragraph', 'info', 'editor-para');
37
            var host = this.get(HOST), inst = host.getInstance(), sel, n,
38
                root = this._getRoot(),
39
                html = root.getHTML(),
40
                col = ((html.length) ? true : false);
41
 
42
            if (html === BR) {
43
                html = '';
44
                col = false;
45
            }
46
 
47
            root.setHTML('<' + P + '>' + html + inst.EditorSelection.CURSOR + '</' + P + '>');
48
 
49
            n = root.one(FIRST_P);
50
            sel = new inst.EditorSelection();
51
 
52
            sel.selectNode(n, true, col);
53
        },
54
        /**
55
        * Performs a block element filter when the Editor is first ready
56
        * @private
57
        * @method _afterEditorReady
58
        */
59
        _afterEditorReady: function() {
60
            var host = this.get(HOST), inst = host.getInstance(), btag;
61
            if (inst) {
62
                inst.EditorSelection.filterBlocks();
63
                btag = inst.EditorSelection.DEFAULT_BLOCK_TAG;
64
                FIRST_P = '> ' + btag;
65
                P = btag;
66
            }
67
        },
68
        /**
69
        * Performs a block element filter when the Editor after an content change
70
        * @private
71
        * @method _afterContentChange
72
        */
73
        _afterContentChange: function() {
74
            var host = this.get(HOST), inst = host.getInstance();
75
            if (inst && inst.EditorSelection) {
76
                inst.EditorSelection.filterBlocks();
77
            }
78
        },
79
        /**
80
        * Performs block/paste filtering after paste.
81
        * @private
82
        * @method _afterPaste
83
        */
84
        _afterPaste: function() {
85
            var host = this.get(HOST), inst = host.getInstance();
86
 
87
            Y.later(50, host, function() {
88
                inst.EditorSelection.filterBlocks();
89
            });
90
 
91
        },
92
        initializer: function() {
93
            var host = this.get(HOST);
94
            if (host.editorBR) {
95
                Y.error('Can not plug EditorPara and EditorBR at the same time.');
96
                return;
97
            }
98
 
99
            host.after('ready', Y.bind(this._afterEditorReady, this));
100
            host.after('contentChange', Y.bind(this._afterContentChange, this));
101
            if (Y.Env.webkit) {
102
                host.after('dom:paste', Y.bind(this._afterPaste, this));
103
            }
104
        }
105
    }, {
106
        /**
107
        * editorPara
108
        * @static
109
        * @property NAME
110
        */
111
        NAME: 'editorParaBase',
112
        /**
113
        * editorPara
114
        * @static
115
        * @property NS
116
        */
117
        NS: 'editorParaBase',
118
        ATTRS: {
119
            host: {
120
                value: false
121
            }
122
        }
123
    });
124
 
125
    Y.namespace('Plugin');
126
 
127
    Y.Plugin.EditorParaBase = EditorParaBase;
128
 
129
 
130
 
131
 
132
}, '3.18.1', {"requires": ["editor-base"]});