Ticket #2767: 2767_2.patch
File 2767_2.patch, 7.3 KB (added by , 15 years ago) |
---|
-
_source/core/dom/text.js
97 97 return this.$.nodeValue.substr( indexA ); 98 98 else 99 99 return this.$.nodeValue.substring( indexA, indexB ); 100 }, 101 /** 102 * Whether this text node contain nothing but spaces. 103 * @return {Boolean} 104 */ 105 isEmpty : function ( ) 106 { 107 return CKEDITOR.tools.trim( this.getText() ).length === 0 100 108 } 101 109 }); -
_source/plugins/elementspath/plugin.js
53 53 editor.on( 'selectionChange', function( ev ) 54 54 { 55 55 var env = CKEDITOR.env; 56 57 var selection = ev.data.selection; 58 59 var element = selection.getStartElement(), 56 57 //The root node of this selection 58 var root = ev.data.selection.getSelectionRootNode(), 60 59 html = [], 61 60 elementsList = this._.elementsPath.list = []; 62 61 63 while ( element )62 while ( root ) 64 63 { 65 var index = elementsList.push( element ) - 1;64 var index = elementsList.push( root ) - 1; 66 65 var name; 67 if ( element.getAttribute( '_cke_real_element_type' ) )68 name = element.getAttribute( '_cke_real_element_type' );66 if ( root.getAttribute( '_cke_real_element_type' ) ) 67 name = root.getAttribute( '_cke_real_element_type' ); 69 68 else 70 name = element.getName();69 name = root.getName(); 71 70 72 71 // Use this variable to add conditional stuff to the 73 72 // HTML (because we are doing it in reverse order... unshift). … … 99 98 if ( name == 'body' ) 100 99 break; 101 100 102 element = element.getParent();101 root = root.getParent(); 103 102 } 104 103 105 104 getSpaceElement().setHtml( html.join('') ); -
_source/plugins/styles/plugin.js
49 49 50 50 // Check the current state for the style defined for that 51 51 // callback. 52 var currentState = callback.style.check Active( ev.data.path) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;52 var currentState = callback.style.checkSelectionStyled( ev.data.selection ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF; 53 53 54 54 // If the state changed since the last check. 55 55 if ( callback.state !== currentState ) … … 152 152 } 153 153 return false; 154 154 }, 155 156 /** 157 * Check whether all the ranges within the specified selection is 158 * stained with the current style. 159 * 160 * @param {CKEDITOR.dom.selection} 161 * selection 162 * @return {Boolean} 163 */ 164 checkSelectionStyled : function ( selection ) 165 { 166 var i , ranges = selection.getRanges() , l = ranges.length , isStyled = true; 167 // In search for a non-styled range 168 for ( i = 0 ; i < l ; i++ ) 169 { 170 if ( !this.checkRangeStyled( ranges[ i ] ) ) 171 { 172 isStyled = false; 173 break; 174 } 175 } 176 // Select a collapsed range cause IE move selection to the end of 177 // text nodes. 178 if ( !CKEDITOR.env.ie ) 179 selection.selectRanges( ranges ); 180 return isStyled; 181 }, 182 183 /** 184 * Check whether all the text content of the specified range is stained 185 * with the current style. 186 * 187 * @param {CKEDITOR.dom.range} 188 * range 189 * @return {Boolean} 190 */ 191 checkRangeStyled : function ( range ) 192 { 193 194 if ( range.collapsed ) 195 return this.checkActive( new CKEDITOR.dom.elementPath( 196 range.startContainer ) ); 197 198 var bookmark = range.createBookmark() , startNode = bookmark.startNode , endNode = bookmark.endNode; 199 200 // Start from first node within range 201 var walker = new CKEDITOR.dom.domWalker( startNode.getNextSourceNode() ) , isStyled = true , self = this; 202 203 // DFS forward in searching for text nodes within the range. 204 walker.forward( function ( walkerEvt ) 205 { 206 var currentNode = walkerEvt.data.from; 207 if ( currentNode.equals( startNode ) ) 208 return; 209 else if ( currentNode.equals( endNode ) ) 210 // Stop after the end node. 211 this.stop(); 212 else if ( currentNode.type === CKEDITOR.NODE_TEXT 213 && !currentNode.isEmpty() 214 && !self.checkActive( new CKEDITOR.dom.elementPath( 215 currentNode ) ) ) 216 // stop when we found the first non-styled non-empty text 217 // node 218 { 219 isStyled = false; 220 this.stop(); 221 } 222 } ); 223 224 range.moveToBookmark( bookmark ); 225 return isStyled; 226 }, 155 227 156 228 // Checks if an element, or any of its attributes, is removable by the 157 229 // current style definition. -
_source/plugins/selection/plugin.js
21 21 var firstElement = sel.getStartElement(); 22 22 var currentPath = new CKEDITOR.dom.elementPath( firstElement ); 23 23 24 if ( !currentPath.compare( this._.selectionPreviousPath ) ) 25 { 26 this._.selectionPreviousPath = currentPath; 27 this.fire( 'selectionChange', { selection : sel, path : currentPath, element : firstElement } ); 28 } 24 this._.selectionPreviousPath = currentPath; 25 this.fire( 'selectionChange', { selection : sel, path : currentPath, element : firstElement } ); 29 26 }; 30 27 31 28 var checkSelectionChangeTimer; … … 198 195 { 199 196 var styleObjectElements = { img:1,hr:1,li:1,table:1,tr:1,td:1,embed:1,object:1,ol:1,ul:1 }; 200 197 198 199 /** 200 * Find the deep-most common ancestor of a set of dom nodes. 201 * Note: This method will report 'body' node as result if nothing satisfied. 202 * @param {Array<CKEDITOR.dom.node>} nodes a set of dom nodes 203 * @return {CKEDITOR.dom.node} The DCA result 204 */ 205 function getNodesDeepMostAncestor( nodes ) 206 { 207 var range , currentDCA; 208 209 while ( nodes.length > 1 ) 210 { 211 range = new CKEDITOR.dom.range(); 212 range.startContainer = nodes[ 0 ]; 213 range.endContainer = nodes[ 1 ]; 214 currentDCA = range.getCommonAncestor( false ); 215 if ( currentDCA.getName() === 'body' ) 216 return currentDCA; 217 else 218 nodes.splice( 0 , 2 , [ currentDCA ] ); 219 } 220 return nodes[ 0 ]; 221 } 222 201 223 CKEDITOR.dom.selection.prototype = 202 224 { 203 225 /** … … 635 657 } 636 658 this.selectRanges( ranges ); 637 659 return this; 660 }, 661 662 /** 663 * Get the root node of this selection, it represent the topmost node which 664 * contain the whole range. 665 * 666 * @return {CKEDITOR.dom.node} The root node of this selection 667 */ 668 getSelectionRootNode : function ( ) 669 { 670 var ranges , ancestors = [] , dca; 671 ranges = this.getRanges(); 672 673 if ( ranges.length == 1 && ranges[ 0 ].collapsed ) 674 return this.getStartElement(); 675 676 var i , l = ranges.length; 677 for ( i = 0 ; i < l ; i++ ) 678 { 679 ancestors.push( ranges[ i ].getCommonAncestor() ); 680 } 681 return ( dca = getNodesDeepMostAncestor( ancestors ) ).type === CKEDITOR.NODE_TEXT ? dca 682 .getParent() 683 : dca; 638 684 } 639 685 }; 640 686 })();