~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/build/editor-para-base/editor-para-base.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.5.1 (build 22)
3
 
Copyright 2012 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('editor-para-base', function(Y) {
8
 
 
9
 
 
10
 
    /**
11
 
     * Base Plugin for Editor to paragraph auto wrapping and correction.
12
 
     * @class Plugin.EditorParaBase
13
 
     * @extends Base
14
 
     * @constructor
15
 
     * @module editor
16
 
     * @submodule editor-para-base
17
 
     */
18
 
 
19
 
 
20
 
    var EditorParaBase = function() {
21
 
        EditorParaBase.superclass.constructor.apply(this, arguments);
22
 
    }, HOST = 'host', BODY = 'body', NODE_CHANGE = 'nodeChange', PARENT_NODE = 'parentNode',
23
 
    FIRST_P = BODY + ' > p', P = 'p', BR = '<br>', FC = 'firstChild', LI = 'li';
24
 
 
25
 
 
26
 
    Y.extend(EditorParaBase, Y.Base, {
27
 
        /**
28
 
        * Utility method to create an empty paragraph when the document is empty.
29
 
        * @private
30
 
        * @method _fixFirstPara
31
 
        */
32
 
        _fixFirstPara: function() {
33
 
            var host = this.get(HOST), inst = host.getInstance(), sel, n,
34
 
                body = inst.config.doc.body,
35
 
                html = body.innerHTML,
36
 
                col = ((html.length) ? true : false);
37
 
 
38
 
            if (html === BR) {
39
 
                html = '';
40
 
                col = false;
41
 
            }
42
 
 
43
 
            body.innerHTML = '<' + P + '>' + html + inst.EditorSelection.CURSOR + '</' + P + '>';
44
 
 
45
 
            n = inst.one(FIRST_P);
46
 
            sel = new inst.EditorSelection();
47
 
 
48
 
            sel.selectNode(n, true, col);
49
 
        },
50
 
        /**
51
 
        * Performs a block element filter when the Editor is first ready
52
 
        * @private
53
 
        * @method _afterEditorReady
54
 
        */
55
 
        _afterEditorReady: function() {
56
 
            var host = this.get(HOST), inst = host.getInstance(), btag;
57
 
            if (inst) {
58
 
                inst.EditorSelection.filterBlocks();
59
 
                btag = inst.EditorSelection.DEFAULT_BLOCK_TAG;
60
 
                FIRST_P = BODY + ' > ' + btag;
61
 
                P = btag;
62
 
            }
63
 
        },
64
 
        /**
65
 
        * Performs a block element filter when the Editor after an content change
66
 
        * @private
67
 
        * @method _afterContentChange
68
 
        */
69
 
        _afterContentChange: function() {
70
 
            var host = this.get(HOST), inst = host.getInstance();
71
 
            if (inst && inst.EditorSelection) {
72
 
                inst.EditorSelection.filterBlocks();
73
 
            }
74
 
        },
75
 
        /**
76
 
        * Performs block/paste filtering after paste.
77
 
        * @private
78
 
        * @method _afterPaste
79
 
        */
80
 
        _afterPaste: function() {
81
 
            var host = this.get(HOST), inst = host.getInstance(),
82
 
                sel = new inst.EditorSelection();
83
 
 
84
 
            Y.later(50, host, function() {
85
 
                inst.EditorSelection.filterBlocks();
86
 
            });
87
 
            
88
 
        },
89
 
        initializer: function() {
90
 
            var host = this.get(HOST);
91
 
            if (host.editorBR) {
92
 
                Y.error('Can not plug EditorPara and EditorBR at the same time.');
93
 
                return;
94
 
            }
95
 
 
96
 
            host.after('ready', Y.bind(this._afterEditorReady, this));
97
 
            host.after('contentChange', Y.bind(this._afterContentChange, this));
98
 
            if (Y.Env.webkit) {
99
 
                host.after('dom:paste', Y.bind(this._afterPaste, this));
100
 
            }
101
 
        }
102
 
    }, {
103
 
        /**
104
 
        * editorPara
105
 
        * @static
106
 
        * @property NAME
107
 
        */
108
 
        NAME: 'editorParaBase',
109
 
        /**
110
 
        * editorPara
111
 
        * @static
112
 
        * @property NS
113
 
        */
114
 
        NS: 'editorParaBase',
115
 
        ATTRS: {
116
 
            host: {
117
 
                value: false
118
 
            }
119
 
        }
120
 
    });
121
 
    
122
 
    Y.namespace('Plugin');
123
 
    
124
 
    Y.Plugin.EditorParaBase = EditorParaBase;
125
 
 
126
 
 
127
 
 
128
 
 
129
 
}, '3.5.1' ,{skinnable:false, requires:['editor-base']});