2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview The "showblocks" plugin. Enable it will make all block level
8 * elements being decorated with a border and the element name
9 * displayed on the left-right corner.
14 var cssTemplate = '.%2 p,'+
26 'background-repeat: no-repeat;'+
27 'background-position: top %3;'+
28 'border: 1px dotted gray;'+
88 var cssTemplateRegex = /%1/g, cssClassRegex = /%2/g, backgroundPositionRegex = /%3/g;
90 var commandDefinition =
95 exec : function ( editor )
98 this.refresh( editor );
101 refresh : function( editor )
103 var funcName = ( this.state == CKEDITOR.TRISTATE_ON ) ? 'addClass' : 'removeClass';
104 editor.document.getBody()[ funcName ]( 'cke_show_blocks' );
108 CKEDITOR.plugins.add( 'showblocks',
110 requires : [ 'wysiwygarea' ],
112 init : function( editor )
114 var command = editor.addCommand( 'showblocks', commandDefinition );
115 command.canUndo = false;
117 if ( editor.config.startupOutlineBlocks )
118 command.setState( CKEDITOR.TRISTATE_ON );
120 editor.addCss( cssTemplate
121 .replace( cssTemplateRegex, 'background-image: url(' + CKEDITOR.getUrl( this.path ) + 'images/block_' )
122 .replace( cssClassRegex, 'cke_show_blocks ' )
123 .replace( backgroundPositionRegex, editor.lang.dir == 'rtl' ? 'right' : 'left' ) );
125 editor.ui.addButton( 'ShowBlocks',
127 label : editor.lang.showBlocks,
128 command : 'showblocks'
131 // Refresh the command on setData.
132 editor.on( 'mode', function()
134 if ( command.state != CKEDITOR.TRISTATE_DISABLED )
135 command.refresh( editor );
138 // Refresh the command on setData.
139 editor.on( 'contentDom', function()
141 if ( command.state != CKEDITOR.TRISTATE_DISABLED )
142 command.refresh( editor );
149 * Whether to automaticaly enable the "show block" command when the editor
150 * loads. (StartupShowBlocks in FCKeditor)
151 * @name CKEDITOR.config.startupOutlineBlocks
155 * config.startupOutlineBlocks = true;