Update ckeditor to version 3.2.1
[gopost.git] / ckeditor / _source / plugins / showborders / plugin.js
blob5987be733e1fe136866cf2bf116765baf14b5c0d
1 /*
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
6 /**
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.
9 */
11 (function()
13 var showBorderClassName = 'cke_show_border',
14 cssStyleText,
15 cssTemplate =
16 // TODO: For IE6, we don't have child selector support,
17 // where nested table cells could be incorrect.
18 ( CKEDITOR.env.ie6Compat ?
20 '.%1 table.%2,',
21 '.%1 table.%2 td, .%1 table.%2 th,',
22 '{',
23 'border : #d3d3d3 1px dotted',
24 '}'
25 ] :
27 '.%1 table.%2,',
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',
32 '{',
33 'border : #d3d3d3 1px dotted',
34 '}'
35 ] ).join( '' );
37 cssStyleText = cssTemplate.replace( /%2/g, showBorderClassName ).replace( /%1/g, 'cke_show_borders ' );
39 var commandDefinition =
41 preserveState : true,
42 editorFocus : false,
44 exec : function ( editor )
46 this.toggleState();
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 );
78 }, null, null, 100 );
80 // Refresh the command on wysiwyg frame reloads.
81 editor.on( 'contentDom', function()
83 if ( command.state != CKEDITOR.TRISTATE_DISABLED )
84 command.refresh( editor );
85 });
88 afterInit : function( editor )
90 var dataProcessor = editor.dataProcessor,
91 dataFilter = dataProcessor && dataProcessor.dataFilter,
92 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
94 if ( dataFilter )
96 dataFilter.addRules(
98 elements :
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;
110 } );
113 if ( htmlFilter )
115 htmlFilter.addRules(
117 elements :
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+$/, '' ) );
130 } );
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 );
155 } );
159 } )();
162 * Whether to automatically enable the "show borders" command when the editor loads.
163 * @type Boolean
164 * @default true
165 * @example
166 * config.startupShowBorders = false;