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