codesnippet.js
2.31 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
/**
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
'use strict';
( function() {
CKEDITOR.dialog.add( 'codeSnippet', function( editor ) {
var snippetLangs = editor._.codesnippet.langs,
lang = editor.lang.codesnippet,
clientHeight = document.documentElement.clientHeight,
langSelectItems = [],
snippetLangId;
langSelectItems.push( [ editor.lang.common.notSet, '' ] );
for ( snippetLangId in snippetLangs )
langSelectItems.push( [ snippetLangs[ snippetLangId ], snippetLangId ] );
// Size adjustments.
var size = CKEDITOR.document.getWindow().getViewPaneSize(),
// Make it maximum 800px wide, but still fully visible in the viewport.
width = Math.min( size.width - 70, 800 ),
// Make it use 2/3 of the viewport height.
height = size.height / 1.5;
// Low resolution settings.
if ( clientHeight < 650 ) {
height = clientHeight - 220;
}
return {
title: lang.title,
minHeight: 200,
resizable: CKEDITOR.DIALOG_RESIZE_NONE,
contents: [
{
id: 'info',
elements: [
{
id: 'lang',
type: 'select',
label: lang.language,
items: langSelectItems,
setup: function( widget ) {
if ( widget.ready && widget.data.lang )
this.setValue( widget.data.lang );
// The only way to have an empty select value in Firefox is
// to set a negative selectedIndex.
if ( CKEDITOR.env.gecko && ( !widget.data.lang || !widget.ready ) )
this.getInputElement().$.selectedIndex = -1;
},
commit: function( widget ) {
widget.setData( 'lang', this.getValue() );
}
},
{
id: 'code',
type: 'textarea',
label: lang.codeContents,
setup: function( widget ) {
this.setValue( widget.data.code );
},
commit: function( widget ) {
widget.setData( 'code', this.getValue() );
},
required: true,
validate: CKEDITOR.dialog.validate.notEmpty( lang.emptySnippetError ),
inputStyle: 'cursor:auto;' +
'width:' + width + 'px;' +
'height:' + height + 'px;' +
'tab-size:4;' +
'text-align:left;',
'class': 'cke_source'
}
]
}
]
};
} );
}() );