|
| 1 | +/** |
| 2 | + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. |
| 3 | + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license |
| 4 | + */ |
| 5 | + |
| 6 | +'use strict'; |
| 7 | + |
| 8 | +( function() { |
| 9 | + CKEDITOR.dialog.add( 'codeSnippet', function( editor ) { |
| 10 | + var snippetLangs = editor._.codesnippet.langs, |
| 11 | + lang = editor.lang.codesnippet, |
| 12 | + clientHeight = document.documentElement.clientHeight, |
| 13 | + langSelectItems = [], |
| 14 | + snippetLangId; |
| 15 | + |
| 16 | + langSelectItems.push( [ editor.lang.common.notSet, '' ] ); |
| 17 | + |
| 18 | + for ( snippetLangId in snippetLangs ) |
| 19 | + langSelectItems.push( [ snippetLangs[ snippetLangId ], snippetLangId ] ); |
| 20 | + |
| 21 | + // Size adjustments. |
| 22 | + var size = CKEDITOR.document.getWindow().getViewPaneSize(), |
| 23 | + // Make it maximum 800px wide, but still fully visible in the viewport. |
| 24 | + width = Math.min( size.width - 70, 800 ), |
| 25 | + // Make it use 2/3 of the viewport height. |
| 26 | + height = size.height / 1.5; |
| 27 | + |
| 28 | + // Low resolution settings. |
| 29 | + if ( clientHeight < 650 ) { |
| 30 | + height = clientHeight - 220; |
| 31 | + } |
| 32 | + |
| 33 | + return { |
| 34 | + title: lang.title, |
| 35 | + minHeight: 200, |
| 36 | + resizable: CKEDITOR.DIALOG_RESIZE_NONE, |
| 37 | + contents: [ |
| 38 | + { |
| 39 | + id: 'info', |
| 40 | + elements: [ |
| 41 | + { |
| 42 | + id: 'lang', |
| 43 | + type: 'select', |
| 44 | + label: lang.language, |
| 45 | + items: langSelectItems, |
| 46 | + setup: function( widget ) { |
| 47 | + if ( widget.ready && widget.data.lang ) |
| 48 | + this.setValue( widget.data.lang ); |
| 49 | + |
| 50 | + // The only way to have an empty select value in Firefox is |
| 51 | + // to set a negative selectedIndex. |
| 52 | + if ( CKEDITOR.env.gecko && ( !widget.data.lang || !widget.ready ) ) |
| 53 | + this.getInputElement().$.selectedIndex = -1; |
| 54 | + }, |
| 55 | + commit: function( widget ) { |
| 56 | + widget.setData( 'lang', this.getValue() ); |
| 57 | + } |
| 58 | + }, |
| 59 | + { |
| 60 | + id: 'code', |
| 61 | + type: 'textarea', |
| 62 | + label: lang.codeContents, |
| 63 | + setup: function( widget ) { |
| 64 | + this.setValue( widget.data.code ); |
| 65 | + }, |
| 66 | + commit: function( widget ) { |
| 67 | + widget.setData( 'code', this.getValue() ); |
| 68 | + }, |
| 69 | + required: true, |
| 70 | + validate: CKEDITOR.dialog.validate.notEmpty( lang.emptySnippetError ), |
| 71 | + inputStyle: 'cursor:auto;' + |
| 72 | + 'width:' + width + 'px;' + |
| 73 | + 'height:' + height + 'px;' + |
| 74 | + 'tab-size:4;' + |
| 75 | + 'text-align:left;', |
| 76 | + 'class': 'cke_source' |
| 77 | + } |
| 78 | + ] |
| 79 | + } |
| 80 | + ] |
| 81 | + }; |
| 82 | + } ); |
| 83 | +}() ); |
0 commit comments