| 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 cssStyleText, |
| 14 | cssTemplate = |
| 15 | // TODO: For IE6, we don't have child selector support, where nested table style could be incorrect. |
| 16 | ( CKEDITOR.env.ie6Compat ? |
| 17 | [ |
| 18 | '.%1 table%2,', |
| 19 | '.%1 table%2 td, .%1 table%2 th,', |
| 20 | '{', |
| 21 | 'border : #d3d3d3 1px dotted', |
| 22 | '}' |
| 23 | ] : |
| 24 | [ |
| 25 | '.%1 table%2,', |
| 26 | '.%1 table%2 > tr > td, .%1 table%2 > tr > th,', |
| 27 | '.%1 table%2 > tbody > tr > td, .%1 table%2 > tbody > tr > th,', |
| 28 | '.%1 table%2 > thead > tr > td, .%1 table%2 > thead > tr > th,', |
| 29 | '.%1 table%2 > tfoot > tr > td, .%1 table%2 > tfoot > tr > th', |
| 30 | '{', |
| 31 | 'border : #d3d3d3 1px dotted', |
| 32 | '}' |
| 33 | ] ).join( '' ); |
| 34 | |
| 35 | if( CKEDITOR.env.ie ) |
| 36 | { |
| 37 | // For IE we use a HTC behavior on table to mimic the desired selector. |
| 38 | cssStyleText = |
| 39 | [ |
| 40 | cssTemplate.replace( /%2/g, '.cke_no_border' ) |
| 41 | ]; |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | cssStyleText = |
| 46 | [ |
| 47 | // For tables with the "border" attribute set to "0" , IE7 doesn't support |
| 48 | // attribute selector on 'border' particularly (weirld). |
| 49 | cssTemplate.replace( /%2/g, '[border="0"]' ), |
| 50 | // For tables with no "border" attribute set, IE8 doesn't support CSS3 |
| 51 | // pseudo selector: not(...) |
| 52 | cssTemplate.replace( /%2/g, ':not([border])' ) |
| 53 | ]; |
| 54 | } |
| 55 | |
| 56 | var commandDefinition = |
| 57 | { |
| 58 | preserveState : true, |
| 59 | editorFocus : false, |
| 60 | |
| 61 | exec : function ( editor ) |
| 62 | { |
| 63 | this.toggleState(); |
| 64 | this.refresh( editor ); |
| 65 | }, |
| 66 | |
| 67 | refresh : function( editor ) |
| 68 | { |
| 69 | var funcName = ( this.state == CKEDITOR.TRISTATE_ON ) ? 'addClass' : 'removeClass'; |
| 70 | editor.document.getBody()[ funcName ]( 'cke_show_borders' ); |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | CKEDITOR.plugins.add( 'showborders', |
| 75 | { |
| 76 | requires : [ 'wysiwygarea' ], |
| 77 | modes : { 'wysiwyg' : 1 }, |
| 78 | |
| 79 | init : function( editor ) |
| 80 | { |
| 81 | if( CKEDITOR.env.ie ) |
| 82 | cssStyleText.push( 'table', '{ behavior: ' + 'url(' + this.path + 'assets/showtableborders.htc)' + '; }' ); |
| 83 | |
| 84 | var command = editor.addCommand( 'showborders', commandDefinition ); |
| 85 | command.canUndo = false; |
| 86 | |
| 87 | if ( editor.config.startupShowBorders ) |
| 88 | command.setState( CKEDITOR.TRISTATE_ON ); |
| 89 | |
| 90 | editor.addCss( cssStyleText.join( '\n' ). |
| 91 | replace( /%1/g, 'cke_show_borders ' ) ); |
| 92 | |
| 93 | // Refresh the command on setData. |
| 94 | editor.on( 'mode', function() |
| 95 | { |
| 96 | if ( command.state != CKEDITOR.TRISTATE_DISABLED ) |
| 97 | command.refresh( editor ); |
| 98 | }, null, null, 100 ); |
| 99 | |
| 100 | // Refresh the command on wysiwyg frame reloads. |
| 101 | editor.on( 'contentDom', function() |
| 102 | { |
| 103 | if ( command.state != CKEDITOR.TRISTATE_DISABLED ) |
| 104 | command.refresh( editor ); |
| 105 | }); |
| 106 | } |
| 107 | }); |
| 108 | } )(); |
| 109 | |