Ticket #7430: 7430_4.patch
File 7430_4.patch, 5.4 KB (added by , 12 years ago) |
---|
-
_source/core/command.js
49 49 if ( this.editorFocus ) // Give editor focus if necessary (#4355). 50 50 editor.focus(); 51 51 52 if ( this.fire( 'exec' ) === true ) 53 return true; 54 52 55 return ( commandDefinition.exec.call( this, editor, data ) !== false ); 53 56 }; 54 57 58 this.refresh = function() 59 { 60 if ( this.fire( 'refresh' ) === true ) 61 return true; 62 63 return ( commandDefinition.refresh && commandDefinition.refresh.apply( this, arguments ) !== false ); 64 }; 65 55 66 CKEDITOR.tools.extend( this, commandDefinition, 56 67 // Defaults 57 68 /** @lends CKEDITOR.command.prototype */ -
_source/plugins/image/plugin.js
7 7 * @file Image plugin 8 8 */ 9 9 10 (function() 11 { 12 10 13 CKEDITOR.plugins.add( 'image', 11 14 { 12 15 init : function( editor ) … … 53 56 { 54 57 editor.contextMenu.addListener( function( element, selection ) 55 58 { 56 if ( !element || !element.is( 'img' ) || element.data( 'cke-realelement' ) || element.isReadOnly() ) 57 return null; 58 59 return { image : CKEDITOR.TRISTATE_OFF }; 59 if ( getSelectedImage( editor, element ) ) 60 return { image : CKEDITOR.TRISTATE_OFF }; 60 61 }); 61 62 } 63 }, 64 afterInit : function( editor ) 65 { 66 // Customize the behavior of the alignment commands. (#7430) 67 setupAlignCommand( 'left' ); 68 setupAlignCommand( 'right' ); 69 setupAlignCommand( 'center' ); 70 setupAlignCommand( 'block' ); 71 72 function setupAlignCommand( value ) 73 { 74 var command = editor.getCommand( 'justify' + value ); 75 if ( command ) 76 { 77 if ( value == 'left' || value == 'right' ) 78 { 79 command.on( 'exec', function( evt ) 80 { 81 var img = getSelectedImage( editor ), align; 82 if ( img ) 83 { 84 align = getImageAlignment( img ); 85 align == value ? img.removeStyle( 'float' ) : img.setStyle( 'float', value ) 86 87 evt.cancel(); 88 } 89 }); 90 } 91 92 command.on( 'refresh', function( evt ) 93 { 94 var img = getSelectedImage( editor ), align; 95 if ( img ) 96 { 97 align = getImageAlignment( img ); 98 99 this.setState( 100 ( align == value ) ? CKEDITOR.TRISTATE_ON : 101 ( value == 'right' || value == 'left' ) ? CKEDITOR.TRISTATE_OFF : 102 CKEDITOR.TRISTATE_DISABLED ); 103 104 evt.cancel(); 105 } 106 }); 107 } 108 } 62 109 } 63 } 110 }); 64 111 112 function getSelectedImage( editor, element ) 113 { 114 if ( !element ) 115 { 116 var sel = editor.getSelection(); 117 element = ( sel.getType() == CKEDITOR.SELECTION_ELEMENT ) && sel.getSelectedElement(); 118 } 119 120 if ( element && element.is( 'img' ) && !element.data( 'cke-realelement' ) && !element.isReadOnly() ) 121 return element; 122 } 123 124 function getImageAlignment( element ) 125 { 126 var align = element.getStyle( 'float' ); 127 128 if ( align == 'inherit' || align == 'none' ) 129 align = 0; 130 131 if ( !align ) 132 align = element.getAttribute( 'align' ); 133 134 return align; 135 } 136 137 })(); 138 65 139 /** 66 140 * Whether to remove links when emptying the link URL field in the image dialog. 67 141 * @type Boolean -
_source/plugins/justify/plugin.js
9 9 10 10 (function() 11 11 { 12 function getState( editor, path )13 {14 var firstBlock = path.block || path.blockLimit;15 16 if ( !firstBlock || firstBlock.getName() == 'body' )17 return CKEDITOR.TRISTATE_OFF;18 19 return ( getAlignment( firstBlock, editor.config.useComputedState ) == this.value ) ?20 CKEDITOR.TRISTATE_ON :21 CKEDITOR.TRISTATE_OFF;22 }23 24 12 function getAlignment( element, useComputedState ) 25 13 { 26 14 useComputedState = useComputedState === undefined || useComputedState; … … 40 28 align = element.getStyle( 'text-align' ) || element.getAttribute( 'align' ) || ''; 41 29 } 42 30 43 align && ( align = align.replace( /-moz-|-webkit-|start|auto/i, '' ) ); 31 // Sometimes computed values doesn't tell. 32 align && ( align = align.replace( /(?:-(?:moz|webkit)-)?(?:start|auto)/i, '' ) ); 44 33 45 34 !align && useComputedState && ( align = element.getComputedStyle( 'direction' ) == 'rtl' ? 'right' : 'left' ); 46 35 … … 52 41 if ( evt.editor.readOnly ) 53 42 return; 54 43 55 var command = evt.editor.getCommand( this.name ); 56 command.state = getState.call( this, evt.editor, evt.data.path ); 57 command.fire( 'state' ); 44 evt.editor.getCommand( this.name ).refresh( evt.data.path ); 58 45 } 59 46 60 47 function justifyCommand( editor, name, value ) 61 48 { 49 this.editor = editor; 62 50 this.name = name; 63 51 this.value = value; 64 52 … … 192 180 editor.focus(); 193 181 editor.forceNextSelectionCheck(); 194 182 selection.selectBookmarks( bookmarks ); 183 }, 184 185 refresh : function( path ) 186 { 187 var firstBlock = path.block || path.blockLimit; 188 189 if ( !firstBlock || firstBlock.getName() == 'body' ) 190 return CKEDITOR.TRISTATE_OFF; 191 192 this.setState( getAlignment( firstBlock, this.editor.config.useComputedState ) == this.value ? 193 CKEDITOR.TRISTATE_ON : 194 CKEDITOR.TRISTATE_OFF ); 195 195 } 196 196 }; 197 197