03826f3fd881e96b207e1d9c1f79c615bba752b6.svn-base
2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
* @fileOverview The "showblocks" plugin. Enable it will make all block level
* elements being decorated with a border and the element name
* displayed on the left-right corner.
*/
(function()
{
var cssTemplate = '.%2 p,'+
'.%2 div,'+
'.%2 pre,'+
'.%2 address,'+
'.%2 blockquote,'+
'.%2 h1,'+
'.%2 h2,'+
'.%2 h3,'+
'.%2 h4,'+
'.%2 h5,'+
'.%2 h6'+
'{'+
'background-repeat: no-repeat;'+
'background-position: top %3;'+
'border: 1px dotted gray;'+
'padding-top: 8px;'+
'padding-%3: 8px;'+
'}'+
'.%2 p'+
'{'+
'%1p.png);'+
'}'+
'.%2 div'+
'{'+
'%1div.png);'+
'}'+
'.%2 pre'+
'{'+
'%1pre.png);'+
'}'+
'.%2 address'+
'{'+
'%1address.png);'+
'}'+
'.%2 blockquote'+
'{'+
'%1blockquote.png);'+
'}'+
'.%2 h1'+
'{'+
'%1h1.png);'+
'}'+
'.%2 h2'+
'{'+
'%1h2.png);'+
'}'+
'.%2 h3'+
'{'+
'%1h3.png);'+
'}'+
'.%2 h4'+
'{'+
'%1h4.png);'+
'}'+
'.%2 h5'+
'{'+
'%1h5.png);'+
'}'+
'.%2 h6'+
'{'+
'%1h6.png);'+
'}';
var cssTemplateRegex = /%1/g, cssClassRegex = /%2/g, backgroundPositionRegex = /%3/g;
var commandDefinition =
{
readOnly : 1,
preserveState : true,
editorFocus : false,
exec : function ( editor )
{
this.toggleState();
this.refresh( editor );
},
refresh : function( editor )
{
if ( editor.document )
{
var funcName = ( this.state == CKEDITOR.TRISTATE_ON ) ? 'addClass' : 'removeClass';
editor.document.getBody()[ funcName ]( 'cke_show_blocks' );
}
}
};
CKEDITOR.plugins.add( 'showblocks',
{
requires : [ 'wysiwygarea' ],
init : function( editor )
{
var command = editor.addCommand( 'showblocks', commandDefinition );
command.canUndo = false;
if ( editor.config.startupOutlineBlocks )
command.setState( CKEDITOR.TRISTATE_ON );
editor.addCss( cssTemplate
.replace( cssTemplateRegex, 'background-image: url(' + CKEDITOR.getUrl( this.path ) + 'images/block_' )
.replace( cssClassRegex, 'cke_show_blocks ' )
.replace( backgroundPositionRegex, editor.lang.dir == 'rtl' ? 'right' : 'left' ) );
editor.ui.addButton( 'ShowBlocks',
{
label : editor.lang.showBlocks,
command : 'showblocks'
});
// Refresh the command on setData.
editor.on( 'mode', function()
{
if ( command.state != CKEDITOR.TRISTATE_DISABLED )
command.refresh( editor );
});
// Refresh the command on setData.
editor.on( 'contentDom', function()
{
if ( command.state != CKEDITOR.TRISTATE_DISABLED )
command.refresh( editor );
});
}
});
} )();
/**
* Whether to automaticaly enable the "show block" command when the editor
* loads. (StartupShowBlocks in FCKeditor)
* @name CKEDITOR.config.startupOutlineBlocks
* @type Boolean
* @default false
* @example
* config.startupOutlineBlocks = true;
*/