Ticket #6735: 6735_4.patch
File 6735_4.patch, 8.4 KB (added by , 14 years ago) |
---|
-
_source/plugins/clipboard/plugin.js
406 406 // For improved performance, we're checking the readOnly state on selectionChange instead of hooking a key event for that. 407 407 editor.on( 'selectionChange', function( evt ) 408 408 { 409 inReadOnly = evt.data.selection.get CommonAncestor().isReadOnly();409 inReadOnly = evt.data.selection.getRanges()[ 0 ].checkReadOnly(); 410 410 }); 411 411 412 412 // If the "contextmenu" plugin is loaded, register the listeners. … … 414 414 { 415 415 editor.contextMenu.addListener( function( element, selection ) 416 416 { 417 var readOnly = selection.get CommonAncestor().isReadOnly();417 var readOnly = selection.getRanges()[ 0 ].checkReadOnly(); 418 418 return { 419 419 cut : !readOnly && stateFromNamedCommand( 'Cut', editor ), 420 420 copy : stateFromNamedCommand( 'Copy', editor ), -
_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 28 36 37 29 function onInsert( insertFunc ) 38 30 { 39 31 return function( evt ) … … 42 34 { 43 35 this.focus(); 44 36 45 var selection = this.getSelection();46 if ( checkReadOnly( selection ) )47 return;48 49 37 this.fire( 'saveSnapshot' ); 50 38 51 39 insertFunc.call( this, evt.data ); … … 67 55 if ( this.dataProcessor ) 68 56 data = this.dataProcessor.toHtml( data ); 69 57 70 var selection = this.getSelection(); 58 // HTML insertion only considers the first range. 59 var selection = this.getSelection(), 60 range = selection.getRanges()[ 0 ]; 61 62 if ( range.checkReadOnly() ) 63 return; 64 71 65 if ( CKEDITOR.env.ie ) 72 66 { 73 67 var selIsLocked = selection.isLocked; … … 86 80 // (#6005), we need to make some checks and eventually 87 81 // delete the selection first. 88 82 89 varrange = selection.getRanges()[0],83 range = selection.getRanges()[0], 90 84 endContainer = range && range.endContainer; 91 85 92 86 if ( endContainer && … … 209 203 { 210 204 range = ranges[ i ]; 211 205 212 // Remove the original contents. 213 range.deleteContents(); 206 if ( !range.checkReadOnly() ) 207 { 208 // Remove the original contents. 209 range.deleteContents(); 214 210 215 clone = !i && element || element.clone( 1 );211 clone = !i && element || element.clone( 1 ); 216 212 217 // If we're inserting a block at dtd-violated position, split218 // the parent blocks until we reach blockLimit.219 var current, dtd;220 if ( isBlock )221 {222 while ( ( current = range.getCommonAncestor( 0, 1 ) )223 && ( dtd = CKEDITOR.dtd[ current.getName() ] )224 && !( dtd && dtd [ elementName ] ) )225 {226 // Split up inline elements.227 if ( current.getName() in CKEDITOR.dtd.span )228 range.splitElement( current );229 // If we're in an empty block which indicate a new paragraph,230 // simply replace it with the inserting block.(#3664)231 else if ( range.checkStartOfBlock()232 && range.checkEndOfBlock() )233 {234 range.setStartBefore( current );235 range.collapse( true );236 current.remove();237 }238 else239 range.splitBlock();240 }241 }213 // If we're inserting a block at dtd-violated position, split 214 // the parent blocks until we reach blockLimit. 215 var current, dtd; 216 if ( isBlock ) 217 { 218 while ( ( current = range.getCommonAncestor( 0, 1 ) ) 219 && ( dtd = CKEDITOR.dtd[ current.getName() ] ) 220 && !( dtd && dtd [ elementName ] ) ) 221 { 222 // Split up inline elements. 223 if ( current.getName() in CKEDITOR.dtd.span ) 224 range.splitElement( current ); 225 // If we're in an empty block which indicate a new paragraph, 226 // simply replace it with the inserting block.(#3664) 227 else if ( range.checkStartOfBlock() 228 && range.checkEndOfBlock() ) 229 { 230 range.setStartBefore( current ); 231 range.collapse( true ); 232 current.remove(); 233 } 234 else 235 range.splitBlock(); 236 } 237 } 242 238 243 // Insert the new node.244 range.insertNode( clone );239 // Insert the new node. 240 range.insertNode( clone ); 245 241 246 // Save the last element reference so we can make the 247 // selection later. 248 if ( !lastElement ) 249 lastElement = clone; 250 } 242 // Save the last element reference so we can make the 243 // selection later. 244 if ( !lastElement ) 245 lastElement = clone; 246 } 247 } 251 248 252 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END ); 249 if ( lastElement ) 250 { 251 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END ); 253 252 254 // If we're inserting a block element immediatelly followed by255 // another block element, the selection must move there. (#3100,#5436)256 if ( isBlock )257 {258 var next = lastElement.getNext( notWhitespaceEval ),259 nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();253 // If we're inserting a block element immediatelly followed by 254 // another block element, the selection must move there. (#3100,#5436) 255 if ( isBlock ) 256 { 257 var next = lastElement.getNext( notWhitespaceEval ), 258 nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName(); 260 259 261 // Check if it's a block element that accepts text. 262 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] ) 263 range.moveToElementEditStart( next ); 264 } 260 // Check if it's a block element that accepts text. 261 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] ) 262 range.moveToElementEditStart( next ); 263 } 264 } 265 265 266 selection.selectRanges( [ range ] );266 selection.selectRanges( [ range ] ); 267 267 268 268 if ( selIsLocked ) 269 269 this.getSelection().lock(); -
_source/core/dom/range.js
1755 1755 }, 1756 1756 1757 1757 /** 1758 * Check if elements at which the range boundaries anchor are read-only, 1759 * with respect to "contenteditable" attribute. 1760 */ 1761 checkReadOnly : ( function() 1762 { 1763 function checkNodesEditable( node, anotherEnd ) 1764 { 1765 while( node ) 1766 { 1767 if ( node.type == CKEDITOR.NODE_ELEMENT ) 1768 { 1769 if ( node.getAttribute( 'contentEditable' ) == 'false' 1770 && !node.data( 'cke-editable' ) ) 1771 { 1772 return 0; 1773 } 1774 // Range enclosed entirely in an editable element. 1775 else if ( node.is( 'body' ) 1776 || node.getAttribute( 'contentEditable' ) == 'true' 1777 && ( node.contains( anotherEnd ) || node.equals( anotherEnd ) ) ) 1778 { 1779 break; 1780 } 1781 } 1782 node = node.getParent(); 1783 } 1784 1785 return 1; 1786 } 1787 1788 return function() 1789 { 1790 var startNode = this.startContainer, 1791 endNode = this.endContainer; 1792 1793 // Check if elements path at both boundaries are editable. 1794 return !( checkNodesEditable( startNode, endNode ) && checkNodesEditable( endNode, startNode ) ) 1795 }; 1796 })(), 1797 1798 /** 1758 1799 * Moves the range boundaries to the first/end editing point inside an 1759 1800 * element. For example, in an element tree like 1760 1801 * "<p><b><i></i></b> Text</p>", the start editing point is -
_source/plugins/scayt/plugin.js
626 626 editor.contextMenu.addListener( function( element, selection ) 627 627 { 628 628 if ( !plugin.isScaytEnabled( editor ) 629 || selection.get CommonAncestor().isReadOnly() )629 || selection.getRanges()[ 0 ].checkReadOnly() ) 630 630 return null; 631 631 632 632 var scayt_control = plugin.getScayt( editor ),