3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('editor-br', function(Y) {
12
* Plugin for Editor to normalize BR's.
13
* @class Plugin.EditorBR
17
* @submodule editor-br
21
var EditorBR = function() {
22
EditorBR.superclass.constructor.apply(this, arguments);
23
}, HOST = 'host', LI = 'li';
26
Y.extend(EditorBR, Y.Base, {
28
* Frame keyDown handler that normalizes BR's when pressing ENTER.
32
_onKeyDown: function(e) {
37
if (e.keyCode == 13) {
38
var host = this.get(HOST), inst = host.getInstance(),
39
sel = new inst.EditorSelection(),
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);
51
if (!sel.anchorNode.test(LI) && !sel.anchorNode.ancestor(LI)) {
52
host.frame._execCommand('insertlinebreak', null);
60
* Adds listeners for keydown in IE and Webkit. Also fires insertbeonreturn for supporting browsers.
62
* @method _afterEditorReady
64
_afterEditorReady: function() {
65
var inst = this.get(HOST).getInstance();
67
inst.config.doc.execCommand('insertbronreturn', null, true);
70
if (Y.UA.ie || Y.UA.webkit) {
71
inst.on('keydown', Y.bind(this._onKeyDown, this), inst.config.doc);
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.
78
* @method _onNodeChange
79
* @param {Event} e The nodeChange event.
81
_onNodeChange: function(e) {
82
switch (e.changedType) {
84
case 'backspace-down':
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"
92
var inst = this.get(HOST).getInstance();
93
var d = e.changedNode;
94
var t = inst.config.doc.createTextNode(' ');
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.');
106
host.after('ready', Y.bind(this._afterEditorReady, this));
108
host.on('nodeChange', Y.bind(this._onNodeChange, this));
131
Y.namespace('Plugin');
133
Y.Plugin.EditorBR = EditorBR;
137
}, '3.5.1' ,{skinnable:false, requires:['editor-base']});