| 1 | /* |
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. |
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license |
| 4 | */ |
| 5 | |
| 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 | */ |
| 10 | |
| 11 | (function() |
| 12 | { |
| 13 | var borderStyleRegex = /%3/g, |
| 14 | selectorRegex = /%2/g, |
| 15 | showBorderRegex = /%1/g; |
| 16 | |
| 17 | var cssTemplate = |
| 18 | [ |
| 19 | '.%1 table%2,', |
| 20 | '.%1 table%2 > tr > td, table%2 > tr > th,', |
| 21 | '.%1 table%2 > tbody > tr > td, table%2 > tbody > tr > th,', |
| 22 | '.%1 table%2 > thead > tr > td, table%2 > thead > tr > th,', |
| 23 | '.%1 table%2 > tfoot > tr > td, table%2 > tfoot > tr > th', |
| 24 | '{', |
| 25 | 'border: %3;', |
| 26 | '}' |
| 27 | ].join( '' ); |
| 28 | |
| 29 | cssTemplate = |
| 30 | [ |
| 31 | // For tables with the "border" attribute set to "0" , IE7 doesn't support |
| 32 | // attribute selector on 'border' particularly (weirld). |
| 33 | cssTemplate.replace( selectorRegex, '[border="0"]' ) |
| 34 | .replace( borderStyleRegex, '#d3d3d3 1px dotted' ), |
| 35 | // For tables with no "border" attribute set, IE8 doesn't support CSS3 |
| 36 | // pseudo selector: not(...) |
| 37 | cssTemplate.replace( selectorRegex, ':not([border])' ) |
| 38 | .replace( borderStyleRegex, '#d3d3d3 1px dotted' ) |
| 39 | ].join( '\n' ); |
| 40 | |
| 41 | var commandDefinition = |
| 42 | { |
| 43 | preserveState : true, |
| 44 | editorFocus : false, |
| 45 | |
| 46 | exec : function ( editor ) |
| 47 | { |
| 48 | this.toggleState(); |
| 49 | this.refresh( editor ); |
| 50 | }, |
| 51 | |
| 52 | refresh : function( editor ) |
| 53 | { |
| 54 | var funcName = ( this.state == CKEDITOR.TRISTATE_ON ) ? 'addClass' : 'removeClass'; |
| 55 | editor.document.getBody()[ funcName ]( 'cke_show_borders' ); |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | CKEDITOR.plugins.add( 'showborders', |
| 60 | { |
| 61 | requires : [ 'wysiwygarea' ], |
| 62 | modes : { 'wysiwyg' : 1 }, |
| 63 | |
| 64 | init : function( editor ) |
| 65 | { |
| 66 | // Doesn't work at all with IE6/7. |
| 67 | if( CKEDITOR.env.ie && !CKEDITOR.env.ie8 ) |
| 68 | return; |
| 69 | |
| 70 | var command = editor.addCommand( 'showborders', commandDefinition ); |
| 71 | command.canUndo = false; |
| 72 | |
| 73 | if ( editor.config.startupShowBorders ) |
| 74 | command.setState( CKEDITOR.TRISTATE_ON ); |
| 75 | |
| 76 | editor.addCss( cssTemplate |
| 77 | .replace( showBorderRegex, 'cke_show_borders ' ) ); |
| 78 | |
| 79 | // Refresh the command on setData. |
| 80 | editor.on( 'mode', function() |
| 81 | { |
| 82 | if ( command.state != CKEDITOR.TRISTATE_DISABLED ) |
| 83 | command.refresh( editor ); |
| 84 | }, null, null, 100 ); |
| 85 | |
| 86 | // Refresh the command on wysiwyg frame reloads. |
| 87 | editor.on( 'contentDom', function() |
| 88 | { |
| 89 | if ( command.state != CKEDITOR.TRISTATE_DISABLED ) |
| 90 | command.refresh( editor ); |
| 91 | }); |
| 92 | } |
| 93 | }); |
| 94 | } )(); |
| 95 | |
| 96 | /** |
| 97 | * Whether to automaticaly enable the "show borders" command when the editor |
| 98 | * loads. |
| 99 | * @type Boolean |
| 100 | * @default false |
| 101 | * @example |
| 102 | * config.startupShowBorders = false; |
| 103 | */ |
| 104 | CKEDITOR.config.startupShowBorders = true; |