3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('editor-para-base', function (Y, NAME) {
11
* Base Plugin for Editor to paragraph auto wrapping and correction.
12
* @class Plugin.EditorParaBase
16
* @submodule editor-para-base
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';
26
Y.extend(EditorParaBase, Y.Base, {
28
* Utility method to create an empty paragraph when the document is empty.
30
* @method _fixFirstPara
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);
43
body.innerHTML = '<' + P + '>' + html + inst.EditorSelection.CURSOR + '</' + P + '>';
45
n = inst.one(FIRST_P);
46
sel = new inst.EditorSelection();
48
sel.selectNode(n, true, col);
51
* Performs a block element filter when the Editor is first ready
53
* @method _afterEditorReady
55
_afterEditorReady: function() {
56
var host = this.get(HOST), inst = host.getInstance(), btag;
58
inst.EditorSelection.filterBlocks();
59
btag = inst.EditorSelection.DEFAULT_BLOCK_TAG;
60
FIRST_P = BODY + ' > ' + btag;
65
* Performs a block element filter when the Editor after an content change
67
* @method _afterContentChange
69
_afterContentChange: function() {
70
var host = this.get(HOST), inst = host.getInstance();
71
if (inst && inst.EditorSelection) {
72
inst.EditorSelection.filterBlocks();
76
* Performs block/paste filtering after paste.
80
_afterPaste: function() {
81
var host = this.get(HOST), inst = host.getInstance(),
82
sel = new inst.EditorSelection();
84
Y.later(50, host, function() {
85
inst.EditorSelection.filterBlocks();
89
initializer: function() {
90
var host = this.get(HOST);
92
Y.error('Can not plug EditorPara and EditorBR at the same time.');
96
host.after('ready', Y.bind(this._afterEditorReady, this));
97
host.after('contentChange', Y.bind(this._afterContentChange, this));
99
host.after('dom:paste', Y.bind(this._afterPaste, this));
108
NAME: 'editorParaBase',
114
NS: 'editorParaBase',
122
Y.namespace('Plugin');
124
Y.Plugin.EditorParaBase = EditorParaBase;
129
}, '3.7.1', {"requires": ["editor-base"]});