mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-29 02:07:36 +00:00
HTML composition, take 2
Monotone-Parent: dbd490c81ea6cac4c12b2e17661e2fef43219e68 Monotone-Revision: 0801dc9f1e4fdc49ea44fc0450fb025c2639ed26 Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-06-25T19:18:02 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.html or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
(function()
|
||||
{
|
||||
CKEDITOR.dialog.add( 'pastetext', function( editor )
|
||||
{
|
||||
return {
|
||||
title : editor.lang.pasteText.title,
|
||||
|
||||
minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 368 : 350,
|
||||
minHeight : 240,
|
||||
|
||||
onShow : function()
|
||||
{
|
||||
// Reset the textarea value.
|
||||
this.getContentElement( 'general', 'content' ).getInputElement().setValue( '' );
|
||||
},
|
||||
|
||||
onOk : function()
|
||||
{
|
||||
// Get the textarea value.
|
||||
var text = this.getContentElement( 'general', 'content' ).getInputElement().getValue();
|
||||
|
||||
// Inserts the text.
|
||||
this.getParentEditor().insertText( text );
|
||||
},
|
||||
|
||||
contents :
|
||||
[
|
||||
{
|
||||
label : editor.lang.common.generalTab,
|
||||
id : 'general',
|
||||
elements :
|
||||
[
|
||||
{
|
||||
type : 'html',
|
||||
id : 'pasteMsg',
|
||||
html : '<div style="white-space:normal;width:340px;">' + editor.lang.clipboard.pasteMsg + '</div>'
|
||||
},
|
||||
{
|
||||
type : 'html',
|
||||
id : 'content',
|
||||
style : 'width:340px;height:170px',
|
||||
html :
|
||||
'<textarea style="' +
|
||||
'width:346px;' +
|
||||
'height:170px;' +
|
||||
'resize: none;' +
|
||||
'border:1px solid black;' +
|
||||
'background-color:white">' +
|
||||
'</textarea>',
|
||||
focus : function()
|
||||
{
|
||||
this.getElement().focus();
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.html or http://ckeditor.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file Paste as plain text plugin
|
||||
*/
|
||||
|
||||
(function()
|
||||
{
|
||||
// The pastetext command definition.
|
||||
var pasteTextCmd =
|
||||
{
|
||||
exec : function( editor )
|
||||
{
|
||||
// We use getClipboardData just to test if the clipboard access has
|
||||
// been granted by the user.
|
||||
if ( CKEDITOR.getClipboardData() === false || !window.clipboardData )
|
||||
{
|
||||
editor.openDialog( 'pastetext' );
|
||||
return;
|
||||
}
|
||||
|
||||
editor.insertText( window.clipboardData.getData( 'Text' ) );
|
||||
}
|
||||
};
|
||||
|
||||
// Register the plugin.
|
||||
CKEDITOR.plugins.add( 'pastetext',
|
||||
{
|
||||
init : function( editor )
|
||||
{
|
||||
var commandName = 'pastetext',
|
||||
command = editor.addCommand( commandName, pasteTextCmd );
|
||||
|
||||
editor.ui.addButton( 'PasteText',
|
||||
{
|
||||
label : editor.lang.pasteText.button,
|
||||
command : commandName
|
||||
});
|
||||
|
||||
CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/pastetext.js' ) );
|
||||
|
||||
if ( editor.config.forcePasteAsPlainText )
|
||||
{
|
||||
editor.on( 'beforePaste', function( event )
|
||||
{
|
||||
setTimeout( function() { command.exec(); }, 0 );
|
||||
event.cancel();
|
||||
},
|
||||
null, null, 20 );
|
||||
}
|
||||
},
|
||||
requires : [ 'clipboard' ]
|
||||
});
|
||||
|
||||
var clipboardDiv;
|
||||
|
||||
CKEDITOR.getClipboardData = function()
|
||||
{
|
||||
if ( !CKEDITOR.env.ie )
|
||||
return false;
|
||||
|
||||
var doc = CKEDITOR.document,
|
||||
body = doc.getBody();
|
||||
|
||||
if ( !clipboardDiv )
|
||||
{
|
||||
clipboardDiv = doc.createElement( 'div',
|
||||
{
|
||||
attributes :
|
||||
{
|
||||
id: 'cke_hiddenDiv'
|
||||
},
|
||||
styles :
|
||||
{
|
||||
position : 'absolute',
|
||||
visibility : 'hidden',
|
||||
overflow : 'hidden',
|
||||
width : '1px',
|
||||
height : '1px'
|
||||
}
|
||||
});
|
||||
|
||||
clipboardDiv.setHtml( '' );
|
||||
|
||||
clipboardDiv.appendTo( body );
|
||||
}
|
||||
|
||||
// The "enabled" flag is used to check whether the paste operation has
|
||||
// been completed (the onpaste event has been fired).
|
||||
var enabled = false;
|
||||
var setEnabled = function()
|
||||
{
|
||||
enabled = true;
|
||||
};
|
||||
|
||||
body.on( 'paste', setEnabled );
|
||||
|
||||
// Create a text range and move it inside the div.
|
||||
var textRange = body.$.createTextRange();
|
||||
textRange.moveToElementText( clipboardDiv.$ );
|
||||
|
||||
// The execCommand in will fire the "onpaste", only if the
|
||||
// security settings are enabled.
|
||||
textRange.execCommand( 'Paste' );
|
||||
|
||||
// Get the DIV html and reset it.
|
||||
var html = clipboardDiv.getHtml();
|
||||
clipboardDiv.setHtml( '' );
|
||||
|
||||
body.removeListener( 'paste', setEnabled );
|
||||
|
||||
// Return the HTML or false if not enabled.
|
||||
return enabled && html;
|
||||
};
|
||||
})();
|
||||
|
||||
CKEDITOR.editor.prototype.insertText = function( text )
|
||||
{
|
||||
text = CKEDITOR.tools.htmlEncode( text );
|
||||
|
||||
// TODO: Replace the following with fill line break processing (see V2).
|
||||
text = text.replace( /(?:\r\n)|\n|\r/g, '<br>' );
|
||||
|
||||
this.insertHtml( text );
|
||||
};
|
||||
|
||||
CKEDITOR.config.forcePasteAsPlainText = false;
|
||||
Reference in New Issue
Block a user