]>
Commit | Line | Data |
---|---|---|
7adcb81e | 1 | /**\r |
3b35bd27 | 2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.\r |
7adcb81e IB |
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license\r |
4 | */\r | |
5 | \r | |
6 | /**\r | |
7 | * @fileOverview The "showblocks" plugin. Enable it will make all block level\r | |
8 | * elements being decorated with a border and the element name\r | |
9 | * displayed on the left-right corner.\r | |
10 | */\r | |
11 | \r | |
12 | ( function() {\r | |
13 | 'use strict';\r | |
14 | \r | |
15 | var commandDefinition = {\r | |
16 | readOnly: 1,\r | |
17 | preserveState: true,\r | |
18 | editorFocus: false,\r | |
19 | \r | |
20 | exec: function( editor ) {\r | |
21 | this.toggleState();\r | |
22 | this.refresh( editor );\r | |
23 | },\r | |
24 | \r | |
25 | refresh: function( editor ) {\r | |
26 | if ( editor.document ) {\r | |
27 | // Show blocks turns inactive after editor loses focus when in inline.\r | |
28 | var showBlocks = ( this.state == CKEDITOR.TRISTATE_ON && ( editor.elementMode != CKEDITOR.ELEMENT_MODE_INLINE || editor.focusManager.hasFocus ) );\r | |
29 | \r | |
30 | var funcName = showBlocks ? 'attachClass' : 'removeClass';\r | |
31 | editor.editable()[ funcName ]( 'cke_show_blocks' );\r | |
32 | }\r | |
33 | }\r | |
34 | };\r | |
35 | \r | |
36 | CKEDITOR.plugins.add( 'showblocks', {\r | |
37 | // jscs:disable maximumLineLength\r | |
3b35bd27 | 38 | lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%\r |
7adcb81e IB |
39 | // jscs:enable maximumLineLength\r |
40 | icons: 'showblocks,showblocks-rtl', // %REMOVE_LINE_CORE%\r | |
41 | hidpi: true, // %REMOVE_LINE_CORE%\r | |
42 | onLoad: function() {\r | |
43 | var tags = [ 'p', 'div', 'pre', 'address', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ],\r | |
44 | cssStd, cssImg, cssLtr, cssRtl,\r | |
45 | path = CKEDITOR.getUrl( this.path ),\r | |
46 | // #10884 don't apply showblocks styles to non-editable elements and chosen ones.\r | |
47 | // IE8 does not support :not() pseudoclass, so we need to reset showblocks rather\r | |
48 | // than 'prevent' its application. We do that by additional rules.\r | |
49 | supportsNotPseudoclass = !( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ),\r | |
50 | notDisabled = supportsNotPseudoclass ? ':not([contenteditable=false]):not(.cke_show_blocks_off)' : '',\r | |
51 | tag, trailing;\r | |
52 | \r | |
53 | cssStd = cssImg = cssLtr = cssRtl = '';\r | |
54 | \r | |
55 | while ( ( tag = tags.pop() ) ) {\r | |
56 | trailing = tags.length ? ',' : '';\r | |
57 | \r | |
58 | cssStd += '.cke_show_blocks ' + tag + notDisabled + trailing;\r | |
59 | cssLtr += '.cke_show_blocks.cke_contents_ltr ' + tag + notDisabled + trailing;\r | |
60 | cssRtl += '.cke_show_blocks.cke_contents_rtl ' + tag + notDisabled + trailing;\r | |
61 | cssImg += '.cke_show_blocks ' + tag + notDisabled + '{' +\r | |
62 | 'background-image:url(' + CKEDITOR.getUrl( path + 'images/block_' + tag + '.png' ) + ')' +\r | |
63 | '}';\r | |
64 | }\r | |
65 | \r | |
66 | // .cke_show_blocks p { ... }\r | |
67 | cssStd += '{' +\r | |
68 | 'background-repeat:no-repeat;' +\r | |
69 | 'border:1px dotted gray;' +\r | |
70 | 'padding-top:8px' +\r | |
71 | '}';\r | |
72 | \r | |
73 | // .cke_show_blocks.cke_contents_ltr p { ... }\r | |
74 | cssLtr += '{' +\r | |
75 | 'background-position:top left;' +\r | |
76 | 'padding-left:8px' +\r | |
77 | '}';\r | |
78 | \r | |
79 | // .cke_show_blocks.cke_contents_rtl p { ... }\r | |
80 | cssRtl += '{' +\r | |
81 | 'background-position:top right;' +\r | |
82 | 'padding-right:8px' +\r | |
83 | '}';\r | |
84 | \r | |
85 | CKEDITOR.addCss( cssStd.concat( cssImg, cssLtr, cssRtl ) );\r | |
86 | \r | |
87 | // [IE8] Reset showblocks styles for non-editables and chosen elements, because\r | |
88 | // it could not be done using :not() pseudoclass (#10884).\r | |
89 | if ( !supportsNotPseudoclass ) {\r | |
90 | CKEDITOR.addCss(\r | |
91 | '.cke_show_blocks [contenteditable=false],.cke_show_blocks .cke_show_blocks_off{' +\r | |
92 | 'border:none;' +\r | |
93 | 'padding-top:0;' +\r | |
94 | 'background-image:none' +\r | |
95 | '}' +\r | |
96 | '.cke_show_blocks.cke_contents_rtl [contenteditable=false],.cke_show_blocks.cke_contents_rtl .cke_show_blocks_off{' +\r | |
97 | 'padding-right:0' +\r | |
98 | '}' +\r | |
99 | '.cke_show_blocks.cke_contents_ltr [contenteditable=false],.cke_show_blocks.cke_contents_ltr .cke_show_blocks_off{' +\r | |
100 | 'padding-left:0' +\r | |
101 | '}'\r | |
102 | );\r | |
103 | }\r | |
104 | },\r | |
105 | init: function( editor ) {\r | |
106 | if ( editor.blockless )\r | |
107 | return;\r | |
108 | \r | |
109 | var command = editor.addCommand( 'showblocks', commandDefinition );\r | |
110 | command.canUndo = false;\r | |
111 | \r | |
112 | if ( editor.config.startupOutlineBlocks )\r | |
113 | command.setState( CKEDITOR.TRISTATE_ON );\r | |
114 | \r | |
115 | editor.ui.addButton && editor.ui.addButton( 'ShowBlocks', {\r | |
116 | label: editor.lang.showblocks.toolbar,\r | |
117 | command: 'showblocks',\r | |
118 | toolbar: 'tools,20'\r | |
119 | } );\r | |
120 | \r | |
121 | // Refresh the command on setData.\r | |
122 | editor.on( 'mode', function() {\r | |
123 | if ( command.state != CKEDITOR.TRISTATE_DISABLED )\r | |
124 | command.refresh( editor );\r | |
125 | } );\r | |
126 | \r | |
127 | // Refresh the command on focus/blur in inline.\r | |
128 | if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE ) {\r | |
129 | editor.on( 'focus', onFocusBlur );\r | |
130 | editor.on( 'blur', onFocusBlur );\r | |
131 | }\r | |
132 | \r | |
133 | // Refresh the command on setData.\r | |
134 | editor.on( 'contentDom', function() {\r | |
135 | if ( command.state != CKEDITOR.TRISTATE_DISABLED )\r | |
136 | command.refresh( editor );\r | |
137 | } );\r | |
138 | \r | |
139 | function onFocusBlur() {\r | |
140 | command.refresh( editor );\r | |
141 | }\r | |
142 | }\r | |
143 | } );\r | |
144 | } )();\r | |
145 | \r | |
146 | /**\r | |
147 | * Whether to automaticaly enable the show block" command when the editor loads.\r | |
148 | *\r | |
149 | * config.startupOutlineBlocks = true;\r | |
150 | *\r | |
151 | * @cfg {Boolean} [startupOutlineBlocks=false]\r | |
152 | * @member CKEDITOR.config\r | |
153 | */\r |