X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Findent%2Fplugin.js;h=e5db0b24768c5f6daa6013bbc4d2f8a658df717a;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=50b13567bb60e2dc9fe3a67ce9c1acf43bf37077;hpb=039a051ccf3901311661022a30afd60fc38130c9;p=ckeditor.git diff --git a/_source/plugins/indent/plugin.js b/_source/plugins/indent/plugin.js index 50b1356..e5db0b2 100644 --- a/_source/plugins/indent/plugin.js +++ b/_source/plugins/indent/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -9,33 +9,28 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { - var listNodeNames = { ol : 1, ul : 1 }; - - var isNotWhitespaces = CKEDITOR.dom.walker.whitespaces( true ), + var listNodeNames = { ol : 1, ul : 1 }, + isNotWhitespaces = CKEDITOR.dom.walker.whitespaces( true ), isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true ); - function setState( editor, state ) - { - editor.getCommand( this.name ).setState( state ); - } - function onSelectionChange( evt ) { - var editor = evt.editor; + if ( evt.editor.readOnly ) + return null; - var elementPath = evt.data.path, - list = elementPath && elementPath.contains( listNodeNames ); + var editor = evt.editor, + elementPath = evt.data.path, + list = elementPath && elementPath.contains( listNodeNames ), + firstBlock = elementPath.block || elementPath.blockLimit; if ( list ) - return setState.call( this, editor, CKEDITOR.TRISTATE_OFF ); + return this.setState( CKEDITOR.TRISTATE_OFF ); if ( !this.useIndentClasses && this.name == 'indent' ) - return setState.call( this, editor, CKEDITOR.TRISTATE_OFF ); + return this.setState( CKEDITOR.TRISTATE_OFF ); - var path = evt.data.path, - firstBlock = path.block || path.blockLimit; if ( !firstBlock ) - return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED ); + return this.setState( CKEDITOR.TRISTATE_DISABLED ); if ( this.useIndentClasses ) { @@ -48,8 +43,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } if ( ( this.name == 'outdent' && !indentStep ) || ( this.name == 'indent' && indentStep == editor.config.indentClasses.length ) ) - return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED ); - return setState.call( this, editor, CKEDITOR.TRISTATE_OFF ); + return this.setState( CKEDITOR.TRISTATE_DISABLED ); + return this.setState( CKEDITOR.TRISTATE_OFF ); } else { @@ -57,8 +52,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( isNaN( indent ) ) indent = 0; if ( indent <= 0 ) - return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED ); - return setState.call( this, editor, CKEDITOR.TRISTATE_OFF ); + return this.setState( CKEDITOR.TRISTATE_DISABLED ); + return this.setState( CKEDITOR.TRISTATE_OFF ); } } @@ -78,14 +73,14 @@ 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 ) { - return node.type = CKEDITOR.NODE_ELEMENT && node.is( 'li' ); + return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'li' ); } indentCommand.prototype = { @@ -147,8 +142,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { listArray[ i ].indent += indentOffset; // Make sure the newly created sublist get a brand-new element of the same type. (#5372) - var listRoot = listArray[ i ].parent; - listArray[ i ].parent = new CKEDITOR.dom.element( listRoot.getName(), listRoot.getDocument() ); + if ( indentOffset > 0 ) + { + var listRoot = listArray[ i ].parent; + listArray[ i ].parent = new CKEDITOR.dom.element( listRoot.getName(), listRoot.getDocument() ); + } } for ( i = lastItem.getCustomData( 'listarray_index' ) + 1 ; @@ -157,8 +155,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) @@ -216,11 +213,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license iterator.enforceRealBlocks = true; iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR; var block; - while ( ( block = iterator.getNextParagraph() ) ) + while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) ) indentElement( block ); } - function indentElement( element ) + function indentElement( element, dir ) { if ( element.getCustomData( 'indent_processed' ) ) return false; @@ -248,15 +245,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 +323,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 +332,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 @@ -359,10 +352,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license init : function( editor ) { // Register commands. - var indent = new indentCommand( editor, 'indent' ), - outdent = new indentCommand( editor, 'outdent' ); - editor.addCommand( 'indent', indent ); - editor.addCommand( 'outdent', outdent ); + var indent = editor.addCommand( 'indent', new indentCommand( editor, 'indent' ) ), + outdent = editor.addCommand( 'outdent', new indentCommand( editor, 'outdent' ) ); // Register the toolbar buttons. editor.ui.addButton( 'Indent', @@ -395,8 +386,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 +397,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 +436,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 +445,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,8 +455,9 @@ 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 + * @default null * @example * // Use the classes 'Indent1', 'Indent2', 'Indent3' * config.indentClasses = ['Indent1', 'Indent2', 'Indent3'];