Ticket #2804: 2804.patch

File 2804.patch, 5.5 KB (added by Frederico Caldeira Knabben, 15 years ago)
  • _source/core/editor.js

     
    424424                 */
    425425                insertHtml : function( data )
    426426                {
    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 );
    431428                },
    432429
    433430                /**
    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.
    436435                 * @example
    437                  * var element = CKEDITOR.dom.element.createFromHtml( '<img src="hello.png" border="0" title="Hello" />' );
     436                 * var element = CKEDITOR.dom.element.createFromHtml( '&lt;img src="hello.png" border="0" title="Hello" /&gt;' );
    438437                 * CKEDITOR.instances.editor1.<b>insertElement( element )</b>;
    439438                 */
    440439                insertElement : function( element )
    441440                {
    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 );
    446442                },
    447443
    448444                /**
  • _source/plugins/editingblock/plugin.js

     
    1919        // the following data handling functions.
    2020        var isHandlingData;
    2121
    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 
    2422        CKEDITOR.plugins.add( 'editingblock',
    2523        {
    2624                init : function( editor, pluginPath )
     
    5755                                        }
    5856                                });
    5957
    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                                                 else
    67                                                         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 
    10958                        editor.on( 'beforeGetData', function()
    11059                                {
    11160                                        if ( !isHandlingData && editor.mode )
  • _source/plugins/wysiwygarea/plugin.js

     
    6666                };
    6767        // #### protectAttributes - END
    6868
     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
    69121        CKEDITOR.plugins.add( 'wysiwygarea',
    70122        {
    71123                requires : [ 'editingblock', 'fakeobjects' ],
     
    314366                                                                        editor.window.focus();
    315367                                                        }
    316368                                                });
     369
     370                                        editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
     371                                        editor.on( 'insertElement', onInsertElement, null, null, 20 );
    317372                                });
    318373                }
    319374        });
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy