11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass /**
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * Extends EditorParaBase with IE support
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @class Plugin.EditorParaIE
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @extends Plugin.EditorParaBase
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @constructor
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @module editor
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @submodule editor-para-ie
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass */
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass var EditorParaIE = function() {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass EditorParaIE.superclass.constructor.apply(this, arguments);
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }, HOST = 'host', BODY = 'body', NODE_CHANGE = 'nodeChange', PARENT_NODE = 'parentNode',
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass FIRST_P = BODY + ' > p', P = 'p', BR = '<br>', FC = 'firstChild', LI = 'li';
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass Y.extend(EditorParaIE, Y.Plugin.EditorParaBase, {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass /**
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * nodeChange handler to handle fixing an empty document.
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @private
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @method _onNodeChange
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass */
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass _onNodeChange: function(e) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass var host = this.get(HOST), inst = host.getInstance(),
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass html, txt, par , d, sel, btag = inst.EditorSelection.DEFAULT_BLOCK_TAG,
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass inHTML, txt2, childs, aNode, index, node2, top, n, sib,
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass ps, br, item, p, imgs, t, LAST_CHILD = ':last-child';
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass switch (e.changedType) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass case 'enter-up':
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass var para = ((this._lastPara) ? this._lastPara : e.changedNode),
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass b = para.one('br.yui-cursor');
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (this._lastPara) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass delete this._lastPara;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (b) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (b.previous() || b.next()) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (b.ancestor(P)) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass b.remove();
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (!para.test(btag)) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass var para2 = para.ancestor(btag);
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (para2) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass para = para2;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass para2 = null;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (para.test(btag)) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass var prev = para.previous(), lc, lc2, found = false;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (prev) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass lc = prev.one(LAST_CHILD);
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass while (!found) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (lc) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass lc2 = lc.one(LAST_CHILD);
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (lc2) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass lc = lc2;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass } else {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass found = true;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass } else {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass found = true;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (lc) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass host.copyStyles(lc, para);
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass break;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass case 'enter':
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (e.changedNode.test('br')) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass e.changedNode.remove();
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass } else if (e.changedNode.test('p, span')) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass var b = e.changedNode.one('br.yui-cursor');
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (b) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass b.remove();
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass break;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass },
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass initializer: function() {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass var host = this.get(HOST);
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass if (host.editorBR) {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass Y.error('Can not plug EditorPara and EditorBR at the same time.');
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass return;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass host.on(NODE_CHANGE, Y.bind(this._onNodeChange, this));
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }, {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass /**
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * editorPara
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @static
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @property NAME
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass */
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass NAME: 'editorPara',
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass /**
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * editorPara
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @static
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass * @property NS
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass */
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass NS: 'editorPara',
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass ATTRS: {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass host: {
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass value: false
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass }
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass });
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass Y.namespace('Plugin');
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass Y.Plugin.EditorPara = EditorParaIE;
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass
11472e48d0b0591b8f3753193304070c6a13cb05Dav Glass