]>
git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - plugin.js
09745be6cc943fa8e6e65183a307dd323b8f09c9
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
7 * @fileOverview The Source Editing Area plugin. It registers the "source" editing
8 * mode, which displays raw HTML data being edited in the editor.
12 CKEDITOR
.plugins
.add( 'sourcearea', {
13 // jscs:disable maximumLineLength
14 lang: 'af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,es-mx,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,oc,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%
15 // jscs:enable maximumLineLength
16 icons: 'source,source-rtl', // %REMOVE_LINE_CORE%
17 hidpi: true, // %REMOVE_LINE_CORE%
18 init: function( editor
) {
19 // Source mode in inline editors is only available through the "sourcedialog" plugin.
20 if ( editor
.elementMode
== CKEDITOR
.ELEMENT_MODE_INLINE
)
23 var sourcearea
= CKEDITOR
.plugins
.sourcearea
;
25 editor
.addMode( 'source', function( callback
) {
26 var contentsSpace
= editor
.ui
.space( 'contents' ),
27 textarea
= contentsSpace
.getDocument().createElement( 'textarea' );
30 CKEDITOR
.tools
.extend( {
31 // IE7 has overflow the <textarea> from wrapping table cell.
32 width: CKEDITOR
.env
.ie7Compat
? '99%' : '100%',
38 CKEDITOR
.tools
.cssVendorPrefix( 'tab-size', editor
.config
.sourceAreaTabSize
|| 4 ) ) );
40 // Make sure that source code is always displayed LTR,
41 // regardless of editor language (http://dev.ckeditor.com/ticket/10105).
42 textarea
.setAttribute( 'dir', 'ltr' );
44 textarea
.addClass( 'cke_source' ).addClass( 'cke_reset' ).addClass( 'cke_enable_context_menu' );
46 editor
.ui
.space( 'contents' ).append( textarea
);
48 var editable
= editor
.editable( new sourceEditable( editor
, textarea
) );
50 // Fill the textarea with the current editor data.
51 editable
.setData( editor
.getData( 1 ) );
53 // Having to make <textarea> fixed sized to conquer the following bugs:
54 // 1. The textarea height/width='100%' doesn't constraint to the 'td' in IE6/7.
55 // 2. Unexpected vertical-scrolling behavior happens whenever focus is moving out of editor
56 // if text content within it has overflowed. (http://dev.ckeditor.com/ticket/4762)
57 if ( CKEDITOR
.env
.ie
) {
58 editable
.attachListener( editor
, 'resize', onResize
, editable
);
59 editable
.attachListener( CKEDITOR
.document
.getWindow(), 'resize', onResize
, editable
);
60 CKEDITOR
.tools
.setTimeout( onResize
, 0, editable
);
63 editor
.fire( 'ariaWidget', this );
68 editor
.addCommand( 'source', sourcearea
.commands
.source
);
70 if ( editor
.ui
.addButton
) {
71 editor
.ui
.addButton( 'Source', {
72 label: editor
.lang
.sourcearea
.toolbar
,
78 editor
.on( 'mode', function() {
79 editor
.getCommand( 'source' ).setState( editor
.mode
== 'source' ? CKEDITOR
.TRISTATE_ON : CKEDITOR
.TRISTATE_OFF
);
82 var needsFocusHack
= CKEDITOR
.env
.ie
&& CKEDITOR
.env
.version
== 9;
85 // We have to do something with focus on IE9, because if sourcearea had focus
86 // before being resized, the caret ends somewhere in the editor UI (http://dev.ckeditor.com/ticket/11839).
87 var wasActive
= needsFocusHack
&& this.equals( CKEDITOR
.document
.getActive() );
89 // Holder rectange size is stretched by textarea,
90 // so hide it just for a moment.
92 this.setStyle( 'height', this.getParent().$.clientHeight
+ 'px' );
93 this.setStyle( 'width', this.getParent().$.clientWidth
+ 'px' );
94 // When we have proper holder size, show textarea again.
103 var sourceEditable
= CKEDITOR
.tools
.createClass( {
104 base: CKEDITOR
.editable
,
106 setData: function( data
) {
107 this.setValue( data
);
108 this.status
= 'ready';
109 this.editor
.fire( 'dataReady' );
112 getData: function() {
113 return this.getValue();
116 // Insertions are not supported in source editable.
117 insertHtml: function() {},
118 insertElement: function() {},
119 insertText: function() {},
121 // Read-only support for textarea.
122 setReadOnly: function( isReadOnly
) {
123 this[ ( isReadOnly
? 'set' : 'remove' ) + 'Attribute' ]( 'readOnly', 'readonly' );
127 sourceEditable
.baseProto
.detach
.call( this );
128 this.clearCustomData();
135 CKEDITOR
.plugins
.sourcearea
= {
138 modes: { wysiwyg: 1, source: 1 },
141 exec: function( editor
) {
142 if ( editor
.mode
== 'wysiwyg' )
143 editor
.fire( 'saveSnapshot' );
144 editor
.getCommand( 'source' ).setState( CKEDITOR
.TRISTATE_DISABLED
);
145 editor
.setMode( editor
.mode
== 'source' ? 'wysiwyg' : 'source' );
154 * Controls the `tab-size` CSS property of the source editing area. Use it to set the width
155 * of the tab character in the source view. Enter an integer to denote the number of spaces
156 * that the tab will contain.
158 * **Note:** Works only with {@link #dataIndentationChars}
159 * set to `'\t'`. Please consider that not all browsers support the `tab-size` CSS
162 * // Set tab-size to 10 characters.
163 * config.sourceAreaTabSize = 10;
165 * @cfg {Number} [sourceAreaTabSize=4]
166 * @member CKEDITOR.config
167 * @see CKEDITOR.config#dataIndentationChars