| 28 | |
| 29 | function cleanupOnInsertHtmlTest(selection, htmlData){ |
| 30 | |
| 31 | var ranges = selection.getRanges(), |
| 32 | element = CKEDITOR.dom.element.createFromHtml(htmlData), |
| 33 | elementName = element.getName(), |
| 34 | isBlock = CKEDITOR.dtd.$block[ elementName ]; |
| 35 | |
| 36 | var range; |
| 37 | |
| 38 | for ( var i = ranges.length - 1 ; i >= 0 ; i-- ) |
| 39 | { |
| 40 | range = ranges[ i ]; |
| 41 | |
| 42 | // Remove the original contents. |
| 43 | range.deleteContents(); |
| 44 | |
| 45 | // If we're inserting a block at dtd-violated position, split |
| 46 | // the parent blocks until we reach blockLimit. |
| 47 | var current, dtd; |
| 48 | if ( isBlock ) |
| 49 | { |
| 50 | while ( ( current = range.getCommonAncestor( 0, 1 ) ) |
| 51 | && ( dtd = CKEDITOR.dtd[ current.getName() ] ) |
| 52 | && !( dtd && dtd [ elementName ] ) ) |
| 53 | { |
| 54 | // Split up inline elements. |
| 55 | if ( current.getName() in CKEDITOR.dtd.span ) |
| 56 | range.splitElement( current ); |
| 57 | // If we're in an empty block which indicate a new paragraph, |
| 58 | // simply replace it with the inserting block.(#3664) |
| 59 | else if ( range.checkStartOfBlock() |
| 60 | && range.checkEndOfBlock() ) |
| 61 | { |
| 62 | range.setStartBefore( current ); |
| 63 | range.collapse( true ); |
| 64 | current.remove(); |
| 65 | } |
| 66 | else |
| 67 | range.splitBlock(); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | selection.selectRanges( [ range ] ); |
| 73 | |
| 74 | return ; |
| 75 | } |