1 | /**
|
---|
2 | * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
|
---|
3 | * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
---|
4 | */
|
---|
5 |
|
---|
6 | CKEDITOR.dialog.add( 'sourcedialog', function( editor ) {
|
---|
7 | var size = CKEDITOR.document.getWindow().getViewPaneSize();
|
---|
8 |
|
---|
9 | // Make it maximum 800px wide, but still fully visible in the viewport.
|
---|
10 | var width = Math.min( size.width - 70, 800 );
|
---|
11 |
|
---|
12 | // Make it use 2/3 of the viewport height.
|
---|
13 | var height = size.height / 1.5;
|
---|
14 |
|
---|
15 | // Store old editor data to avoid unnecessary setData.
|
---|
16 | var oldData;
|
---|
17 |
|
---|
18 | return {
|
---|
19 | title: editor.lang.sourcedialog.title,
|
---|
20 | minWidth: 100,
|
---|
21 | minHeight: 100,
|
---|
22 |
|
---|
23 | onShow: function() {
|
---|
24 | this.setValueOf( 'main', 'data', oldData = editor.getData() );
|
---|
25 | },
|
---|
26 |
|
---|
27 | onOk: ( function() {
|
---|
28 | function setData( dialog, newData ) {
|
---|
29 | // [IE8] Focus editor before setting selection to avoid setting data on
|
---|
30 | // locked selection, because in case of inline editor, it won't be
|
---|
31 | // unlocked before editable's HTML is altered. (https://dev.ckeditor.com/ticket/11585)
|
---|
32 | editor.focus();
|
---|
33 | editor.setData( newData, function() {
|
---|
34 | dialog.hide();
|
---|
35 |
|
---|
36 | // Ensure correct selection.
|
---|
37 | var range = editor.createRange();
|
---|
38 | range.moveToElementEditStart( editor.editable() );
|
---|
39 | range.select();
|
---|
40 | } );
|
---|
41 | }
|
---|
42 |
|
---|
43 | return function() {
|
---|
44 | // Remove CR from input data for reliable comparison with editor data.
|
---|
45 | var newData = this.getValueOf( 'main', 'data' ).replace( /\r/g, '' ),
|
---|
46 | that = this;
|
---|
47 |
|
---|
48 | // Avoid unnecessary setData. Also preserve selection
|
---|
49 | // when user changed his mind and goes back to wysiwyg editing.
|
---|
50 | if ( newData === oldData )
|
---|
51 | return true;
|
---|
52 |
|
---|
53 | setTimeout( function() {
|
---|
54 | setData( that, newData );
|
---|
55 | } );
|
---|
56 |
|
---|
57 | // Don't let the dialog close before setData is over, to hide
|
---|
58 | // from user blinking caused by selection restoring and setting new data.
|
---|
59 | return false;
|
---|
60 | };
|
---|
61 | } )(),
|
---|
62 |
|
---|
63 | contents: [ {
|
---|
64 | id: 'main',
|
---|
65 | label: editor.lang.sourcedialog.title,
|
---|
66 | elements: [ {
|
---|
67 | type: 'textarea',
|
---|
68 | id: 'data',
|
---|
69 | dir: 'ltr',
|
---|
70 | inputStyle: 'cursor:auto;' +
|
---|
71 | 'width:' + width + 'px;' +
|
---|
72 | 'height:' + height + 'px;' +
|
---|
73 | 'tab-size:4;' +
|
---|
74 | 'text-align:left;',
|
---|
75 | 'class': 'cke_source'
|
---|
76 | } ]
|
---|
77 | } ]
|
---|
78 | };
|
---|
79 | } );
|
---|