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
=
96 exec : function ( editor
)
99 this.refresh( editor
);
102 refresh : function( editor
)
104 if ( editor
.document
)
106 var funcName
= ( this.state
== CKEDITOR
.TRISTATE_ON
) ? 'addClass' : 'removeClass';
107 editor
.document
.getBody()[ funcName
]( 'cke_show_blocks' );
112 CKEDITOR
.plugins
.add( 'showblocks',
114 requires
: [ 'wysiwygarea' ],
116 init : function( editor
)
118 var command
= editor
.addCommand( 'showblocks', commandDefinition
);
119 command
.canUndo
= false;
121 if ( editor
.config
.startupOutlineBlocks
)
122 command
.setState( CKEDITOR
.TRISTATE_ON
);
124 editor
.addCss( cssTemplate
125 .replace( cssTemplateRegex
, 'background-image: url(' + CKEDITOR
.getUrl( this.path
) + 'images/block_' )
126 .replace( cssClassRegex
, 'cke_show_blocks ' )
127 .replace( backgroundPositionRegex
, editor
.lang
.dir
== 'rtl' ? 'right' : 'left' ) );
129 editor
.ui
.addButton( 'ShowBlocks',
131 label
: editor
.lang
.showBlocks
,
132 command
: 'showblocks'
135 // Refresh the command on setData.
136 editor
.on( 'mode', function()
138 if ( command
.state
!= CKEDITOR
.TRISTATE_DISABLED
)
139 command
.refresh( editor
);
142 // Refresh the command on setData.
143 editor
.on( 'contentDom', function()
145 if ( command
.state
!= CKEDITOR
.TRISTATE_DISABLED
)
146 command
.refresh( editor
);
153 * Whether to automaticaly enable the "show block" command when the editor
154 * loads. (StartupShowBlocks in FCKeditor)
155 * @name CKEDITOR.config.startupOutlineBlocks
159 * config.startupOutlineBlocks = true;