editor-para.js revision 7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7
31acd99497fcc9fc72f15c5553fe356d64fb9d03Matt Sweeney * Plugin for Editor to paragraph auto wrapping and correction.
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * @module editor
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * @submodule editor-para
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney * Plugin for Editor to paragraph auto wrapping and correction.
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * @class Plugin.EditorPara
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * @extends Base
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * @constructor
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney var EditorPara = function() {
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney EditorPara.superclass.constructor.apply(this, arguments);
b0614bd702ed299874c87fd5d4d48bccda498c73Matt Sweeney }, HOST = 'host', BODY = 'body', NODE_CHANGE = 'nodeChange', PARENT_NODE = 'parentNode',
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney FIRST_P = BODY + ' > p', P = 'p', BR = '<br>', FC = 'firstChild', LI = 'li';
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * Utility method to create an empty paragraph when the document is empty.
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * @method _fixFirstPara
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney var host = this.get(HOST), inst = host.getInstance(), sel;
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney inst.one('body').set('innerHTML', '<' + P + '>' + inst.Selection.CURSOR + '</' + P + '>');
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * nodeChange handler to handle fixing an empty document.
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney * @method _onNodeChange
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney var host = this.get(HOST), inst = host.getInstance(),
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney html, txt, par , d, sel, btag = inst.Selection.DEFAULT_BLOCK_TAG,
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney inHTML, txt2, childs, aNode, index, node2, top, n, sib,
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney ps, br, item, p, imgs, t, LAST_CHILD = ':last-child';
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney case 'enter-up':
ac9a31a10e6b74ccde5140bc7696b4364724dedcLuke Smith var para = ((this._lastPara) ? this._lastPara : e.changedNode),
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney var prev = para.previous(), lc, lc2, found = false;
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney case 'enter':
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney //Webkit doesn't support shift+enter as a BR, this fixes that.
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney //TODO Move this to a GECKO MODULE - Can't for the moment, requires no change to metadata (YMAIL)
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney if (Y.UA.gecko && host.get('defaultblock') !== 'p') {
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney d = inst.Node.create('<' + btag + '></' + btag + '>');
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney txt = inst.one(inst.config.doc.createTextNode(inHTML.substr(0, sel.anchorOffset)));
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney txt2 = inst.one(inst.config.doc.createTextNode(inHTML.substr(sel.anchorOffset)));
752e31b910dbf30e2b803437da522585eca28528Matt Sweeney //Get children..
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney case 'keydown':
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney if (cont && cont.length < 5 && cont.toLowerCase() == BR) {
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney case 'backspace-up':
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney case 'backspace-down':
eb2ea4a236bb9b9bc726a4ba7ed9fdef81246381Matt Sweeney case 'delete-up':
this._fixFirstPara();
p = e.changedNode;
if (p && !p.test(P)) {
p = p.ancestor(P);
if (e.changedNode) {
e.preventDefault();
d = e.changedNode;
d.appendChild(t);
d.removeChild(t);
this._lastPara = p;
_afterEditorReady: function() {
if (inst) {
P = btag;
_afterContentChange: function() {
_afterPaste: function() {
initializer: function() {
ATTRS: {
host: {
value: false