123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- /**
- * @license Licensed under the terms of any of the following licenses at your choice:
- *
- * - GNU General Public License Version 2 or later (the "GPL")
- * http://www.gnu.org/licenses/gpl.html
- * (See Appendix A)
- *
- * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
- * http://www.gnu.org/licenses/lgpl.html
- * (See Appendix B)
- *
- * - Mozilla Public License Version 1.1 or later (the "MPL")
- * http://www.mozilla.org/MPL/MPL-1.1.html
- * (See Appendix C)
- *
- */
- /**
- * @fileOverview Paste as code plugin.
- */
- (function() {
- // The pastecode command definition.
- var pasteCodeCmd = {
- // Snapshots are done manually by editable.insertXXX methods.
- canUndo: false,
- async: true,
- exec: function( editor ) {
- editor.getClipboardData({ title: editor.lang.pastecode.title }, function( data ) {
- // Do not use editor#paste, because it would start from beforePaste event.
- //data && editor.fire( 'paste', { type: 'html', dataValue: data.dataValue } );
- editor.insertHtml( data.dataValue );
- editor.fire( 'afterCommandExec', {
- name: 'pastecode',
- command: pasteCodeCmd,
- returnValue: !!data
- });
- });
- }
- };
- // Register the plugin.
- CKEDITOR.plugins.add( 'pastecode', {
- requires: 'clipboard',
- lang: 'fr,en', // %REMOVE_LINE_CORE%
- icons: 'pastecode,pastecode-rtl', // %REMOVE_LINE_CORE%
- init: function( editor ) {
- var commandName = 'pastecode';
- editor.addCommand( commandName, new CKEDITOR.dialogCommand( 'pastecode', {
- //allowedContent : required,
- //requiredContent : required
- } ) );
- editor.ui.addButton && editor.ui.addButton( 'PasteCode', {
- label: editor.lang.pastecode.button,
- command: commandName,
- toolbar: 'clipboard,40'
- });
- CKEDITOR.dialog.add( 'pastecode', function( editor )
- {
- return {
- title : editor.lang.pastecode.title,
- minWidth : 350,
- minHeight : 200,
- contents : [
- {
- id : 'general',
- label : editor.lang.pastecode.code,
- elements : [
- {
- type : 'textarea',
- id : 'contents',
- label : editor.lang.pastecode.code,
- //cols: 140,
- rows: 10,
- validate : CKEDITOR.dialog.validate.notEmpty( editor.lang.pastecode.notEmpty ),
- required : true,
- commit : function()
- {
- //element.setHtml( this.getValue() );
- editor.insertHtml( this.getValue() );
- }
- }
- ]
- }
- ],
- onOk : function()
- {
- /*
- if ( this.insertMode )
- editor.insertElement( this.pre );
- this.commitContent( this.pre );
- */
- this.commitContent();
- }
- };
- } );
- editor.on( 'paste', function( evt ) {
- // Do NOT overwrite if HTML format is explicitly requested.
- // This allows pastefromword dominates over pastecode.
- /*
- if ( evt.data.type != 'html' )
- evt.data.type = 'text';
- */
- });
- editor.on( 'pasteState', function( evt ) {
- editor.getCommand( commandName ).setState( evt.data );
- });
- }
- });
- })();
|