Ticket #6735: 6375_3.patch
File 6375_3.patch, 6.8 KB (added by , 13 years ago) |
---|
-
_source/plugins/wysiwygarea/plugin.js
25 25 || element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ]; 26 26 } 27 27 28 function checkReadOnly( selection )29 {30 if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )31 return selection.getSelectedElement().isReadOnly();32 else33 return selection.getCommonAncestor().isReadOnly();34 }35 36 28 function onInsertHtml( evt ) 37 29 { 38 30 if ( this.mode == 'wysiwyg' ) 39 31 { 40 32 this.focus(); 41 33 42 var selection = this.getSelection(); 43 if ( checkReadOnly( selection ) ) 34 // HTML insertion only considers the first range. 35 var selection = this.getSelection(), 36 range = selection.getRanges()[ 0 ]; 37 38 if ( range.checkReadOnly() ) 44 39 return; 45 40 46 41 var data = evt.data; … … 67 62 // (#6005), we need to make some checks and eventually 68 63 // delete the selection first. 69 64 70 varrange = selection.getRanges()[0],65 range = selection.getRanges()[0], 71 66 endContainer = range && range.endContainer; 72 67 73 68 if ( endContainer && … … 116 111 this.focus(); 117 112 118 113 var selection = this.getSelection(); 119 if ( checkReadOnly( selection ) )120 return;121 114 122 115 this.fire( 'saveSnapshot' ); 123 116 … … 137 130 { 138 131 range = ranges[ i ]; 139 132 140 // Remove the original contents. 141 range.deleteContents(); 133 if ( !range.checkReadOnly() ) 134 { 135 // Remove the original contents. 136 range.deleteContents(); 142 137 143 clone = !i && element || element.clone( 1 );138 clone = !i && element || element.clone( 1 ); 144 139 145 // If we're inserting a block at dtd-violated position, split146 // the parent blocks until we reach blockLimit.147 var current, dtd;148 if ( isBlock )149 {150 while ( ( current = range.getCommonAncestor( 0, 1 ) )151 && ( dtd = CKEDITOR.dtd[ current.getName() ] )152 && !( dtd && dtd [ elementName ] ) )153 {154 // Split up inline elements.155 if ( current.getName() in CKEDITOR.dtd.span )156 range.splitElement( current );157 // If we're in an empty block which indicate a new paragraph,158 // simply replace it with the inserting block.(#3664)159 else if ( range.checkStartOfBlock()160 161 {162 range.setStartBefore( current );163 range.collapse( true );164 current.remove();165 }166 else167 range.splitBlock();168 }169 }140 // If we're inserting a block at dtd-violated position, split 141 // the parent blocks until we reach blockLimit. 142 var current, dtd; 143 if ( isBlock ) 144 { 145 while ( ( current = range.getCommonAncestor( 0, 1 ) ) 146 && ( dtd = CKEDITOR.dtd[ current.getName() ] ) 147 && !( dtd && dtd [ elementName ] ) ) 148 { 149 // Split up inline elements. 150 if ( current.getName() in CKEDITOR.dtd.span ) 151 range.splitElement( current ); 152 // If we're in an empty block which indicate a new paragraph, 153 // simply replace it with the inserting block.(#3664) 154 else if ( range.checkStartOfBlock() 155 && range.checkEndOfBlock() ) 156 { 157 range.setStartBefore( current ); 158 range.collapse( true ); 159 current.remove(); 160 } 161 else 162 range.splitBlock(); 163 } 164 } 170 165 171 // Insert the new node. 172 range.insertNode( clone ); 166 // Insert the new node. 167 range.insertNode( clone ); 168 i && ranges.pop(); 173 169 174 // Save the last element reference so we can make the 175 // selection later. 176 if ( !lastElement ) 177 lastElement = clone; 178 } 170 // Save the last element reference so we can make the 171 // selection later. 172 if ( !lastElement ) 173 lastElement = clone; 174 } 175 } 179 176 180 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END ); 177 if ( lastElement ) 178 { 179 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END ); 181 180 182 // If we're inserting a block element immediatelly followed by183 // another block element, the selection must move there. (#3100,#5436)184 if ( isBlock )185 {186 var next = lastElement.getNext( notWhitespaceEval ),187 nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();181 // If we're inserting a block element immediatelly followed by 182 // another block element, the selection must move there. (#3100,#5436) 183 if ( isBlock ) 184 { 185 var next = lastElement.getNext( notWhitespaceEval ), 186 nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName(); 188 187 189 // Check if it's a block element that accepts text. 190 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] ) 191 range.moveToElementEditStart( next ); 192 } 188 // Check if it's a block element that accepts text. 189 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] ) 190 range.moveToElementEditStart( next ); 191 } 192 } 193 193 194 selection.selectRanges( [ range ]);194 selection.selectRanges( ranges ); 195 195 196 196 if ( selIsLocked ) 197 197 this.getSelection().lock(); -
_source/core/dom/range.js
1745 1745 }, 1746 1746 1747 1747 /** 1748 * Check if elements at which the range boundaries anchor are read-only, 1749 * with respect to "contenteditable" attribute. 1750 */ 1751 checkReadOnly : ( function() 1752 { 1753 function checkPathEditable( node, anotherEnd ) 1754 { 1755 while( node ) 1756 { 1757 if ( node.type == CKEDITOR.NODE_ELEMENT ) 1758 { 1759 if ( node.getAttribute( 'contentEditable' ) == 'false' 1760 && !node.getCustomData( '_cke_notReadOnly' ) ) 1761 return 0; 1762 else if ( node.is( 'body' ) 1763 || node.getAttribute( 'contentEditable' ) == 'true' 1764 && ( node.contains( anotherEnd ) || node.equals( anotherEnd ) ) ) 1765 { 1766 break; 1767 } 1768 } 1769 node = node.getParent(); 1770 } 1771 1772 return 1; 1773 } 1774 1775 return function() 1776 { 1777 var startNode = this.startContainer, 1778 endNode = this.endContainer; 1779 1780 // Check if elements path at both boundaries are editable. 1781 return !( checkPathEditable( startNode, endNode ) && checkPathEditable( endNode, startNode ) ) 1782 }; 1783 })(), 1784 1785 /** 1748 1786 * Moves the range boundaries to the first/end editing point inside an 1749 1787 * element. For example, in an element tree like 1750 1788 * "<p><b><i></i></b> Text</p>", the start editing point is