]>
git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - sources/plugins/showborders/plugin.js
2 * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md 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.
12 var commandDefinition
= {
17 exec: function( editor
) {
19 this.refresh( editor
);
22 refresh: function( editor
) {
23 if ( editor
.document
) {
24 var funcName
= ( this.state
== CKEDITOR
.TRISTATE_ON
) ? 'attachClass' : 'removeClass';
25 editor
.editable()[ funcName
]( 'cke_show_borders' );
30 var showBorderClassName
= 'cke_show_border';
32 CKEDITOR
.plugins
.add( 'showborders', {
33 modes: { 'wysiwyg': 1 },
38 // TODO: For IE6, we don't have child selector support,
39 // where nested table cells could be incorrect.
40 ( CKEDITOR
.env
.ie6Compat
? [
42 '.%1 table.%2 td, .%1 table.%2 th',
44 'border : #d3d3d3 1px dotted',
48 '.%1 table.%2 > tr > td, .%1 table.%2 > tr > th,',
49 '.%1 table.%2 > tbody > tr > td, .%1 table.%2 > tbody > tr > th,',
50 '.%1 table.%2 > thead > tr > td, .%1 table.%2 > thead > tr > th,',
51 '.%1 table.%2 > tfoot > tr > td, .%1 table.%2 > tfoot > tr > th',
53 'border : #d3d3d3 1px dotted',
57 cssStyleText
= cssTemplate
.replace( /%2/g, showBorderClassName
).replace( /%1/g, 'cke_show_borders ' );
59 CKEDITOR
.addCss( cssStyleText
);
62 init: function( editor
) {
64 var command
= editor
.addCommand( 'showborders', commandDefinition
);
65 command
.canUndo
= false;
67 if ( editor
.config
.startupShowBorders
!== false )
68 command
.setState( CKEDITOR
.TRISTATE_ON
);
70 // Refresh the command on setData.
71 editor
.on( 'mode', function() {
72 if ( command
.state
!= CKEDITOR
.TRISTATE_DISABLED
)
73 command
.refresh( editor
);
76 // Refresh the command on wysiwyg frame reloads.
77 editor
.on( 'contentDom', function() {
78 if ( command
.state
!= CKEDITOR
.TRISTATE_DISABLED
)
79 command
.refresh( editor
);
82 editor
.on( 'removeFormatCleanup', function( evt
) {
83 var element
= evt
.data
;
84 if ( editor
.getCommand( 'showborders' ).state
== CKEDITOR
.TRISTATE_ON
&& element
.is( 'table' ) && ( !element
.hasAttribute( 'border' ) || parseInt( element
.getAttribute( 'border' ), 10 ) <= 0 ) )
85 element
.addClass( showBorderClassName
);
89 afterInit: function( editor
) {
90 var dataProcessor
= editor
.dataProcessor
,
91 dataFilter
= dataProcessor
&& dataProcessor
.dataFilter
,
92 htmlFilter
= dataProcessor
&& dataProcessor
.htmlFilter
;
95 dataFilter
.addRules( {
97 'table': function( element
) {
98 var attributes
= element
.attributes
,
99 cssClass
= attributes
[ 'class' ],
100 border
= parseInt( attributes
.border
, 10 );
102 if ( ( !border
|| border
<= 0 ) && ( !cssClass
|| cssClass
.indexOf( showBorderClassName
) == -1 ) )
103 attributes
[ 'class' ] = ( cssClass
|| '' ) + ' ' + showBorderClassName
;
110 htmlFilter
.addRules( {
112 'table': function( table
) {
113 var attributes
= table
.attributes
,
114 cssClass
= attributes
[ 'class' ];
116 cssClass
&& ( attributes
[ 'class' ] = cssClass
.replace( showBorderClassName
, '' ).replace( /\s{2}/, ' ' ).replace( /^\s+|\s+$/, '' ) );
124 // Table dialog must be aware of it.
125 CKEDITOR
.on( 'dialogDefinition', function( ev
) {
126 var dialogName
= ev
.data
.name
;
128 if ( dialogName
== 'table' || dialogName
== 'tableProperties' ) {
129 var dialogDefinition
= ev
.data
.definition
,
130 infoTab
= dialogDefinition
.getContents( 'info' ),
131 borderField
= infoTab
.get( 'txtBorder' ),
132 originalCommit
= borderField
.commit
;
134 borderField
.commit
= CKEDITOR
.tools
.override( originalCommit
, function( org
) {
135 return function( data
, selectedTable
) {
136 org
.apply( this, arguments
);
137 var value
= parseInt( this.getValue(), 10 );
138 selectedTable
[ ( !value
|| value
<= 0 ) ? 'addClass' : 'removeClass' ]( showBorderClassName
);
142 var advTab
= dialogDefinition
.getContents( 'advanced' ),
143 classField
= advTab
&& advTab
.get( 'advCSSClasses' );
146 classField
.setup
= CKEDITOR
.tools
.override( classField
.setup
, function( originalSetup
) {
148 originalSetup
.apply( this, arguments
);
149 this.setValue( this.getValue().replace( /cke_show_border/, '' ) );
153 classField
.commit
= CKEDITOR
.tools
.override( classField
.commit
, function( originalCommit
) {
154 return function( data
, element
) {
155 originalCommit
.apply( this, arguments
);
157 if ( !parseInt( element
.getAttribute( 'border' ), 10 ) )
158 element
.addClass( 'cke_show_border' );
168 * Whether to automatically enable the "show borders" command when the editor loads.
170 * config.startupShowBorders = false;
172 * @cfg {Boolean} [startupShowBorders=true]
173 * @member CKEDITOR.config