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 "show border" plugin. The command display visible outline
8 * border line around all table elements if table doesn't have a none-zero 'border' attribute specified.
13 var showBorderClassName
= 'cke_show_border',
16 // TODO: For IE6, we don't have child selector support,
17 // where nested table cells could be incorrect.
18 ( CKEDITOR
.env
.ie6Compat
?
21 '.%1 table.%2 td, .%1 table.%2 th',
23 'border : #d3d3d3 1px dotted',
28 '.%1 table.%2 > tr > td, .%1 table.%2 > tr > th,',
29 '.%1 table.%2 > tbody > tr > td, .%1 table.%2 > tbody > tr > th,',
30 '.%1 table.%2 > thead > tr > td, .%1 table.%2 > thead > tr > th,',
31 '.%1 table.%2 > tfoot > tr > td, .%1 table.%2 > tfoot > tr > th',
33 'border : #d3d3d3 1px dotted',
37 cssStyleText
= cssTemplate
.replace( /%2/g, showBorderClassName
).replace( /%1/g, 'cke_show_borders ' );
39 var commandDefinition
=
45 exec : function ( editor
)
48 this.refresh( editor
);
51 refresh : function( editor
)
53 if ( editor
.document
)
55 var funcName
= ( this.state
== CKEDITOR
.TRISTATE_ON
) ? 'addClass' : 'removeClass';
56 editor
.document
.getBody()[ funcName
]( 'cke_show_borders' );
61 CKEDITOR
.plugins
.add( 'showborders',
63 requires
: [ 'wysiwygarea' ],
64 modes
: { 'wysiwyg' : 1 },
66 init : function( editor
)
69 var command
= editor
.addCommand( 'showborders', commandDefinition
);
70 command
.canUndo
= false;
72 if ( editor
.config
.startupShowBorders
!== false )
73 command
.setState( CKEDITOR
.TRISTATE_ON
);
75 editor
.addCss( cssStyleText
);
77 // Refresh the command on setData.
78 editor
.on( 'mode', function()
80 if ( command
.state
!= CKEDITOR
.TRISTATE_DISABLED
)
81 command
.refresh( editor
);
84 // Refresh the command on wysiwyg frame reloads.
85 editor
.on( 'contentDom', function()
87 if ( command
.state
!= CKEDITOR
.TRISTATE_DISABLED
)
88 command
.refresh( editor
);
91 editor
.on( 'removeFormatCleanup', function( evt
)
93 var element
= evt
.data
;
94 if ( editor
.getCommand( 'showborders' ).state
== CKEDITOR
.TRISTATE_ON
&&
95 element
.is( 'table' ) && ( !element
.hasAttribute( 'border' ) || parseInt( element
.getAttribute( 'border' ), 10 ) <= 0 ) )
96 element
.addClass( showBorderClassName
);
100 afterInit : function( editor
)
102 var dataProcessor
= editor
.dataProcessor
,
103 dataFilter
= dataProcessor
&& dataProcessor
.dataFilter
,
104 htmlFilter
= dataProcessor
&& dataProcessor
.htmlFilter
;
112 'table' : function( element
)
114 var attributes
= element
.attributes
,
115 cssClass
= attributes
[ 'class' ],
116 border
= parseInt( attributes
.border
, 10 );
118 if ( !border
|| border
<= 0 )
119 attributes
[ 'class' ] = ( cssClass
|| '' ) + ' ' + showBorderClassName
;
131 'table' : function( table
)
133 var attributes
= table
.attributes
,
134 cssClass
= attributes
[ 'class' ];
136 cssClass
&& ( attributes
[ 'class' ] =
137 cssClass
.replace( showBorderClassName
, '' )
138 .replace( /\s{2}/, ' ' )
139 .replace( /^\s+|\s+$/, '' ) );
147 // Table dialog must be aware of it.
148 CKEDITOR
.on( 'dialogDefinition', function( ev
)
150 var dialogName
= ev
.data
.name
;
152 if ( dialogName
== 'table' || dialogName
== 'tableProperties' )
154 var dialogDefinition
= ev
.data
.definition
,
155 infoTab
= dialogDefinition
.getContents( 'info' ),
156 borderField
= infoTab
.get( 'txtBorder' ),
157 originalCommit
= borderField
.commit
;
159 borderField
.commit
= CKEDITOR
.tools
.override( originalCommit
, function( org
)
161 return function( data
, selectedTable
)
163 org
.apply( this, arguments
);
164 var value
= parseInt( this.getValue(), 10 );
165 selectedTable
[ ( !value
|| value
<= 0 ) ? 'addClass' : 'removeClass' ]( showBorderClassName
);
169 var advTab
= dialogDefinition
.getContents( 'advanced' ),
170 classField
= advTab
&& advTab
.get( 'advCSSClasses' );
174 classField
.setup
= CKEDITOR
.tools
.override( classField
.setup
, function( originalSetup
)
178 originalSetup
.apply( this, arguments
);
179 this.setValue( this.getValue().replace( /cke_show_border/, '' ) );
183 classField
.commit
= CKEDITOR
.tools
.override( classField
.commit
, function( originalCommit
)
185 return function( data
, element
)
187 originalCommit
.apply( this, arguments
);
189 if ( !parseInt( element
.getAttribute( 'border' ), 10 ) )
190 element
.addClass( 'cke_show_border' );
200 * Whether to automatically enable the "show borders" command when the editor loads.
201 * (ShowBorders in FCKeditor)
202 * @name CKEDITOR.config.startupShowBorders
206 * config.startupShowBorders = false;