2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview The "show border" plugin. The command display visible outline
\r
8 * border line around all table elements if table doesn't have a none-zero 'border' attribute specified.
\r
13 var showBorderClassName = 'cke_show_border',
\r
16 // TODO: For IE6, we don't have child selector support,
\r
17 // where nested table cells could be incorrect.
\r
18 ( CKEDITOR.env.ie6Compat ?
\r
21 '.%1 table.%2 td, .%1 table.%2 th,',
\r
23 'border : #d3d3d3 1px dotted',
\r
28 '.%1 table.%2 > tr > td, .%1 table.%2 > tr > th,',
\r
29 '.%1 table.%2 > tbody > tr > td, .%1 table.%2 > tbody > tr > th,',
\r
30 '.%1 table.%2 > thead > tr > td, .%1 table.%2 > thead > tr > th,',
\r
31 '.%1 table.%2 > tfoot > tr > td, .%1 table.%2 > tfoot > tr > th',
\r
33 'border : #d3d3d3 1px dotted',
\r
37 cssStyleText = cssTemplate.replace( /%2/g, showBorderClassName ).replace( /%1/g, 'cke_show_borders ' );
\r
39 var commandDefinition =
\r
41 preserveState : true,
\r
42 editorFocus : false,
\r
44 exec : function ( editor )
\r
47 this.refresh( editor );
\r
50 refresh : function( editor )
\r
52 var funcName = ( this.state == CKEDITOR.TRISTATE_ON ) ? 'addClass' : 'removeClass';
\r
53 editor.document.getBody()[ funcName ]( 'cke_show_borders' );
\r
57 CKEDITOR.plugins.add( 'showborders',
\r
59 requires : [ 'wysiwygarea' ],
\r
60 modes : { 'wysiwyg' : 1 },
\r
62 init : function( editor )
\r
65 var command = editor.addCommand( 'showborders', commandDefinition );
\r
66 command.canUndo = false;
\r
68 if ( editor.config.startupShowBorders !== false )
\r
69 command.setState( CKEDITOR.TRISTATE_ON );
\r
71 editor.addCss( cssStyleText );
\r
73 // Refresh the command on setData.
\r
74 editor.on( 'mode', function()
\r
76 if ( command.state != CKEDITOR.TRISTATE_DISABLED )
\r
77 command.refresh( editor );
\r
78 }, null, null, 100 );
\r
80 // Refresh the command on wysiwyg frame reloads.
\r
81 editor.on( 'contentDom', function()
\r
83 if ( command.state != CKEDITOR.TRISTATE_DISABLED )
\r
84 command.refresh( editor );
\r
88 afterInit : function( editor )
\r
90 var dataProcessor = editor.dataProcessor,
\r
91 dataFilter = dataProcessor && dataProcessor.dataFilter,
\r
92 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
\r
96 dataFilter.addRules(
\r
100 'table' : function( element )
\r
102 var attributes = element.attributes,
\r
103 cssClass = attributes[ 'class' ],
\r
104 border = parseInt( attributes.border, 10 );
\r
106 if ( !border || border <= 0 )
\r
107 attributes[ 'class' ] = ( cssClass || '' ) + ' ' + showBorderClassName;
\r
115 htmlFilter.addRules(
\r
119 'table' : function( table )
\r
121 var attributes = table.attributes,
\r
122 cssClass = attributes[ 'class' ];
\r
124 cssClass && ( attributes[ 'class' ] =
\r
125 cssClass.replace( showBorderClassName, '' )
\r
126 .replace( /\s{2}/, ' ' )
\r
127 .replace( /^\s+|\s+$/, '' ) );
\r
133 // Table dialog must be aware of it.
\r
134 CKEDITOR.on( 'dialogDefinition', function( ev )
\r
136 if ( ev.editor != editor )
\r
139 var dialogName = ev.data.name;
\r
141 if ( dialogName == 'table' || dialogName == 'tableProperties' )
\r
143 var dialogDefinition = ev.data.definition,
\r
144 infoTab = dialogDefinition.getContents( 'info' ),
\r
145 borderField = infoTab.get( 'txtBorder' ),
\r
146 originalCommit = borderField.commit;
\r
148 borderField.commit = CKEDITOR.tools.override( originalCommit, function( org )
\r
150 return function( data, selectedTable )
\r
152 org.apply( this, arguments );
\r
153 var value = parseInt( this.getValue(), 10 );
\r
154 selectedTable[ ( !value || value <= 0 ) ? 'addClass' : 'removeClass' ]( showBorderClassName );
\r
165 * Whether to automatically enable the "show borders" command when the editor loads.
\r
169 * config.startupShowBorders = false;
\r