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/
8 YUI.add('editor-br', function (Y, NAME) {
13 * Plugin for Editor to normalize BR's.
14 * @class Plugin.EditorBR
18 * @submodule editor-br
22 var EditorBR = function() {
23 EditorBR.superclass.constructor.apply(this, arguments);
24 }, HOST = 'host', LI = 'li';
27 Y.extend(EditorBR, Y.Base, {
29 * Frame keyDown handler that normalizes BR's when pressing ENTER.
33 _onKeyDown: function(e) {
38 if (e.keyCode === 13) {
39 var host = this.get(HOST), inst = host.getInstance(),
40 sel = new inst.EditorSelection();
44 if (!sel.anchorNode || (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI))) {
45 host.execCommand('inserthtml', inst.EditorSelection.CURSOR);
50 if (!sel.anchorNode || (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI))) {
51 host.frame._execCommand('insertlinebreak', null);
59 * Adds listeners for keydown in IE and Webkit. Also fires insertbeonreturn for supporting browsers.
61 * @method _afterEditorReady
63 _afterEditorReady: function() {
64 var inst = this.get(HOST).getInstance(),
68 inst.config.doc.execCommand('insertbronreturn', null, true);
71 if (Y.UA.ie || Y.UA.webkit) {
72 container = inst.EditorSelection.ROOT;
74 if (container.test('body')) {
75 container = inst.config.doc;
78 inst.on('keydown', Y.bind(this._onKeyDown, this), container);
82 * Adds a nodeChange listener only for FF, in the event of a backspace or delete, it creates an empy textNode
83 * inserts it into the DOM after the e.changedNode, then removes it. Causing FF to redraw the content.
85 * @method _onNodeChange
86 * @param {Event} e The nodeChange event.
88 _onNodeChange: function(e) {
89 switch (e.changedType) {
91 case 'backspace-down':
94 * This forced FF to redraw the content on backspace.
95 * On some occasions FF will leave a cursor residue after content has been deleted.
96 * Dropping in the empty textnode and then removing it causes FF to redraw and
97 * remove the "ghost cursors"
99 var inst = this.get(HOST).getInstance(),
101 t = inst.config.doc.createTextNode(' ');
107 initializer: function() {
108 var host = this.get(HOST);
109 if (host.editorPara) {
110 Y.error('Can not plug EditorBR and EditorPara at the same time.');
113 host.after('ready', Y.bind(this._afterEditorReady, this));
115 host.on('nodeChange', Y.bind(this._onNodeChange, this));
138 Y.namespace('Plugin');
140 Y.Plugin.EditorBR = EditorBR;
144 }, '3.13.0', {"requires": ["editor-base"]});