~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/build/editor-br/editor-br-debug.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-br', function(Y) {
8
 
 
9
 
 
10
 
 
11
 
    /**
12
 
     * Plugin for Editor to normalize BR's.
13
 
     * @class Plugin.EditorBR
14
 
     * @extends Base
15
 
     * @constructor
16
 
     * @module editor
17
 
     * @submodule editor-br
18
 
     */
19
 
 
20
 
 
21
 
    var EditorBR = function() {
22
 
        EditorBR.superclass.constructor.apply(this, arguments);
23
 
    }, HOST = 'host', LI = 'li';
24
 
 
25
 
 
26
 
    Y.extend(EditorBR, Y.Base, {
27
 
        /**
28
 
        * Frame keyDown handler that normalizes BR's when pressing ENTER.
29
 
        * @private
30
 
        * @method _onKeyDown
31
 
        */
32
 
        _onKeyDown: function(e) {
33
 
            if (e.stopped) {
34
 
                e.halt();
35
 
                return;
36
 
            }
37
 
            if (e.keyCode == 13) {
38
 
                var host = this.get(HOST), inst = host.getInstance(),
39
 
                    sel = new inst.EditorSelection(),
40
 
                    last = '';
41
 
 
42
 
                if (sel) {
43
 
                    if (Y.UA.ie) {
44
 
                        if (!sel.anchorNode || (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI))) {
45
 
                            var host = this.get(HOST);
46
 
                            host.execCommand('inserthtml', inst.EditorSelection.CURSOR);
47
 
                            e.halt();
48
 
                        }
49
 
                    }
50
 
                    if (Y.UA.webkit) {
51
 
                        if (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI)) {
52
 
                            host.frame._execCommand('insertlinebreak', null);
53
 
                            e.halt();
54
 
                        }
55
 
                    }
56
 
                }
57
 
            }
58
 
        },
59
 
        /**
60
 
        * Adds listeners for keydown in IE and Webkit. Also fires insertbeonreturn for supporting browsers.
61
 
        * @private
62
 
        * @method _afterEditorReady
63
 
        */
64
 
        _afterEditorReady: function() {
65
 
            var inst = this.get(HOST).getInstance();
66
 
            try {
67
 
                inst.config.doc.execCommand('insertbronreturn', null, true);
68
 
            } catch (bre) {}
69
 
 
70
 
            if (Y.UA.ie || Y.UA.webkit) {
71
 
                inst.on('keydown', Y.bind(this._onKeyDown, this), inst.config.doc);
72
 
            }
73
 
        },
74
 
        /**
75
 
        * Adds a nodeChange listener only for FF, in the event of a backspace or delete, it creates an empy textNode
76
 
        * inserts it into the DOM after the e.changedNode, then removes it. Causing FF to redraw the content.
77
 
        * @private
78
 
        * @method _onNodeChange
79
 
        * @param {Event} e The nodeChange event.
80
 
        */
81
 
        _onNodeChange: function(e) {
82
 
            switch (e.changedType) {
83
 
                case 'backspace-up':
84
 
                case 'backspace-down':
85
 
                case 'delete-up':
86
 
                    /*
87
 
                    * This forced FF to redraw the content on backspace.
88
 
                    * On some occasions FF will leave a cursor residue after content has been deleted.
89
 
                    * Dropping in the empty textnode and then removing it causes FF to redraw and
90
 
                    * remove the "ghost cursors"
91
 
                    */
92
 
                    var inst = this.get(HOST).getInstance();
93
 
                    var d = e.changedNode;
94
 
                    var t = inst.config.doc.createTextNode(' ');
95
 
                    d.appendChild(t);
96
 
                    d.removeChild(t);
97
 
                    break;
98
 
            }
99
 
        },
100
 
        initializer: function() {
101
 
            var host = this.get(HOST);
102
 
            if (host.editorPara) {
103
 
                Y.error('Can not plug EditorBR and EditorPara at the same time.');
104
 
                return;
105
 
            }
106
 
            host.after('ready', Y.bind(this._afterEditorReady, this));
107
 
            if (Y.UA.gecko) {
108
 
                host.on('nodeChange', Y.bind(this._onNodeChange, this));
109
 
            }
110
 
        }
111
 
    }, {
112
 
        /**
113
 
        * editorBR
114
 
        * @static
115
 
        * @property NAME
116
 
        */
117
 
        NAME: 'editorBR',
118
 
        /**
119
 
        * editorBR
120
 
        * @static
121
 
        * @property NS
122
 
        */
123
 
        NS: 'editorBR',
124
 
        ATTRS: {
125
 
            host: {
126
 
                value: false
127
 
            }
128
 
        }
129
 
    });
130
 
    
131
 
    Y.namespace('Plugin');
132
 
    
133
 
    Y.Plugin.EditorBR = EditorBR;
134
 
 
135
 
 
136
 
 
137
 
}, '3.5.1' ,{skinnable:false, requires:['editor-base']});