| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 /* 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 /** 7 * @file Paste as plain text plugin 8 */ 9 10 (function() 11 { 12 // The pastetext command definition. 13 var pasteTextCmd = 14 { 15 exec : function( editor ) 16 { 17 var clipboardText = CKEDITOR.tools.tryThese( 18 function() 19 { 20 var clipboardText = window.clipboardData.getData( 'Text' ); 21 if ( !clipboardText ) 22 throw 0; 23 return clipboardText; 24 } 25 // Any other approach that's working... 26 ); 27 28 if ( !clipboardText ) // Clipboard access privilege is not granted. 29 { 30 editor.openDialog( 'pastetext' ); 31 return false; 32 } 33 else 34 editor.fire( 'paste', { 'text' : clipboardText } ); 35 36 return true; 37 } 38 }; 39 40 function doInsertText( doc, text ) 41 { 42 // Native text insertion. 43 if ( CKEDITOR.env.ie ) 44 { 45 var selection = doc.selection; 46 if ( selection.type == 'Control' ) 47 selection.clear(); 48 selection.createRange().pasteHTML( text ); 49 } 50 else 51 doc.execCommand( 'inserthtml', false, text ); 52 } 53 54 // Register the plugin. 55 CKEDITOR.plugins.add( 'pastetext', 56 { 57 init : function( editor ) 58 { 59 var commandName = 'pastetext', 60 command = editor.addCommand( commandName, pasteTextCmd ); 61 62 editor.ui.addButton( 'PasteText', 63 { 64 label : editor.lang.pasteText.button, 65 command : commandName 66 }); 67 68 CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/pastetext.js' ) ); 69 70 if ( editor.config.forcePasteAsPlainText ) 71 { 72 // Intercept the default pasting process. 73 editor.on( 'beforeCommandExec', function ( evt ) 74 { 75 if ( evt.data.name == 'paste' ) 76 { 77 editor.execCommand( 'pastetext' ); 78 evt.cancel(); 79 } 80 }, null, null, 0 ); 81 } 82 }, 83 84 requires : [ 'clipboard' ] 85 }); 86 87 function doEnter( editor, mode, times, forceMode ) 88 { 89 while ( times-- ) 90 { 91 CKEDITOR.plugins.enterkey[ mode == CKEDITOR.ENTER_BR ? 'enterBr' : 'enterBlock' ] 92 ( editor, mode, null, forceMode ); 93 } 94 } 95 96 CKEDITOR.editor.prototype.insertText = function( text ) 97 { 98 this.focus(); 99 this.fire( 'saveSnapshot' ); 100 101 var mode = this.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : this.config.enterMode, 102 isEnterBrMode = mode == CKEDITOR.ENTER_BR, 103 doc = this.document.$, 104 self = this, 105 line; 106 107 text = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) ); 108 109 var startIndex = 0; 110 text.replace( /\n+/g, function( match, lastIndex ) 111 { 112 line = text.substring( startIndex, lastIndex ); 113 startIndex = lastIndex + match.length; 114 line.length && doInsertText( doc, line ); 115 116 var lineBreakNums = match.length, 117 // Duo consequence line-break as a enter block. 118 enterBlockTimes = isEnterBrMode ? 0 : Math.floor( lineBreakNums / 2 ), 119 // Per link-break as a enter br. 120 enterBrTimes = isEnterBrMode ? lineBreakNums : lineBreakNums % 2; 121 122 // Line-breaks are converted to editor enter key strokes. 123 doEnter( self, mode, enterBlockTimes ); 124 doEnter( self, CKEDITOR.ENTER_BR, enterBrTimes, isEnterBrMode ? false : true ); 125 }); 126 127 // Insert the last text line of text. 128 line = text.substring( startIndex, text.length ); 129 line.length && doInsertText( doc, line ); 130 131 this.fire( 'saveSnapshot' ); 132 }; 133 })(); 134 135 136 /** 137 * Whether to force all pasting operations to insert on plain text into the 138 * editor, loosing any formatting information possibly available in the source 139 * text. 140 * @name CKEDITOR.config.forcePasteAsPlainText 141 * @type Boolean 142 * @default false 143 * @example 144 * config.forcePasteAsPlainText = true; 145 */
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |