X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Flist%2Fplugin.js;h=ad791533b8b823cc3830b0fbf4a984eff5e3269e;hb=refs%2Ftags%2Fv3.6.2;hp=b0676d0def8917b81fc3ac02cd979188f8cd7066;hpb=4e90e78dc97789709ee7404359a5517540c27553;p=ckeditor.git diff --git a/_source/plugins/list/plugin.js b/_source/plugins/list/plugin.js index b0676d0..ad79153 100644 --- a/_source/plugins/list/plugin.js +++ b/_source/plugins/list/plugin.js @@ -16,6 +16,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license bookmarks = CKEDITOR.dom.walker.bookmark(), nonEmpty = function( node ){ return !( whitespaces( node ) || bookmarks( node ) ); }; + function cleanUpDirection( element ) + { + var dir, parent, parentDir; + if ( ( dir = element.getDirection() ) ) + { + parent = element.getParent(); + while ( parent && !( parentDir = parent.getDirection() ) ) + parent = parent.getParent(); + + if ( dir == parentDir ) + element.removeAttribute( 'dir' ); + } + } + CKEDITOR.plugins.list = { /* * Convert a DOM list tree into a data structure that is easier to @@ -87,11 +101,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license currentIndex = baseIndex, indentLevel = Math.max( listArray[ baseIndex ].indent, 0 ), currentListItem = null, - itemDir, + orgDir, paragraphName = ( paragraphMode == CKEDITOR.ENTER_P ? 'p' : 'div' ); while ( 1 ) { var item = listArray[ currentIndex ]; + + orgDir = item.element.getDirection( 1 ); + if ( item.indent == indentLevel ) { if ( !rootNode || listArray[ currentIndex ].parent.getName() != rootNode.getName() ) @@ -101,6 +118,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license retval.append( rootNode ); } currentListItem = rootNode.append( item.element.clone( 0, 1 ) ); + + if ( orgDir != rootNode.getDirection( 1 ) ) + currentListItem.setAttribute( 'dir', orgDir ); + for ( var i = 0 ; i < item.contents.length ; i++ ) currentListItem.append( item.contents[i].clone( 1, 1 ) ); currentIndex++; @@ -108,8 +129,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license else if ( item.indent == Math.max( indentLevel, 0 ) + 1 ) { // Maintain original direction (#6861). - var orgDir = item.element.getDirection( 1 ), - currDir = listArray[ currentIndex - 1 ].element.getDirection( 1 ), + var currDir = listArray[ currentIndex - 1 ].element.getDirection( 1 ), listData = CKEDITOR.plugins.list.arrayToList( listArray, null, currentIndex, paragraphMode, currDir != orgDir ? orgDir: null ); @@ -124,12 +144,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license else if ( item.indent == -1 && !baseIndex && item.grandparent ) { if ( listNodeNames[ item.grandparent.getName() ] ) - { currentListItem = item.element.clone( false, true ); - itemDir = item.element.getDirection( 1 ); - item.grandparent.getDirection( 1 ) != itemDir && - currentListItem.setAttribute( 'dir', itemDir ); - } else { // Create completely new blocks here. @@ -137,9 +152,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { currentListItem = doc.createElement( paragraphName ); item.element.copyAttributes( currentListItem, { type:1, value:1 } ); - itemDir = item.element.getDirection() || dir; - itemDir && - currentListItem.setAttribute( 'dir', itemDir ); // 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, @@ -151,6 +163,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license currentListItem = new CKEDITOR.dom.documentFragment( doc ); } + if ( currentListItem.type == CKEDITOR.NODE_ELEMENT ) + { + if ( item.grandparent.getDirection( 1 ) != orgDir ) + currentListItem.setAttribute( 'dir', orgDir ); + } + for ( i = 0 ; i < item.contents.length ; i++ ) currentListItem.append( item.contents[i].clone( 1, 1 ) ); @@ -200,14 +218,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license break; } - // Clear marker attributes for the new list tree made of cloned nodes, if any. if ( database ) { - var currentNode = retval.getFirst(); + var currentNode = retval.getFirst(), + listRoot = listArray[ 0 ].parent; + while ( currentNode ) { if ( currentNode.type == CKEDITOR.NODE_ELEMENT ) + { + // Clear marker attributes for the new list tree made of cloned nodes, if any. CKEDITOR.dom.element.clearMarkers( database, currentNode ); + + // Clear redundant direction attribute specified on list items. + if ( currentNode.getName() in CKEDITOR.dtd.$listItem ) + cleanUpDirection( currentNode ); + } + currentNode = currentNode.getNextSourceNode(); } } @@ -218,6 +245,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function onSelectionChange( evt ) { + if ( evt.editor.readOnly ) + return null; + var path = evt.data.path, blockLimit = path.blockLimit, elements = path.elements, @@ -228,8 +258,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license for ( i = 0 ; i < elements.length && ( element = elements[ i ] ) && !element.equals( blockLimit ); i++ ) { - if ( listNodeNames[ elements[i].getName() ] ) - return this.setState( this.type == elements[i].getName() ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); + if ( listNodeNames[ elements[ i ].getName() ] ) + return this.setState( this.type == elements[ i ].getName() ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); } return this.setState( CKEDITOR.TRISTATE_OFF ); @@ -360,14 +390,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license contentBlock.appendTo( listItem ); else { - // Remove DIR attribute if it was merged into list root. + contentBlock.copyAttributes( listItem ); + // Remove direction attribute after it was merged into list root. (#7657) if ( listDir && contentBlock.getDirection() ) { - contentBlock.removeStyle( 'direction' ); - contentBlock.removeAttribute( 'dir' ); + listItem.removeStyle( 'direction' ); + listItem.removeAttribute( 'dir' ); } - - contentBlock.copyAttributes( listItem ); contentBlock.moveChildren( listItem ); contentBlock.remove(); } @@ -454,6 +483,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.type = type; } + // Move direction attribute from root to list items. + function dirToListItems( list ) + { + var dir = list.getDirection(); + if ( dir ) + { + for ( var i = 0, children = list.getChildren(), child; child = children.getItem( i ), i < children.count(); i++ ) + { + if ( child.type == CKEDITOR.NODE_ELEMENT && child.is( 'li' ) && !child.getDirection() ) + child.setAttribute( 'dir', dir ); + } + + list.removeAttribute( 'dir' ); + } + } + listCommand.prototype = { exec : function( editor ) { @@ -607,6 +652,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( sibling && sibling.getName && sibling.getName() == listCommand.type ) { + + // In case to be merged lists have difference directions. (#7448) + if ( sibling.getDirection( 1 ) != listNode.getDirection( 1 ) ) + dirToListItems( listNode.getDirection() ? listNode : sibling ); + sibling.remove(); // Move children order by merge direction.(#3820) sibling.moveChildren( listNode, rtl );