X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Findent%2Fplugin.js;h=c49ce882832188b5b1c876898cd5a5d9d2762a6b;hp=50b13567bb60e2dc9fe3a67ce9c1acf43bf37077;hb=614511639979907ceb0da3614122a4d8eb963ad4;hpb=039a051ccf3901311661022a30afd60fc38130c9 diff --git a/_source/plugins/indent/plugin.js b/_source/plugins/indent/plugin.js index 50b1356..c49ce88 100644 --- a/_source/plugins/indent/plugin.js +++ b/_source/plugins/indent/plugin.js @@ -78,9 +78,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } // Returns the CSS property to be used for identing a given element. - function getIndentCssProperty( element ) + function getIndentCssProperty( element, dir ) { - return element.getComputedStyle( 'direction' ) == 'ltr' ? 'margin-left' : 'margin-right'; + return ( dir || element.getComputedStyle( 'direction' ) ) == 'ltr' ? 'margin-left' : 'margin-right'; } function isListItem( node ) @@ -157,8 +157,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Convert the array back to a DOM forest (yes we might have a few subtrees now). // And replace the old list with the new forest. - var newListDir = listNode.getAttribute( 'dir' ) || listNode.getStyle( 'direction' ); - var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode, newListDir ); + var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode, listNode.getDirection() ); // Avoid nested
  • after outdent even they're visually same, // recording them for later refactoring.(#3982) @@ -220,7 +219,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license indentElement( block ); } - function indentElement( element ) + function indentElement( element, dir ) { if ( element.getCustomData( 'indent_processed' ) ) return false; @@ -248,15 +247,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license indentStep = Math.min( indentStep, editor.config.indentClasses.length ); indentStep = Math.max( indentStep, 0 ); - var className = CKEDITOR.tools.ltrim( element.$.className.replace( self.classNameRegex, '' ) ); - if ( indentStep < 1 ) - element.$.className = className; - else + element.$.className = CKEDITOR.tools.ltrim( element.$.className.replace( self.classNameRegex, '' ) ); + if ( indentStep > 0 ) element.addClass( editor.config.indentClasses[ indentStep - 1 ] ); } else { - var indentCssProperty = getIndentCssProperty( element ), + var indentCssProperty = getIndentCssProperty( element, dir ), currentOffset = parseInt( element.getStyle( indentCssProperty ), 10 ); if ( isNaN( currentOffset ) ) currentOffset = 0; @@ -328,10 +325,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( nearestListBlock ) { - var firstListItem = nearestListBlock.getFirst( function( node ) - { - return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'li' ); - }), + var firstListItem = nearestListBlock.getFirst( isListItem ), + hasMultipleItems = !!firstListItem.getNext( isListItem ), rangeStart = range.startContainer, indentWholeList = firstListItem.equals( rangeStart ) || firstListItem.contains( rangeStart ); @@ -339,7 +334,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Only do that for indenting or when using indent classes or when there is something to outdent. (#6141) if ( !( indentWholeList && ( self.name == 'indent' || self.useIndentClasses || parseInt( nearestListBlock.getStyle( getIndentCssProperty( nearestListBlock ) ), 10 ) ) && - indentElement( nearestListBlock ) ) ) + indentElement( nearestListBlock, !hasMultipleItems && firstListItem.getDirection() ) ) ) indentList( nearestListBlock ); } else @@ -395,8 +390,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.on( 'dirChanged', function( e ) { var range = new CKEDITOR.dom.range( editor.document ); - range.setStartBefore( e.data ); - range.setEndAfter( e.data ); + range.setStartBefore( e.data.node ); + range.setEndAfter( e.data.node ); var walker = new CKEDITOR.dom.walker( range ), node; @@ -406,13 +401,28 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( node.type == CKEDITOR.NODE_ELEMENT ) { // A child with the defined dir is to be ignored. - if ( !node.equals( e.data ) && node.getDirection() ) + if ( !node.equals( e.data.node ) && node.getDirection() ) { range.setStartAfter( node ); walker = new CKEDITOR.dom.walker( range ); continue; } + // Switch alignment classes. + var classes = editor.config.indentClasses; + if ( classes ) + { + var suffix = ( e.data.dir == 'ltr' ) ? [ '_rtl', '' ] : [ '', '_rtl' ]; + for ( var i = 0; i < classes.length; i++ ) + { + if ( node.hasClass( classes[ i ] + suffix[ 0 ] ) ) + { + node.removeClass( classes[ i ] + suffix[ 0 ] ); + node.addClass( classes[ i ] + suffix[ 1 ] ); + } + } + } + // Switch the margins. var marginLeft = node.getStyle( 'margin-right' ), marginRight = node.getStyle( 'margin-left' ); @@ -430,6 +440,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license /** * Size of each indentation step + * @name CKEDITOR.config.indentOffset * @type Number * @default 40 * @example @@ -438,6 +449,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license /** * Unit for the indentation style + * @name CKEDITOR.config.indentUnit * @type String * @default 'px' * @example @@ -447,6 +459,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license /** * List of classes to use for indenting the contents. If it's null, no classes will be used * and instead the {@link #indentUnit} and {@link #indentOffset} properties will be used. + * @name CKEDITOR.config.indentClasses * @type Array * default null * @example