Ticket #2804: 2804.patch
File 2804.patch, 5.5 KB (added by , 15 years ago) |
---|
-
_source/core/editor.js
424 424 */ 425 425 insertHtml : function( data ) 426 426 { 427 var eventData = { insert : data }; 428 this.fire( 'insertHtml', eventData ); 429 this.fire( 'afterInsertHtml', eventData ); 430 this._.data = this.document.getBody().getHtml(); 427 this.fire( 'insertHtml', data ); 431 428 }, 432 429 433 430 /** 434 * Inserts an element into the currently selected position in the editor. 435 * @param {CKEDITOR.dom.element} element Element to be inserted into the editor. 431 * Inserts an element into the currently selected position in the 432 * editor. 433 * @param {CKEDITOR.dom.element} element The element to be inserted 434 * into the editor. 436 435 * @example 437 * var element = CKEDITOR.dom.element.createFromHtml( ' <img src="hello.png" border="0" title="Hello" />' );436 * var element = CKEDITOR.dom.element.createFromHtml( '<img src="hello.png" border="0" title="Hello" />' ); 438 437 * CKEDITOR.instances.editor1.<b>insertElement( element )</b>; 439 438 */ 440 439 insertElement : function( element ) 441 440 { 442 var eventData = { insert : element }; 443 this.fire( 'insertElement', eventData ); 444 this.fire( 'afterInsertElement', eventData ); 445 this._.data = this.document.getBody().getHtml(); 441 this.fire( 'insertElement', element ); 446 442 }, 447 443 448 444 /** -
_source/plugins/editingblock/plugin.js
19 19 // the following data handling functions. 20 20 var isHandlingData; 21 21 22 var blockElements = { address:1,blockquote:1,center:1,div:1,dl:1,fieldset:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,marquee:1,noscript:1,ol:1,p:1,pre:1,script:1,table:1,ul:1 };23 24 22 CKEDITOR.plugins.add( 'editingblock', 25 23 { 26 24 init : function( editor, pluginPath ) … … 57 55 } 58 56 }); 59 57 60 editor.on( 'afterInsertHtml', function( evt )61 {62 if ( editor.mode )63 {64 if ( CKEDITOR.env.ie )65 editor.document.$.selection.createRange().pasteHtml( evt.data.insert );66 else67 editor.document.$.execCommand( 'inserthtml', false, evt.data.insert );68 }69 });70 71 editor.on( 'afterInsertElement', function( evt )72 {73 if ( editor.mode )74 {75 var selection = new CKEDITOR.dom.selection( editor.document ),76 ranges = selection.getRanges(),77 clone, lastRange, bookmark,78 isBlock = blockElements[ evt.data.insert.getName() ];79 80 for ( var i = ranges.length - 1 ; i >= 0 ; i-- )81 {82 // Remove the original contents.83 ranges[i].deleteContents();84 85 clone = evt.data.insert.clone( true );86 87 // If the new node is a block element, split the current block.88 if ( editor.config.enterMode != 'br' && isBlock )89 ranges[i].splitBlock();90 91 // Insert the new node.92 ranges[i].insertNode( clone );93 94 // Move the caret after the last insertion point.95 if ( !lastRange )96 {97 lastRange = ranges[i];98 lastRange.setStartAfter( clone );99 lastRange.collapse( true );100 bookmark = lastRange.createBookmark();101 }102 }103 104 lastRange.moveToBookmark( bookmark );105 selection.selectRanges( [lastRange] );106 }107 } );108 109 58 editor.on( 'beforeGetData', function() 110 59 { 111 60 if ( !isHandlingData && editor.mode ) -
_source/plugins/wysiwygarea/plugin.js
66 66 }; 67 67 // #### protectAttributes - END 68 68 69 var onInsertHtml = function( evt ) 70 { 71 if ( this.mode == 'wysiwyg' ) 72 { 73 var $doc = this.document.$; 74 75 if ( CKEDITOR.env.ie ) 76 doc.selection.createRange().pasteHtml( evt.data ); 77 else 78 doc.execCommand( 'inserthtml', false, evt.data ); 79 } 80 }; 81 82 var onInsertElement = function( evt ) 83 { 84 if ( this.mode == 'wysiwyg' ) 85 { 86 var element = evt.data; 87 isBlock = CKEDITOR.dtd.$block[ element.getName() ]; 88 89 var selection = this.getSelection(), 90 ranges = selection.getRanges(); 91 92 var range, clone, lastElement, bookmark; 93 94 for ( var i = ranges.length - 1 ; i >= 0 ; i-- ) 95 { 96 range = ranges[ i ]; 97 98 // Remove the original contents. 99 range.deleteContents(); 100 101 clone = element.clone( true ); 102 103 // If the new node is a block element, split the current block. 104 if ( this.config.enterMode != 'br' && isBlock ) 105 range.splitBlock(); 106 107 // Insert the new node. 108 range.insertNode( clone ); 109 110 // Save the last element reference so we can make the 111 // selection later. 112 if ( !lastElement ) 113 lastElement = clone; 114 } 115 116 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END ); 117 selection.selectRanges( [ range ] ); 118 } 119 }; 120 69 121 CKEDITOR.plugins.add( 'wysiwygarea', 70 122 { 71 123 requires : [ 'editingblock', 'fakeobjects' ], … … 314 366 editor.window.focus(); 315 367 } 316 368 }); 369 370 editor.on( 'insertHtml', onInsertHtml, null, null, 20 ); 371 editor.on( 'insertElement', onInsertElement, null, null, 20 ); 317 372 }); 318 373 } 319 374 });