X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fpastetext%2Fplugin.js;h=42dbf5dd9c19433906fcfba1200d0f9e813399cd;hb=1056598c95187351dc58f4991d331e2258d038b5;hp=0d9cd9d92e7f02134851d9f1d7ff8ba570a023a0;hpb=c6e377a02b54abc07129d72b632763c727476a15;p=ckeditor.git diff --git a/_source/plugins/pastetext/plugin.js b/_source/plugins/pastetext/plugin.js index 0d9cd9d..42dbf5d 100644 --- a/_source/plugins/pastetext/plugin.js +++ b/_source/plugins/pastetext/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -21,23 +21,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !clipboardText ) throw 0; return clipboardText; - }, - function() - { - window.netscape.security.PrivilegeManager.enablePrivilege( "UniversalXPConnect" ); - - var clip = window.Components.classes[ "@mozilla.org/widget/clipboard;1" ] - .getService( window.Components.interfaces.nsIClipboard ); - var trans = window.Components.classes[ "@mozilla.org/widget/transferable;1" ] - .createInstance( window.Components.interfaces.nsITransferable ); - trans.addDataFlavor( "text/unicode" ); - clip.getData( trans, clip.kGlobalClipboard ); - - var str = {}, strLength = {}, clipboardText; - trans.getTransferData( "text/unicode", str, strLength ); - str = str.value.QueryInterface( window.Components.interfaces.nsISupportsString ); - clipboardText = str.data.substring( 0, strLength.value / 2 ); - return clipboardText; } // Any other approach that's working... ); @@ -54,20 +37,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } }; - function doInsertText( doc, text ) - { - // Native text insertion. - if ( CKEDITOR.env.ie ) - { - var selection = doc.selection; - if ( selection.type == 'Control' ) - selection.clear(); - selection.createRange().pasteHTML( text ); - } - else - doc.execCommand( 'inserthtml', false, text ); - } - // Register the plugin. CKEDITOR.plugins.add( 'pastetext', { @@ -89,64 +58,30 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Intercept the default pasting process. editor.on( 'beforeCommandExec', function ( evt ) { - if ( evt.data.name == 'paste' ) + var mode = evt.data.commandData; + // Do NOT overwrite if HTML format is explicitly requested. + if ( evt.data.name == 'paste' && mode != 'html' ) { editor.execCommand( 'pastetext' ); evt.cancel(); } }, null, null, 0 ); + + editor.on( 'beforePaste', function( evt ) + { + evt.data.mode = 'text'; + }); } + + editor.on( 'pasteState', function( evt ) + { + editor.getCommand( 'pastetext' ).setState( evt.data ); + }); }, requires : [ 'clipboard' ] }); - function doEnter( editor, mode, times, forceMode ) - { - while ( times-- ) - { - CKEDITOR.plugins.enterkey[ mode == CKEDITOR.ENTER_BR ? 'enterBr' : 'enterBlock' ] - ( editor, mode, null, forceMode ); - } - } - - CKEDITOR.editor.prototype.insertText = function( text ) - { - this.focus(); - this.fire( 'saveSnapshot' ); - - var mode = this.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : this.config.enterMode, - isEnterBrMode = mode == CKEDITOR.ENTER_BR, - doc = this.document.$, - self = this, - line; - - text = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) ); - - var startIndex = 0; - text.replace( /\n+/g, function( match, lastIndex ) - { - line = text.substring( startIndex, lastIndex ); - startIndex = lastIndex + match.length; - line.length && doInsertText( doc, line ); - - var lineBreakNums = match.length, - // Duo consequence line-break as a enter block. - enterBlockTimes = isEnterBrMode ? 0 : Math.floor( lineBreakNums / 2 ), - // Per link-break as a enter br. - enterBrTimes = isEnterBrMode ? lineBreakNums : lineBreakNums % 2; - - // Line-breaks are converted to editor enter key strokes. - doEnter( self, mode, enterBlockTimes ); - doEnter( self, CKEDITOR.ENTER_BR, enterBrTimes, isEnterBrMode ? false : true ); - }); - - // Insert the last text line of text. - line = text.substring( startIndex, text.length ); - line.length && doInsertText( doc, line ); - - this.fire( 'saveSnapshot' ); - }; })(); @@ -154,6 +89,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * Whether to force all pasting operations to insert on plain text into the * editor, loosing any formatting information possibly available in the source * text. + * Note: paste from word is not affected by this configuration. * @name CKEDITOR.config.forcePasteAsPlainText * @type Boolean * @default false