Ticket #1384: fckdomrange.patch
File fckdomrange.patch, 4.1 KB (added by , 16 years ago) |
---|
-
fckdomrange.js
160 160 this._Range.insertNode( node ) ; 161 161 }, 162 162 163 CheckIsEmpty : function() 163 // Checks if the range is empty 164 // @bCheckEmptyInline Return true on empty inline tags such as: <u></u> 165 // @iTrimType 0 = full trim, 1 = left trim, 2 = right trim, 3 = no trim 166 CheckIsEmpty : function( bCheckEmptyInline, iTrimType ) 164 167 { 165 168 if ( this.CheckIsCollapsed() ) 166 169 return true ; … … 169 172 var eToolDiv = this.Window.document.createElement( 'div' ) ; 170 173 this._Range.cloneContents().AppendTo( eToolDiv ) ; 171 174 172 FCKDomTools.TrimNode( eToolDiv ) ; 175 if( iTrimType == 1 ) 176 { 177 FCKDomTools.LTrimNode( eToolDiv ) ; 178 } 179 else if( iTrimType == 2 ) 180 { 181 FCKDomTools.RTrimNode( eToolDiv ) ; 182 } 183 else if( iTrimType != 3 ) 184 { 185 FCKDomTools.TrimNode( eToolDiv ) ; 186 } 173 187 188 if( bCheckEmptyInline ) 189 { 190 // Recursive function to determine if all children of a node are inline 191 AreAllChildrenInline = function( pElement ) 192 { 193 for( var i = 0; i < pElement.childNodes.length; i++ ) 194 { 195 var pChild = pElement.childNodes[i] ; 196 197 if( !pChild.nodeName ) 198 { 199 return false ; 200 } 201 202 if( FCKListsLib.InlineChildReqElements[pChild.nodeName.toLowerCase() ] == null ) 203 { 204 return false ; 205 } 206 207 if( !AreAllChildrenInline( pChild ) ) 208 { 209 return false ; 210 } 211 } 212 213 return true ; 214 }; 215 216 return AreAllChildrenInline( eToolDiv ) ; 217 } 218 174 219 return ( eToolDiv.innerHTML.length == 0 ) ; 175 220 }, 176 221 177 CheckStartOfBlock : function( )222 CheckStartOfBlock : function( refreshSelection ) 178 223 { 179 224 var bIsStartOfBlock = this._Cache.IsStartOfBlock ; 180 225 … … 190 235 // Move the start boundary to the start of the block. 191 236 oTestRange.SetStart( oTestRange.StartBlock || oTestRange.StartBlockLimit, 1 ) ; 192 237 193 if ( oTestRange.CheckIsCollapsed() )194 bIsStartOfBlock = true ; 195 else238 bIsStartOfBlock = oTestRange.CheckIsCollapsed() ; 239 240 if ( !bIsStartOfBlock ) 196 241 { 197 // Inserts the contents of the range in a div tag.198 var eToolDiv = oTestRange.Window.document.createElement( 'div' ) ;199 oTestRange._Range.cloneContents().AppendTo( eToolDiv ) ;200 201 // This line is why we don't use CheckIsEmpty() here...202 // Because using RTrimNode() or TrimNode() would be incorrect -203 242 // TrimNode() and RTrimNode() would delete <br> nodes at the end of the div node, 204 243 // but for checking start of block they are actually meaningful. (Bug #1350) 205 FCKDomTools.LTrimNode( eToolDiv ) ; 206 207 bIsStartOfBlock = ( eToolDiv.innerHTML.length == 0 ) ; 244 // The second parameter to CheckIsEmpty forces just an LTrimNode() 245 bIsStartOfBlock = oTestRange.CheckIsEmpty( true, 2 ); 208 246 } 209 247 210 248 oTestRange.Release() ; 249 250 if ( refreshSelection ) 251 this.Select() ; 211 252 212 253 return ( this._Cache.IsStartOfBlock = bIsStartOfBlock ) ; 213 254 }, … … 232 273 233 274 if ( !bIsEndOfBlock ) 234 275 { 235 // Inserts the contents of the range in a div tag. 236 var eToolDiv = this.Window.document.createElement( 'div' ) ; 237 oTestRange._Range.cloneContents().AppendTo( eToolDiv ) ; 238 FCKDomTools.TrimNode( eToolDiv ) ; 239 240 // Find out if we are in an empty tree of inline elements, like <b><i><span></span></i></b> 241 bIsEndOfBlock = true ; 242 var eLastChild = eToolDiv ; 243 while ( ( eLastChild = eLastChild.lastChild ) ) 244 { 245 // Check the following: 246 // 1. Is there more than one node in the parents children? 247 // 2. Is the node not an element node? 248 // 3. Is it not a inline element. 249 if ( eLastChild.previousSibling || eLastChild.nodeType != 1 || FCKListsLib.InlineChildReqElements[ eLastChild.nodeName.toLowerCase() ] == null ) 250 { 251 // So we are not in the end of the range. 252 bIsEndOfBlock = false ; 253 break ; 254 } 255 } 276 bIsEndOfBlock = oTestRange.CheckIsEmpty( true ); 256 277 } 257 278 258 279 oTestRange.Release() ;