X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fdiv%2Fdialogs%2Fdiv.js;h=4b67ed26510aa0ac655bdecb1473f229dba71431;hb=039a051ccf3901311661022a30afd60fc38130c9;hp=c63e061d33cfb432ff56d5902f207531f156b377;hpb=c6e377a02b54abc07129d72b632763c727476a15;p=ckeditor.git diff --git a/_source/plugins/div/dialogs/div.js b/_source/plugins/div/dialogs/div.js index c63e061..4b67ed2 100644 --- a/_source/plugins/div/dialogs/div.js +++ b/_source/plugins/div/dialogs/div.js @@ -140,8 +140,8 @@ var containedBlocks = [], block; // Get all ranges from the selection. - var selection = editor.document.getSelection(); - var ranges = selection.getRanges(); + var selection = editor.document.getSelection(), + ranges = selection.getRanges(); var bookmarks = selection.createBookmarks(); var i, iterator; @@ -259,6 +259,29 @@ return groups; } + // Synchronous field values to other impacted fields is required, e.g. div styles + // change should also alter inline-style text. + function commitInternally( targetFields ) + { + var dialog = this.getDialog(), + element = dialog._element && dialog._element.clone() + || new CKEDITOR.dom.element( 'div', editor.document ); + + // Commit this field and broadcast to target fields. + this.commit( element, true ); + + targetFields = [].concat( targetFields ); + var length = targetFields.length, field; + for ( var i = 0; i < length; i++ ) + { + field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) ); + field && field.setup && field.setup( element, true ); + } + } + + + // Registered 'CKEDITOR.style' instances. + var styles = {} ; /** * Hold a collection of created block container elements. */ @@ -289,17 +312,31 @@ style :'width: 100%;', label :editor.lang.div.styleSelectLabel, 'default' : '', - items : [], + // Options are loaded dynamically. + items : + [ + [ editor.lang.common.notSet , '' ] + ], + onChange : function() + { + commitInternally.call( this, [ 'info:class', 'advanced:dir', 'advanced:style' ] ); + }, setup : function( element ) { - this.setValue( element.$.style.cssText || '' ); + for ( var name in styles ) + styles[ name ].checkElementRemovable( element, true ) && this.setValue( name ); }, commit: function( element ) { - if ( this.getValue() ) - element.$.style.cssText = this.getValue(); - else - element.removeAttribute( 'style' ); + var styleName; + if ( ( styleName = this.getValue() ) ) + { + var style = styles[ styleName ]; + var customData = element.getCustomData( 'elementStyle' ) || ''; + + style.applyToObject( element ); + element.setCustomData( 'elementStyle', customData + style._.definition.attributes.style ); + } } }, { @@ -351,7 +388,13 @@ id :'style', style :'width: 100%;', label :editor.lang.common.cssStyle, - 'default' : '' + 'default' : '', + commit : function( element ) + { + // Merge with 'elementStyle', which is of higher priority. + var merged = this.getValue() + ( element.getCustomData( 'elementStyle' ) || '' ); + element.setAttribute( 'style', merged ); + } } ] }, @@ -376,6 +419,7 @@ 'default' : '', items : [ + [ editor.lang.common.notSet , '' ], [ editor.lang.common.langDirLtr, 'ltr' @@ -393,7 +437,42 @@ ], onLoad : function() { - setupFields.call(this); + setupFields.call( this ); + + // Preparing for the 'elementStyle' field. + var dialog = this, + stylesField = this.getContentElement( 'info', 'elementStyle' ); + + // Reuse the 'stylescombo' plugin's styles definition. + editor.getStylesSet( function( stylesDefinitions ) + { + var styleName; + + if ( stylesDefinitions ) + { + // Digg only those styles that apply to 'div'. + for ( var i = 0 ; i < stylesDefinitions.length ; i++ ) + { + var styleDefinition = stylesDefinitions[ i ]; + if ( styleDefinition.element && styleDefinition.element == 'div' ) + { + styleName = styleDefinition.name; + styles[ styleName ] = new CKEDITOR.style( styleDefinition ); + + // Populate the styles field options with style name. + stylesField.items.push( [ styleName, styleName ] ); + stylesField.add( styleName, styleName ); + } + } + } + + // We should disable the content element + // it if no options are available at all. + stylesField[ stylesField.items.length > 1 ? 'enable' : 'disable' ](); + + // Now setup the field value manually. + setTimeout( function() { stylesField.setup( dialog._element ); }, 0 ); + } ); }, onShow : function() { @@ -416,9 +495,23 @@ containers = createDiv( editor, true ); // Update elements attributes - for ( var i = 0 ; i < containers.length ; i++ ) + var size = containers.length; + for ( var i = 0; i < size; i++ ) + { this.commitContent( containers[ i ] ); + + // Remove empty 'style' attribute. + !containers[ i ].getAttribute( 'style' ) && containers[ i ].removeAttribute( 'style' ); + } + this.hide(); + }, + onHide : function() + { + // Remove style only when editing existing DIV. (#6315) + if ( command == 'editdiv' ) + this._element.removeCustomData( 'elementStyle' ); + delete this._element; } }; }