2 Copyright (c) 2003-2010, 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
=
44 exec : function ( editor
)
47 this.refresh( editor
);
50 refresh : function( editor
)
52 var funcName
= ( this.state
== CKEDITOR
.TRISTATE_ON
) ? 'addClass' : 'removeClass';
53 editor
.document
.getBody()[ funcName
]( 'cke_show_borders' );
57 CKEDITOR
.plugins
.add( 'showborders',
59 requires
: [ 'wysiwygarea' ],
60 modes
: { 'wysiwyg' : 1 },
62 init : function( editor
)
65 var command
= editor
.addCommand( 'showborders', commandDefinition
);
66 command
.canUndo
= false;
68 if ( editor
.config
.startupShowBorders
!== false )
69 command
.setState( CKEDITOR
.TRISTATE_ON
);
71 editor
.addCss( cssStyleText
);
73 // Refresh the command on setData.
74 editor
.on( 'mode', function()
76 if ( command
.state
!= CKEDITOR
.TRISTATE_DISABLED
)
77 command
.refresh( editor
);
80 // Refresh the command on wysiwyg frame reloads.
81 editor
.on( 'contentDom', function()
83 if ( command
.state
!= CKEDITOR
.TRISTATE_DISABLED
)
84 command
.refresh( editor
);
88 afterInit : function( editor
)
90 var dataProcessor
= editor
.dataProcessor
,
91 dataFilter
= dataProcessor
&& dataProcessor
.dataFilter
,
92 htmlFilter
= dataProcessor
&& dataProcessor
.htmlFilter
;
100 'table' : function( element
)
102 var attributes
= element
.attributes
,
103 cssClass
= attributes
[ 'class' ],
104 border
= parseInt( attributes
.border
, 10 );
106 if ( !border
|| border
<= 0 )
107 attributes
[ 'class' ] = ( cssClass
|| '' ) + ' ' + showBorderClassName
;
119 'table' : function( table
)
121 var attributes
= table
.attributes
,
122 cssClass
= attributes
[ 'class' ];
124 cssClass
&& ( attributes
[ 'class' ] =
125 cssClass
.replace( showBorderClassName
, '' )
126 .replace( /\s{2}/, ' ' )
127 .replace( /^\s+|\s+$/, '' ) );
135 // Table dialog must be aware of it.
136 CKEDITOR
.on( 'dialogDefinition', function( ev
)
138 var dialogName
= ev
.data
.name
;
140 if ( dialogName
== 'table' || dialogName
== 'tableProperties' )
142 var dialogDefinition
= ev
.data
.definition
,
143 infoTab
= dialogDefinition
.getContents( 'info' ),
144 borderField
= infoTab
.get( 'txtBorder' ),
145 originalCommit
= borderField
.commit
;
147 borderField
.commit
= CKEDITOR
.tools
.override( originalCommit
, function( org
)
149 return function( data
, selectedTable
)
151 org
.apply( this, arguments
);
152 var value
= parseInt( this.getValue(), 10 );
153 selectedTable
[ ( !value
|| value
<= 0 ) ? 'addClass' : 'removeClass' ]( showBorderClassName
);
162 * Whether to automatically enable the "show borders" command when the editor loads.
166 * config.startupShowBorders = false;