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 init : function( editor )
\r
17 var pluginName = 'image';
\r
19 // Register the dialog.
\r
20 CKEDITOR.dialog.add( pluginName, this.path + 'dialogs/image.js' );
\r
22 // Register the command.
\r
23 editor.addCommand( pluginName, new CKEDITOR.dialogCommand( pluginName ) );
\r
25 // Register the toolbar button.
\r
26 editor.ui.addButton( 'Image',
\r
28 label : editor.lang.common.image,
\r
29 command : pluginName
\r
32 editor.on( 'doubleclick', function( evt )
\r
34 var element = evt.data.element;
\r
36 if ( element.is( 'img' ) && !element.data( 'cke-realelement' ) && !element.isReadOnly() )
\r
37 evt.data.dialog = 'image';
\r
40 // If the "menu" plugin is loaded, register the menu items.
\r
41 if ( editor.addMenuItems )
\r
43 editor.addMenuItems(
\r
47 label : editor.lang.image.menu,
\r
54 // If the "contextmenu" plugin is loaded, register the listeners.
\r
55 if ( editor.contextMenu )
\r
57 editor.contextMenu.addListener( function( element, selection )
\r
59 if ( getSelectedImage( editor, element ) )
\r
60 return { image : CKEDITOR.TRISTATE_OFF };
\r
64 afterInit : function( editor )
\r
66 // Customize the behavior of the alignment commands. (#7430)
\r
67 setupAlignCommand( 'left' );
\r
68 setupAlignCommand( 'right' );
\r
69 setupAlignCommand( 'center' );
\r
70 setupAlignCommand( 'block' );
\r
72 function setupAlignCommand( value )
\r
74 var command = editor.getCommand( 'justify' + value );
\r
77 if ( value == 'left' || value == 'right' )
\r
79 command.on( 'exec', function( evt )
\r
81 var img = getSelectedImage( editor ), align;
\r
84 align = getImageAlignment( img );
\r
85 if ( align == value )
\r
87 img.removeStyle( 'float' );
\r
89 // Remove "align" attribute when necessary.
\r
90 if ( value == getImageAlignment( img ) )
\r
91 img.removeAttribute( 'align' );
\r
94 img.setStyle( 'float', value );
\r
101 command.on( 'refresh', function( evt )
\r
103 var img = getSelectedImage( editor ), align;
\r
106 align = getImageAlignment( img );
\r
109 ( align == value ) ? CKEDITOR.TRISTATE_ON :
\r
110 ( value == 'right' || value == 'left' ) ? CKEDITOR.TRISTATE_OFF :
\r
111 CKEDITOR.TRISTATE_DISABLED );
\r
121 function getSelectedImage( editor, element )
\r
125 var sel = editor.getSelection();
\r
126 element = ( sel.getType() == CKEDITOR.SELECTION_ELEMENT ) && sel.getSelectedElement();
\r
129 if ( element && element.is( 'img' ) && !element.data( 'cke-realelement' ) && !element.isReadOnly() )
\r
133 function getImageAlignment( element )
\r
135 var align = element.getStyle( 'float' );
\r
137 if ( align == 'inherit' || align == 'none' )
\r
141 align = element.getAttribute( 'align' );
\r
149 * Whether to remove links when emptying the link URL field in the image dialog.
\r
153 * config.image_removeLinkByEmptyURL = false;
\r
155 CKEDITOR.config.image_removeLinkByEmptyURL = true;
\r
158 * Padding text to set off the image in preview area.
\r
159 * @name CKEDITOR.config.image_previewText
\r
161 * @default "Lorem ipsum dolor..." placehoder text.
\r
163 * config.image_previewText = CKEDITOR.tools.repeat( '___ ', 100 );
\r