Ticket #3312: 3312.patch

File 3312.patch, 10.1 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/enterkey/plugin.js

     
    7777
    7878                var node;
    7979
    80                 // If this is a block under a list item, split it as well. (#1647)
     80                // 1. If this is a block under a list item, split it as well. (#1647)
     81                // 2. Exist the whole list if it's the last empty first-level list item. (#3312)
    8182                if ( nextBlock )
    8283                {
    8384                        node = nextBlock.getParent();
     
    9394                        range.moveToElementEditStart( previousBlock.getNext() );
    9495                        previousBlock.move( previousBlock.getPrevious() );
    9596                }
     97                else if ( ( node = previousBlock ) && node.is( 'li' )
     98                                        && node.getParent().is('ul')
     99                                        && !node.getNext()
     100                                        && !CKEDITOR.tools.trim( node.getText() ).length )
     101                {
     102                        var editableElement;
     103                        // Locate the next content edit-able element of this node.
     104                        function getNextEditableElement( node )
     105                        {
     106                                var walker = new CKEDITOR.dom.walker( node );
     107                                walker.evaluator = function( toNode ){
     108                                        return ( !!toNode.isEditable && toNode.isEditable() );
     109                                };
     110                                return walker.next();
     111                        }
     112                       
     113                        if ( editableElement = getNextEditableElement(
     114                                                ( node.getLast && node.getLast() )|| node ) )
     115                        {
     116                                editableElement.scrollIntoView();
     117                                range.moveToPosition( editableElement, CKEDITOR.POSITION_AFTER_START );
     118                                range.select();
     119                        }
    96120
     121                        return;
     122                }
    97123                // If we have both the previous and next blocks, it means that the
    98124                // boundaries were on separated blocks, or none of them where on the
    99125                // block limits (start/end).
  • _source/core/dom/element.js

     
    55
    66/**
    77 * @fileOverview Defines the {@link CKEDITOR.dom.element} class, which
    8  *              represents a DOM element.
     8 *      represents a DOM element.
    99 */
    1010
    1111/**
     
    1313 * @constructor
    1414 * @augments CKEDITOR.dom.node
    1515 * @param {Object|String} element A native DOM element or the element name for
    16  *              new elements.
     16 *      new elements.
    1717 * @param {CKEDITOR.dom.document} [ownerDocument] The document that will contain
    18  *              the element in case of element creation.
     18 *      the element in case of element creation.
    1919 * @example
    2020 * // Create a new <span> element.
    2121 * var element = new CKEDITOR.dom.element( 'span' );
     
    5757 * Creates an instance of the {@link CKEDITOR.dom.element} class based on the
    5858 * HTML representation of an element.
    5959 * @param {String} html The element HTML. It should define only one element in
    60  *              the "root" level. The "root" element can have child nodes, but not
    61  *              siblings.
     60 *      the "root" level. The "root" element can have child nodes, but not
     61 *      siblings.
    6262 * @returns {CKEDITOR.dom.element} The element instance.
    6363 * @example
    6464 * var element = <b>CKEDITOR.dom.element.createFromHtml( '&lt;strong class="anyclass"&gt;My element&lt;/strong&gt;' )</b>;
     
    176176                /**
    177177                 * Append a node as a child of this element.
    178178                 * @param {CKEDITOR.dom.node|String} node The node or element name to be
    179                  *              appended.
     179                 *      appended.
    180180                 * @param {Boolean} [toStart] Indicates that the element is to be
    181                  *              appended at the start.
     181                 *      appended at the start.
    182182                 * @returns {CKEDITOR.dom.node} The appended node.
    183183                 * @example
    184184                 * var p = new CKEDITOR.dom.element( 'p' );
     
    463463                /**
    464464                 * Gets the DTD entries for this element.
    465465                 * @returns {Object} An object containing the list of elements accepted
    466                  *              by this element.
     466                 *      by this element.
    467467                 */
    468468                getDtd : function()
    469469                {
     
    477477                        return dtd;
    478478                },
    479479
    480                 getElementsByTag : CKEDITOR.dom.document.prototype.getElementsByTag,
     480                getElementsByTag : function( tagName, namespace )
     481                {
     482                        if ( !CKEDITOR.env.ie && namespace )
     483                                tagName = namespace + ':' + tagName;
     484                        return new CKEDITOR.dom.nodeList( this.$.getElementsByTagName( tagName ) );
     485                },
    481486
    482487                /**
    483488                 * Gets the computed tabindex for this element.
     
    543548                 */
    544549                getText : function()
    545550                {
    546                         return this.$.textContent || this.$.innerText;
     551                        return ( typeof this.$.textContent != 'undefined' )?
     552                                this.$.textContent : this.$.innerText;
    547553                },
    548554
    549555                /**
     
    621627                /**
    622628                 * Gets the first child node of this element.
    623629                 * @returns {CKEDITOR.dom.node} The first child node or null if not
    624                  *              available.
     630                 *      available.
    625631                 * @example
    626632                 * var element = CKEDITOR.dom.element.createFromHtml( '&lt;div&gt;&lt;b&gt;Example&lt;/b&gt;&lt;/div&gt;' );
    627633                 * var first = <b>element.getFirst()</b>;
     
    642648                /**
    643649                 * Gets the node that follows this element in its parent's child list.
    644650                 * @returns {CKEDITOR.dom.node} The next node or null if not
    645                  *              available.
     651                 *      available.
    646652                 * @example
    647653                 * var element = CKEDITOR.dom.element.createFromHtml( '&lt;div&gt;&lt;b&gt;Example&lt;/b&gt; &lt;i&gt;next&lt;/i&gt;&lt;/div&gt;' );
    648654                 * var first = <b>element.getFirst().getNext()</b>;
     
    897903                                                this.$.className = value;
    898904                                        else if ( name == 'style' )
    899905                                                this.$.style.cssText = value;
    900                                         else if ( name == 'tabindex' )  // Case sensitive.
     906                                        else if ( name == 'tabindex' )  // Case sensitive.
    901907                                                this.$.tabIndex = value;
    902908                                        else
    903909                                                standard.apply( this, arguments );
     
    911917                /**
    912918                 * Sets the value of several element attributes.
    913919                 * @param {Object} attributesPairs An object containing the names and
    914                  *              values of the attributes.
     920                 *      values of the attributes.
    915921                 * @returns {CKEDITOR.dom.element} This element instance.
    916922                 * @example
    917923                 * var element = CKEDITOR.dom.element.getById( 'myElement' );
     
    9941000                /**
    9951001                 * Sets the value of an element style.
    9961002                 * @param {String} name The name of the style. The CSS naming notation
    997                  *              must be used (e.g. "background-color").
     1003                 *      must be used (e.g. "background-color").
    9981004                 * @param {String} value The value to be set to the style.
    9991005                 * @returns {CKEDITOR.dom.element} This element instance.
    10001006                 * @example
     
    10121018                /**
    10131019                 * Sets the value of several element styles.
    10141020                 * @param {Object} stylesPairs An object containing the names and
    1015                  *              values of the styles.
     1021                 *      values of the styles.
    10161022                 * @returns {CKEDITOR.dom.element} This element instance.
    10171023                 * @example
    10181024                 * var element = CKEDITOR.dom.element.getById( 'myElement' );
     
    11141120
    11151121                                if ( !CKEDITOR.env.opera )
    11161122                                {
    1117                                         // Opera includes clientTop|Left into offsetTop|Left.
    1118                                         if ( !current.equals( this ) )
    1119                                         {
    1120                                                 x += ( current.$.clientLeft || 0 );
    1121                                                 y += ( current.$.clientTop || 0 );
    1122                                         }
    1123 
    11241123                                        var scrollElement = previous;
    11251124                                        while ( scrollElement && !scrollElement.equals( current ) )
    11261125                                        {
     
    11481147                                }
    11491148                        }
    11501149
    1151                         var body = this.getDocument().getBody();
    1152 
    11531150                        // document.body is a special case when it comes to offsetTop and offsetLeft
    11541151                        // values.
    11551152                        // 1. It matters if document.body itself is a positioned element;
     
    11551152                        // 1. It matters if document.body itself is a positioned element;
    11561153                        // 2. It matters when we're in IE and the element has no positioned ancestor.
    11571154                        // Otherwise the values should be ignored.
    1158                         if ( body.getComputedStyle( 'position' ) != 'static' || ( CKEDITOR.env.ie && !this.getPositionedAncestor() ) )
     1155                        if ( this.getComputedStyle( 'position' ) != 'static' || ( CKEDITOR.env.ie && !this.getPositionedAncestor() ) )
    11591156                        {
    1160                                 x += body.$.offsetLeft + ( body.$.clientLeft || 0 );
    1161                                 y += body.$.offsetTop + ( body.$.clientTop || 0 );
    1162                         }
    1163 
    1164                         // In Firefox, we'll endup one pixel before the element positions,
    1165                         // so we must add it here.
    1166                         if ( CKEDITOR.env.gecko && !CKEDITOR.env.quirks )
    1167                         {
    1168                                 x += this.$.clientLeft ? 1 : 0;
    1169                                 y += this.$.clientTop ? 1 : 0;;
     1157                                x += this.getDocument().getBody().$.offsetLeft;
     1158                                y += this.getDocument().getBody().$.offsetTop;
    11701159                        }
    11711160
    11721161                        return { x : x, y : y };
     
    12601249                        }
    12611250
    12621251                        return $ && new CKEDITOR.dom.document( $.contentWindow.document );
    1263                 },
    1264 
    1265                 /**
    1266                  * Copy all the attributes from one node to the other, kinda like a clone
    1267                  * skipAttributes is an object with the attributes that must NOT be copied.
    1268                  * @param {CKEDITOR.dom.element} dest The destination element.
    1269                  * @param {Object} skipAttributes A dictionary of attributes to skip.
    1270                  * @example
    1271                  */
    1272                 copyAttributes : function( dest, skipAttributes )
    1273                 {
    1274                         var attributes = this.$.attributes;
    1275                         skipAttributes = skipAttributes || {};
    1276 
    1277                         for ( var n = 0 ; n < attributes.length ; n++ )
    1278                         {
    1279                                 var attribute = attributes[n];
    1280 
    1281                                 if ( attribute.specified )
    1282                                 {
    1283                                         var attrName = attribute.nodeName;
    1284                                         // We can set the type only once, so do it with the proper value, not copying it.
    1285                                         if ( attrName in skipAttributes )
    1286                                                 continue;
    1287 
    1288                                         var attrValue = this.getAttribute( attrName );
    1289                                         if ( attrValue === null )
    1290                                                 attrValue = attribute.nodeValue;
    1291 
    1292                                         dest.setAttribute( attrName, attrValue );
    1293                                 }
    1294                         }
    1295 
    1296                         // The style:
    1297                         if ( this.$.style.cssText !== '' )
    1298                                 dest.$.style.cssText = this.$.style.cssText;
    1299                 },
    1300 
    1301                 /**
    1302                  * Changes the tag name of the current element.
    1303                  * @param {String} newTag The new tag for the element.
    1304                  */
    1305                 renameNode : function( newTag )
    1306                 {
    1307                         // If it's already correct exit here.
    1308                         if ( this.getName() == newTag )
    1309                                 return;
    1310 
    1311                         var doc = this.getDocument();
    1312 
    1313                         // Create the new node.
    1314                         var newNode = new CKEDITOR.dom.element( newTag, doc );
    1315 
    1316                         // Copy all attributes.
    1317                         this.copyAttributes( newNode );
    1318 
    1319                         // Move children to the new node.
    1320                         this.moveChildren( newNode );
    1321 
    1322                         // Replace the node.
    1323                         this.$.parentNode.replaceChild( newNode.$, this.$ );
    1324                         newNode.$._cke_expando = this.$._cke_expando;
    1325                         this.$ = newNode.$;
    13261252                }
    13271253        });
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy