Index: branches/5.2.x/admin/system_presets/simple/inp_ckconfig.js =================================================================== --- branches/5.2.x/admin/system_presets/simple/inp_ckconfig.js +++ branches/5.2.x/admin/system_presets/simple/inp_ckconfig.js @@ -24,7 +24,7 @@ CKEDITOR.config.entities = false; -CKEDITOR.config.extraPlugins = 'my_link,my_document,my_maximize,my_inline'; +CKEDITOR.config.extraPlugins = 'my_link,my_document,my_maximize,my_inline,sourcedialog'; //CKEDITOR.plugins.add('MySource'); //CKEDITOR.plugins.add('MyPreview'); @@ -58,7 +58,7 @@ ['Find', 'Replace', 'Scayt'], '/', ['Styles'], ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'], - ['NumberedList', 'BulletedList', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] + ['NumberedList', 'BulletedList', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'Sourcedialog'] ]; /*CKEDITOR.config.toolbar_Simple = [ Index: branches/5.2.x/core/admin_templates/js/inp_ckconfig.js =================================================================== --- branches/5.2.x/core/admin_templates/js/inp_ckconfig.js +++ branches/5.2.x/core/admin_templates/js/inp_ckconfig.js @@ -24,7 +24,7 @@ CKEDITOR.config.entities = false; -CKEDITOR.config.extraPlugins = 'my_link,my_document,my_maximize,my_inline'; +CKEDITOR.config.extraPlugins = 'my_link,my_document,my_maximize,my_inline,sourcedialog'; //CKEDITOR.plugins.add('MySource'); //CKEDITOR.plugins.add('MyPreview'); @@ -58,7 +58,7 @@ ['Find', 'Replace', 'Scayt'], '/', ['Styles'], ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'], - ['NumberedList', 'BulletedList', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] + ['NumberedList', 'BulletedList', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'Sourcedialog'] ]; /*CKEDITOR.config.toolbar_Simple = [ Index: branches/5.2.x/core/ckeditor/plugins/sourcedialog/dialogs/sourcedialog.js =================================================================== --- branches/5.2.x/core/ckeditor/plugins/sourcedialog/dialogs/sourcedialog.js +++ branches/5.2.x/core/ckeditor/plugins/sourcedialog/dialogs/sourcedialog.js @@ -0,0 +1,79 @@ +/** + * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or http://ckeditor.com/license + */ + +CKEDITOR.dialog.add( 'sourcedialog', function( editor ) { + var size = CKEDITOR.document.getWindow().getViewPaneSize(); + + // Make it maximum 800px wide, but still fully visible in the viewport. + var width = Math.min( size.width - 70, 800 ); + + // Make it use 2/3 of the viewport height. + var height = size.height / 1.5; + + // Store old editor data to avoid unnecessary setData. + var oldData; + + return { + title: editor.lang.sourcedialog.title, + minWidth: 100, + minHeight: 100, + + onShow: function() { + this.setValueOf( 'main', 'data', oldData = editor.getData() ); + }, + + onOk: ( function() { + function setData( dialog, newData ) { + // [IE8] Focus editor before setting selection to avoid setting data on + // locked selection, because in case of inline editor, it won't be + // unlocked before editable's HTML is altered. (#11585) + editor.focus(); + editor.setData( newData, function() { + dialog.hide(); + + // Ensure correct selection. + var range = editor.createRange(); + range.moveToElementEditStart( editor.editable() ); + range.select(); + } ); + } + + return function() { + // Remove CR from input data for reliable comparison with editor data. + var newData = this.getValueOf( 'main', 'data' ).replace( /\r/g, '' ), + that = this; + + // Avoid unnecessary setData. Also preserve selection + // when user changed his mind and goes back to wysiwyg editing. + if ( newData === oldData ) + return true; + + setTimeout( function() { + setData( that, newData ); + } ); + + // Don't let the dialog close before setData is over, to hide + // from user blinking caused by selection restoring and setting new data. + return false; + }; + } )(), + + contents: [ { + id: 'main', + label: editor.lang.sourcedialog.title, + elements: [ { + type: 'textarea', + id: 'data', + dir: 'ltr', + inputStyle: 'cursor:auto;' + + 'width:' + width + 'px;' + + 'height:' + height + 'px;' + + 'tab-size:4;' + + 'text-align:left;', + 'class': 'cke_source' + } ] + } ] + }; +} ); Index: branches/5.2.x/core/ckeditor/plugins/sourcedialog/lang/en.js =================================================================== --- branches/5.2.x/core/ckeditor/plugins/sourcedialog/lang/en.js +++ branches/5.2.x/core/ckeditor/plugins/sourcedialog/lang/en.js @@ -0,0 +1,9 @@ +/* +Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. +For licensing, see LICENSE.md or http://ckeditor.com/license +*/ + +CKEDITOR.plugins.setLang( 'sourcedialog', 'en', { + toolbar: 'Source', + title: 'Source' +} ); Index: branches/5.2.x/core/ckeditor/plugins/sourcedialog/plugin.js =================================================================== --- branches/5.2.x/core/ckeditor/plugins/sourcedialog/plugin.js +++ branches/5.2.x/core/ckeditor/plugins/sourcedialog/plugin.js @@ -0,0 +1,29 @@ +/** + * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or http://ckeditor.com/license + */ + +CKEDITOR.plugins.add( 'sourcedialog', { + // jscs:disable maximumLineLength + 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,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% + // jscs:enable maximumLineLength + icons: 'sourcedialog,sourcedialog-rtl', // %REMOVE_LINE_CORE% + hidpi: true, // %REMOVE_LINE_CORE% + + init: function( editor ) { + // Register the "source" command, which simply opens the "source" dialog. + editor.addCommand( 'sourcedialog', new CKEDITOR.dialogCommand( 'sourcedialog' ) ); + + // Register the "source" dialog. + CKEDITOR.dialog.add( 'sourcedialog', this.path + 'dialogs/sourcedialog.js' ); + + // If the toolbar is available, create the "Source" button. + if ( editor.ui.addButton ) { + editor.ui.addButton( 'Sourcedialog', { + label: editor.lang.sourcedialog.toolbar, + command: 'sourcedialog', + toolbar: 'mode,10' + } ); + } + } +} ); Index: branches/5.2.x/core/ckeditor/plugins/sourcedialog/samples/sourcedialog.html =================================================================== --- branches/5.2.x/core/ckeditor/plugins/sourcedialog/samples/sourcedialog.html +++ branches/5.2.x/core/ckeditor/plugins/sourcedialog/samples/sourcedialog.html @@ -0,0 +1,121 @@ + + + + + + Editing source code in a dialog — CKEditor Sample + + + + + + + + + +

+ CKEditor Samples » Editing source code in a dialog +

+
+ This sample is not maintained anymore. Check out its brand new version in CKEditor SDK. +
+
+

+ Sourcedialog plugin provides an easy way to edit raw HTML content + of an editor, similarly to what is possible with Sourcearea + plugin for classic (iframe-based) instances but using dialogs. Thanks to that, it's also possible + to manipulate raw content of inline editor instances. +

+

+ This plugin extends the toolbar with a button, + which opens a dialog window with a source code editor. It works with both classic + and inline instances. To enable this + plugin, basically add extraPlugins: 'sourcedialog' to editor's + config: +

+
+// Inline editor.
+CKEDITOR.inline( 'editable', {
+	extraPlugins: 'sourcedialog'
+});
+
+// Classic (iframe-based) editor.
+CKEDITOR.replace( 'textarea_id', {
+	extraPlugins: 'sourcedialog',
+	removePlugins: 'sourcearea'
+});
+
+

+ Note that you may want to include removePlugins: 'sourcearea' + in your config when using Sourcedialog in classic editor instances. + This prevents feature redundancy. +

+

+ Note that editable in the code above is the id + attribute of the <div> element to be converted into an inline instance. +

+

+ Note that textarea_id in the code above is the id attribute of + the <textarea> element to be replaced with CKEditor. +

+
+
+ +
+

This is some sample text. You are using CKEditor.

+
+
+
+
+ + +
+ + + +