2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
13 CKEDITOR.plugins.add( 'image',
\r
15 requires: [ 'dialog' ],
\r
17 init : function( editor )
\r
19 var pluginName = 'image';
\r
21 // Register the dialog.
\r
22 CKEDITOR.dialog.add( pluginName, this.path + 'dialogs/image.js' );
\r
24 // Register the command.
\r
25 editor.addCommand( pluginName, new CKEDITOR.dialogCommand( pluginName ) );
\r
27 // Register the toolbar button.
\r
28 editor.ui.addButton( 'Image',
\r
30 label : editor.lang.common.image,
\r
31 command : pluginName
\r
34 editor.on( 'doubleclick', function( evt )
\r
36 var element = evt.data.element;
\r
38 if ( element.is( 'img' ) && !element.data( 'cke-realelement' ) && !element.isReadOnly() )
\r
39 evt.data.dialog = 'image';
\r
42 // If the "menu" plugin is loaded, register the menu items.
\r
43 if ( editor.addMenuItems )
\r
45 editor.addMenuItems(
\r
49 label : editor.lang.image.menu,
\r
56 // If the "contextmenu" plugin is loaded, register the listeners.
\r
57 if ( editor.contextMenu )
\r
59 editor.contextMenu.addListener( function( element, selection )
\r
61 if ( getSelectedImage( editor, element ) )
\r
62 return { image : CKEDITOR.TRISTATE_OFF };
\r
66 afterInit : function( editor )
\r
68 // Customize the behavior of the alignment commands. (#7430)
\r
69 setupAlignCommand( 'left' );
\r
70 setupAlignCommand( 'right' );
\r
71 setupAlignCommand( 'center' );
\r
72 setupAlignCommand( 'block' );
\r
74 function setupAlignCommand( value )
\r
76 var command = editor.getCommand( 'justify' + value );
\r
79 if ( value == 'left' || value == 'right' )
\r
81 command.on( 'exec', function( evt )
\r
83 var img = getSelectedImage( editor ), align;
\r
86 align = getImageAlignment( img );
\r
87 if ( align == value )
\r
89 img.removeStyle( 'float' );
\r
91 // Remove "align" attribute when necessary.
\r
92 if ( value == getImageAlignment( img ) )
\r
93 img.removeAttribute( 'align' );
\r
96 img.setStyle( 'float', value );
\r
103 command.on( 'refresh', function( evt )
\r
105 var img = getSelectedImage( editor ), align;
\r
108 align = getImageAlignment( img );
\r
111 ( align == value ) ? CKEDITOR.TRISTATE_ON :
\r
112 ( value == 'right' || value == 'left' ) ? CKEDITOR.TRISTATE_OFF :
\r
113 CKEDITOR.TRISTATE_DISABLED );
\r
123 function getSelectedImage( editor, element )
\r
127 var sel = editor.getSelection();
\r
128 element = ( sel.getType() == CKEDITOR.SELECTION_ELEMENT ) && sel.getSelectedElement();
\r
131 if ( element && element.is( 'img' ) && !element.data( 'cke-realelement' ) && !element.isReadOnly() )
\r
135 function getImageAlignment( element )
\r
137 var align = element.getStyle( 'float' );
\r
139 if ( align == 'inherit' || align == 'none' )
\r
143 align = element.getAttribute( 'align' );
\r
151 * Whether to remove links when emptying the link URL field in the image dialog.
\r
155 * config.image_removeLinkByEmptyURL = false;
\r
157 CKEDITOR.config.image_removeLinkByEmptyURL = true;
\r
160 * Padding text to set off the image in preview area.
\r
161 * @name CKEDITOR.config.image_previewText
\r
163 * @default "Lorem ipsum dolor..." placehoder text.
\r
165 * config.image_previewText = CKEDITOR.tools.repeat( '___ ', 100 );
\r