X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Flist%2Fplugin.js;h=0b61c2d7f06329e23ceab83aa824db17196b26d5;hp=b0d5e8cf63103dd8f58b52da3e361eb19b99c780;hb=039a051ccf3901311661022a30afd60fc38130c9;hpb=c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7 diff --git a/_source/plugins/list/plugin.js b/_source/plugins/list/plugin.js index b0d5e8c..0b61c2d 100644 --- a/_source/plugins/list/plugin.js +++ b/_source/plugins/list/plugin.js @@ -80,19 +80,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license indentLevel = Math.max( listArray[ baseIndex ].indent, 0 ), currentListItem = null, paragraphName = ( paragraphMode == CKEDITOR.ENTER_P ? 'p' : 'div' ); - while ( true ) + while ( 1 ) { var item = listArray[ currentIndex ]; if ( item.indent == indentLevel ) { if ( !rootNode || listArray[ currentIndex ].parent.getName() != rootNode.getName() ) { - rootNode = listArray[ currentIndex ].parent.clone( false, true ); + rootNode = listArray[ currentIndex ].parent.clone( false, 1 ); retval.append( rootNode ); } - currentListItem = rootNode.append( item.element.clone( false, true ) ); + currentListItem = rootNode.append( item.element.clone( 0, 1 ) ); for ( var i = 0 ; i < item.contents.length ; i++ ) - currentListItem.append( item.contents[i].clone( true, true ) ); + currentListItem.append( item.contents[i].clone( 1, 1 ) ); currentIndex++; } else if ( item.indent == Math.max( indentLevel, 0 ) + 1 ) @@ -108,19 +108,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license currentListItem = item.element.clone( false, true ); else { - // Create completely new blocks here, attributes are dropped. - if ( dir || ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' ) ) + // Create completely new blocks here. + if ( dir || item.element.hasAttributes() || + ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' ) ) { currentListItem = doc.createElement( paragraphName ); - if ( dir ) - currentListItem.setAttribute( 'dir', dir ); + item.element.copyAttributes( currentListItem, { type:1, value:1 } ); + dir && currentListItem.setAttribute( 'dir', dir ); + + // There might be a case where there are no attributes in the element after all + // (i.e. when "type" or "value" are the only attributes set). In this case, if enterMode = BR, + // the current item should be a fragment. + if ( !dir && paragraphMode == CKEDITOR.ENTER_BR && !currentListItem.hasAttributes() ) + currentListItem = new CKEDITOR.dom.documentFragment( doc ); } else currentListItem = new CKEDITOR.dom.documentFragment( doc ); } for ( i = 0 ; i < item.contents.length ; i++ ) - currentListItem.append( item.contents[i].clone( true, true ) ); + currentListItem.append( item.contents[i].clone( 1, 1 ) ); if ( currentListItem.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT && currentIndex != listArray.length - 1 ) @@ -268,6 +275,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license for ( var i = 0 ; i < contents.length ; i++ ) commonParent = commonParent.getCommonAncestor( contents[i].getParent() ); + var useComputedState = editor.config.useComputedState, + listDir, explicitDirection; + + useComputedState = useComputedState === undefined || useComputedState; + // We want to insert things that are in the same tree level only, so calculate the contents again // by expanding the selected blocks to the same tree level. for ( i = 0 ; i < contents.length ; i++ ) @@ -279,6 +291,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( parentNode.equals( commonParent ) ) { listContents.push( contentNode ); + + // Determine the lists's direction. + if ( !explicitDirection && contentNode.getDirection() ) + explicitDirection = 1; + + var itemDir = contentNode.getDirection( useComputedState ); + + if ( listDir !== null ) + { + // If at least one LI have a different direction than current listDir, we can't have listDir. + if ( listDir && listDir != itemDir ) + listDir = null; + else + listDir = itemDir; + } + break; } contentNode = parentNode; @@ -290,39 +318,40 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Insert the list to the DOM tree. var insertAnchor = listContents[ listContents.length - 1 ].getNext(), - listNode = doc.createElement( this.type ), - dir; + listNode = doc.createElement( this.type ); listsCreated.push( listNode ); + + var contentBlock, listItem; + while ( listContents.length ) { - var contentBlock = listContents.shift(), - listItem = doc.createElement( 'li' ); + contentBlock = listContents.shift(); + listItem = doc.createElement( 'li' ); // Preserve preformat block and heading structure when converting to list item. (#5335) (#5271) if ( contentBlock.is( 'pre' ) || headerTagRegex.test( contentBlock.getName() ) ) contentBlock.appendTo( listItem ); else { - if ( contentBlock.hasAttribute( 'dir' ) ) + // Remove DIR attribute if it was merged into list root. + if ( listDir && contentBlock.getDirection() ) { - dir = dir || contentBlock.getAttribute( 'dir' ); + contentBlock.removeStyle( 'direction' ); contentBlock.removeAttribute( 'dir' ); } + contentBlock.copyAttributes( listItem ); contentBlock.moveChildren( listItem ); contentBlock.remove(); - - // Append a bogus BR to force the LI to render at full height - if ( !CKEDITOR.env.ie ) - listItem.appendBogus(); } listItem.appendTo( listNode ); } - if ( dir ) - listNode.setAttribute( 'dir', dir ); + // Apply list root dir only if it has been explicitly declared. + if ( listDir && explicitDirection ) + listNode.setAttribute( 'dir', listDir ); if ( insertAnchor ) listNode.insertBefore( insertAnchor ); @@ -443,9 +472,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license enclosedNode = range && range.getEnclosedNode(); if ( enclosedNode && enclosedNode.is && this.type == enclosedNode.getName() ) - { - setState.call( this, editor, CKEDITOR.TRISTATE_ON ); - } + setState.call( this, editor, CKEDITOR.TRISTATE_ON ); } } @@ -487,7 +514,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license pathElements = path.elements, pathElementsCount = pathElements.length, listNode = null, - processedFlag = false, + processedFlag = 0, blockLimit = path.blockLimit, element; @@ -513,7 +540,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license listGroups.push( groupObj ); CKEDITOR.dom.element.setMarker( database, element, 'list_group_object', groupObj ); } - processedFlag = true; + processedFlag = 1; break; } } @@ -566,10 +593,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { sibling.remove(); // Move children order by merge direction.(#3820) - sibling.moveChildren( listNode, rtl ? true : false ); + sibling.moveChildren( listNode, rtl ); } } )(); - mergeSibling( true ); + mergeSibling( 1 ); } // Clean up, restore selection and update toolbar button states.