- Timestamp:
- 05/23/05 15:12:55 (15 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/EnterParagraphs/enter-paragraphs.js
r189 r190 15 15 */ 16 16 17 EnterParagraphs._pluginInfo = 17 EnterParagraphs._pluginInfo = 18 18 { 19 19 name : "EnterParagraphs", … … 85 85 */ 86 86 87 function EnterParagraphs(editor) 87 function EnterParagraphs(editor) 88 88 { 89 89 … … 91 91 92 92 // [STRIP 93 // create a ddt debug trace object. There may be multiple editors on 93 // create a ddt debug trace object. There may be multiple editors on 94 94 // the page each EnterParagraphs .. to distinguish which instance 95 95 // is generating the message we tack on the name of the textarea. 96 96 97 this.ddt = new DDT( editor._textArea + ":EnterParagraphs Plugin" );97 //this.ddt = new DDT( editor._textArea + ":EnterParagraphs Plugin" ); 98 98 99 99 // uncomment to turn on debugging messages. 100 101 this.ddt._ddtOn();102 103 this.ddt._ddt( "enter-paragraphs.js","23", "EnterParagraphs(): constructor" );100 101 //this.ddt._ddtOn(); 102 103 //this.ddt._ddt( "enter-paragraphs.js","23", "EnterParagraphs(): constructor" ); 104 104 105 105 // STRIP] … … 110 110 if (HTMLArea.is_gecko) 111 111 { 112 this.ddt._ddt( "enter-paragraphs.js","23", "EnterParagraphs(): we are gecko. Setting event handler." );112 //this.ddt._ddt( "enter-paragraphs.js","23", "EnterParagraphs(): we are gecko. Setting event handler." ); 113 113 this.onKeyPress = this.__onKeyPress; 114 114 } … … 131 131 */ 132 132 133 EnterParagraphs.prototype.insertAdjacentElement = function(ref,pos,el) 134 { 135 136 this.ddt._ddtDumpNode( "enter-paragraphs.js", "122", "insertAdjacentElement(): top with pos '" + pos + "' ref:", ref );137 this.ddt._ddtDumpNode( "enter-paragraphs.js", "122", "insertAdjacentElement(): top with el:", el );138 139 if ( pos == 'BeforeBegin' ) 133 EnterParagraphs.prototype.insertAdjacentElement = function(ref,pos,el) 134 { 135 136 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "122", "insertAdjacentElement(): top with pos '" + pos + "' ref:", ref ); 137 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "122", "insertAdjacentElement(): top with el:", el ); 138 139 if ( pos == 'BeforeBegin' ) 140 140 { 141 141 ref.parentNode.insertBefore(el,ref); 142 142 } 143 else if ( pos == 'AfterEnd' ) 143 else if ( pos == 'AfterEnd' ) 144 144 { 145 145 ref.nextSibling ? ref.parentNode.insertBefore(el,ref.nextSibling) : ref.parentNode.appendChild(el); 146 146 } 147 else if ( pos == 'AfterBegin' && ref.firstChild ) 147 else if ( pos == 'AfterBegin' && ref.firstChild ) 148 148 { 149 149 ref.insertBefore(el,ref.firstChild); 150 150 } 151 else if ( pos == 'BeforeEnd' || pos == 'AfterBegin' ) 151 else if ( pos == 'BeforeEnd' || pos == 'AfterBegin' ) 152 152 { 153 153 ref.appendChild(el); 154 154 } 155 155 156 this.ddt._ddtDumpNode( "enter-paragraphs.js", "122", "insertAdjacentElement(): bottom with ref:", ref );156 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "122", "insertAdjacentElement(): bottom with ref:", ref ); 157 157 158 158 }; // end of insertAdjacentElement() … … 169 169 */ 170 170 171 EnterParagraphs.prototype.forEachNodeUnder = function ( root, mode, direction, init ) 172 { 173 174 this.ddt._ddtDumpNode( "enter-paragraphs.js", "144", "forEachNodeUnder(): top mode is '" + mode + "' direction is '" + direction + "' starting with root node:", root );171 EnterParagraphs.prototype.forEachNodeUnder = function ( root, mode, direction, init ) 172 { 173 174 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "144", "forEachNodeUnder(): top mode is '" + mode + "' direction is '" + direction + "' starting with root node:", root ); 175 175 176 176 // Identify the first and last nodes to deal with 177 177 178 178 var start, end; 179 179 180 // nodeType 11 is DOCUMENT_FRAGMENT_NODE which is a container. 181 182 if ( root.nodeType == 11 && root.firstChild ) 180 // nodeType 11 is DOCUMENT_FRAGMENT_NODE which is a container. 181 182 if ( root.nodeType == 11 && root.firstChild ) 183 183 { 184 184 start = root.firstChild; 185 185 end = root.lastChild; 186 } 187 else 186 } 187 else 188 188 { 189 189 start = end = root; 190 190 } 191 191 192 this.ddt._ddtDumpNode( "enter-paragraphs.js", "144", "forEachNodeUnder(): start node is:", start );193 this.ddt._ddtDumpNode( "enter-paragraphs.js", "144", "forEachNodeUnder(): initial end node is:", end );192 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "144", "forEachNodeUnder(): start node is:", start ); 193 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "144", "forEachNodeUnder(): initial end node is:", end ); 194 194 195 195 // traverse down the right hand side of the tree getting the last child of the last 196 196 // child in each level until we reach bottom. 197 while ( end.lastChild ) 197 while ( end.lastChild ) 198 198 end = end.lastChild; 199 199 200 this.ddt._ddtDumpNode( "enter-paragraphs.js", "144", "forEachNodeUnder(): end node after descent is:", end );200 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "144", "forEachNodeUnder(): end node after descent is:", end ); 201 201 202 202 return this.forEachNode( start, end, mode, direction, init); … … 216 216 */ 217 217 218 EnterParagraphs.prototype.forEachNode = function (left_node, right_node, mode, direction, init) 219 { 220 221 this.ddt._ddt( "enter-paragraphs.js", "175", "forEachNode(): top - mode is:" + mode + "' direction '" + direction + "'" );222 this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): top - left node is:", left_node );223 this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): top - right node is:", right_node );218 EnterParagraphs.prototype.forEachNode = function (left_node, right_node, mode, direction, init) 219 { 220 221 //this.ddt._ddt( "enter-paragraphs.js", "175", "forEachNode(): top - mode is:" + mode + "' direction '" + direction + "'" ); 222 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): top - left node is:", left_node ); 223 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): top - right node is:", right_node ); 224 224 225 225 // returns "Brother" node either left or right. 226 226 227 var getSibling = function(elem, direction) 228 { 229 return ( direction == "ltr" ? elem.nextSibling : elem.previousSibling ); 227 var getSibling = function(elem, direction) 228 { 229 return ( direction == "ltr" ? elem.nextSibling : elem.previousSibling ); 230 230 }; 231 231 232 var getChild = function(elem, direction) 233 { 234 return ( direction == "ltr" ? elem.firstChild : elem.lastChild ); 232 var getChild = function(elem, direction) 233 { 234 return ( direction == "ltr" ? elem.firstChild : elem.lastChild ); 235 235 }; 236 236 237 237 var walk, lookup, fnReturnVal; 238 238 239 // FIXME: init is a boolean in the emptyset case and an object in 239 // FIXME: init is a boolean in the emptyset case and an object in 240 240 // the cullids case. Used inconsistently. 241 241 242 242 var next_node = init; 243 243 … … 249 249 // if we're going left to right that's the right_node and visa-versa. 250 250 251 while ( walk != direction == "ltr" ? right_node : left_node ) 252 { 253 254 // on first entry, walk here is null. So this is how 251 while ( walk != direction == "ltr" ? right_node : left_node ) 252 { 253 254 // on first entry, walk here is null. So this is how 255 255 // we prime the loop with the first node. 256 256 257 if ( !walk ) 257 if ( !walk ) 258 258 { 259 259 walk = direction == "ltr" ? left_node : right_node; 260 260 261 this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): !walk - current node is:", walk );262 } 263 else 261 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): !walk - current node is:", walk ); 262 } 263 else 264 264 { 265 265 266 266 // is there a child node? 267 267 268 if ( getChild(walk,direction) ) 268 if ( getChild(walk,direction) ) 269 269 { 270 270 … … 273 273 walk = getChild(walk,direction); 274 274 275 this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode():descending to child node:", walk );275 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode():descending to child node:", walk ); 276 276 277 277 } 278 else 278 else 279 279 { 280 280 281 281 // is there a sibling node on this level? 282 282 283 if ( getSibling(walk,direction) ) 283 if ( getSibling(walk,direction) ) 284 284 { 285 285 … … 288 288 walk = getSibling(walk,direction); 289 289 290 this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): moving to sibling node:", walk );290 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): moving to sibling node:", walk ); 291 291 292 292 } 293 else 293 else 294 294 { 295 295 lookup = walk; 296 296 297 // climb back up the tree until we find a level where we are not the end 297 // climb back up the tree until we find a level where we are not the end 298 298 // node on the level (i.e. that we have a sibling in the direction 299 299 // we are searching) or until we reach the end. 300 300 301 while ( !getSibling(lookup,direction) && lookup != (direction == "ltr" ? right_node : left_node) ) 301 while ( !getSibling(lookup,direction) && lookup != (direction == "ltr" ? right_node : left_node) ) 302 302 { 303 303 lookup = lookup.parentNode; 304 304 } 305 305 306 // did we find a level with a sibling? 306 // did we find a level with a sibling? 307 307 308 308 // walk = ( lookup.nextSibling ? lookup.nextSibling : lookup ) ; … … 310 310 walk = ( getSibling(lookup,direction) ? getSibling(lookup,direction) : lookup ) ; 311 311 312 this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): climbed back up (or found right node):", walk );313 314 } 315 } 312 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): climbed back up (or found right node):", walk ); 313 314 } 315 } 316 316 317 317 } // end of else walk. … … 323 323 324 324 // call the requested function on the current node. Functions 325 // return an array. 325 // return an array. 326 326 // 327 327 // Possible functions are _fenCullIds, _fenEmptySet … … 332 332 // next_node can be an object (this.takenIds), a node (text, el, etc) or false. 333 333 334 this.ddt._ddt( "enter-paragraphs.js", "175", "forEachNode(): calling function" );334 //this.ddt._ddt( "enter-paragraphs.js", "175", "forEachNode(): calling function" ); 335 335 336 336 switch( mode ) … … 339 339 case "cullids": 340 340 341 fnReturnVal = this._fenCullIds(walk, next_node ); 341 fnReturnVal = this._fenCullIds(walk, next_node ); 342 342 break; 343 343 344 344 case "find_fill": 345 345 346 fnReturnVal = this._fenEmptySet(walk, next_node, mode, done_flag); 346 fnReturnVal = this._fenEmptySet(walk, next_node, mode, done_flag); 347 347 break; 348 348 349 349 case "find_cursorpoint": 350 350 351 fnReturnVal = this._fenEmptySet(walk, next_node, mode, done_flag); 351 fnReturnVal = this._fenEmptySet(walk, next_node, mode, done_flag); 352 352 break; 353 353 … … 356 356 // If this node wants us to return, return next_node 357 357 358 if ( fnReturnVal[0] ) 359 { 360 this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): returning node:", fnReturnVal[1] );361 362 return fnReturnVal[1]; 363 } 364 365 // are we done with the loop? 358 if ( fnReturnVal[0] ) 359 { 360 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "175", "forEachNode(): returning node:", fnReturnVal[1] ); 361 362 return fnReturnVal[1]; 363 } 364 365 // are we done with the loop? 366 366 367 367 if ( done_flag ) … … 372 372 // Otherwise, pass to the next node 373 373 374 if ( fnReturnVal[1] ) 375 { 376 next_node = fnReturnVal[1]; 374 if ( fnReturnVal[1] ) 375 { 376 next_node = fnReturnVal[1]; 377 377 } 378 378 379 379 } // end of while loop 380 380 381 this.ddt._ddt( "enter-paragraphs.js", "175", "forEachNode(): returning false." );381 //this.ddt._ddt( "enter-paragraphs.js", "175", "forEachNode(): returning false." ); 382 382 383 383 return false; … … 393 393 * @param next_node node next node to be examined. 394 394 * @param node string "find_fill" or "find_cursorpoint" 395 * @param last_flag boolean is this the last node? 396 */ 397 398 EnterParagraphs.prototype._fenEmptySet = function( node, next_node, mode, last_flag) 399 { 400 401 this.ddt._ddtDumpNode( "enter-paragraphs.js", "263", "_fenEmptySet() : top with mode '" + mode + "' and last_flag '" + last_flag + "' and node:", node );395 * @param last_flag boolean is this the last node? 396 */ 397 398 EnterParagraphs.prototype._fenEmptySet = function( node, next_node, mode, last_flag) 399 { 400 401 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "263", "_fenEmptySet() : top with mode '" + mode + "' and last_flag '" + last_flag + "' and node:", node ); 402 402 403 403 // Mark this if it's the first base 404 404 405 if ( !next_node && !node.firstChild ) 405 if ( !next_node && !node.firstChild ) 406 406 { 407 407 next_node = node; … … 414 414 if ( (node.nodeType == 1 && this._elemSolid.test(node.nodeName)) || 415 415 (node.nodeType == 3 && !this._whiteSpace.test(node.nodeValue)) || 416 (node.nodeType != 1 && node.nodeType != 3) ) 417 { 418 419 this.ddt._ddtDumpNode( "enter-paragraphs.js", "263", "_fenEmptySet() : found content in node:", node );416 (node.nodeType != 1 && node.nodeType != 3) ) 417 { 418 419 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "263", "_fenEmptySet() : found content in node:", node ); 420 420 421 421 switch( mode ) … … 430 430 431 431 case "find_cursorpoint": 432 432 433 433 // returns content 434 434 … … 445 445 if ( last_flag ) 446 446 { 447 this.ddt._ddtDumpNode( "enter-paragraphs.js", "263", "_fenEmptySet() : return 'base' node:", next_node );447 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "263", "_fenEmptySet() : return 'base' node:", next_node ); 448 448 449 449 return new Array( true, next_node ); 450 450 } 451 451 452 this.ddt._ddtDumpNode( "enter-paragraphs.js", "263", "_fenEmptySet() : bottom returning false and :", next_node );452 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "263", "_fenEmptySet() : bottom returning false and :", next_node ); 453 453 454 454 return new Array( false, next_node ); … … 459 459 460 460 /** 461 * remove duplicate Id's. 461 * remove duplicate Id's. 462 462 * 463 463 * @param ep_ref enterparagraphs reference to enterparagraphs object 464 464 */ 465 465 466 EnterParagraphs.prototype._fenCullIds = function ( ep_ref, node, pong ) 467 { 468 469 this.ddt._ddt( "enter-paragraphs.js", "299", "_fenCullIds(): top" );466 EnterParagraphs.prototype._fenCullIds = function ( ep_ref, node, pong ) 467 { 468 469 //this.ddt._ddt( "enter-paragraphs.js", "299", "_fenCullIds(): top" ); 470 470 471 471 // Check for an id, blast it if it's in the store, otherwise add it 472 472 473 if ( node.id ) 474 { 475 476 this.ddt._ddt( "enter-paragraphs.js", "299", "_fenCullIds(): node '" + node.nodeName + "' has an id '" + node.id + "'" );473 if ( node.id ) 474 { 475 476 //this.ddt._ddt( "enter-paragraphs.js", "299", "_fenCullIds(): node '" + node.nodeName + "' has an id '" + node.id + "'" ); 477 477 478 478 pong[node.id] ? node.id = '' : pong[node.id] = true; … … 489 489 * 490 490 * @param rng Range 491 * @param search_direction string "left" or "right" 491 * @param search_direction string "left" or "right" 492 492 * 493 493 * @todo check blank node issue in roaming loop. 494 494 */ 495 495 496 EnterParagraphs.prototype.processSide = function( rng, search_direction) 497 { 498 499 this.ddt._ddt( "enter-paragraphs.js", "329", "processSide(): top search_direction == '" + search_direction + "'" );500 501 var next = function(element, search_direction) 502 { 503 return ( search_direction == "left" ? element.previousSibling : element.nextSibling ); 496 EnterParagraphs.prototype.processSide = function( rng, search_direction) 497 { 498 499 //this.ddt._ddt( "enter-paragraphs.js", "329", "processSide(): top search_direction == '" + search_direction + "'" ); 500 501 var next = function(element, search_direction) 502 { 503 return ( search_direction == "left" ? element.previousSibling : element.nextSibling ); 504 504 }; 505 505 … … 508 508 var roam, start = node; 509 509 510 this.ddt._ddtDumpNode( "enter-paragraphs.js", "337", "processSide(): starting with node:", node );510 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "337", "processSide(): starting with node:", node ); 511 511 512 512 // Never start with an element, because then the first roaming node might 513 513 // be on the exclusion list and we wouldn't know until it was too late 514 514 515 while ( start.nodeType == 1 && !this._permEmpty.test(start.nodeName) ) 515 while ( start.nodeType == 1 && !this._permEmpty.test(start.nodeName) ) 516 516 { 517 517 start = ( offset ? start.lastChild : start.firstChild ); … … 532 532 { 533 533 534 this.ddt._ddtDumpNode( "enter-paragraphs.js", "357", "processSide(): roaming loop, search_direction is '" + search_direction + "' current node is: ", roam );534 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "357", "processSide(): roaming loop, search_direction is '" + search_direction + "' current node is: ", roam ); 535 535 536 536 // next() is an inline function defined above that returns the next node depending 537 537 // on the direction we're searching. 538 538 539 if ( next(roam,search_direction) ) 540 { 541 542 this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Checking next node '" + next(roam,search_direction).NodeName + "' for _pExclusions list." );539 if ( next(roam,search_direction) ) 540 { 541 542 //this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Checking next node '" + next(roam,search_direction).NodeName + "' for _pExclusions list." ); 543 543 544 544 // If the next sibling's on the exclusion list, stop before it 545 545 546 if ( this._pExclusions.test(next(roam,search_direction).nodeName) ) 546 if ( this._pExclusions.test(next(roam,search_direction).nodeName) ) 547 547 { 548 548 549 this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Node '" + next(roam,search_direction).NodeName + "' is on the _pExclusions list. Stopping before it." );549 //this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Node '" + next(roam,search_direction).NodeName + "' is on the _pExclusions list. Stopping before it." ); 550 550 551 551 return this.processRng(rng, search_direction, roam, next(roam,search_direction), (search_direction == "left"?'AfterEnd':'BeforeBegin'), true, false); 552 } 553 } 554 else 555 { 556 557 this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): No next node, examing parent node '" + roam.parentNode.nodeName + "' for containers or exclusions." );552 } 553 } 554 else 555 { 556 557 //this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): No next node, examing parent node '" + roam.parentNode.nodeName + "' for containers or exclusions." ); 558 558 559 559 // If our parent's on the container list, stop inside it 560 560 561 if (this._pContainers.test(roam.parentNode.nodeName)) 561 if (this._pContainers.test(roam.parentNode.nodeName)) 562 562 { 563 563 564 this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Parent Node '" + roam.parentNode.nodeName + "' is on the _pContainer list. Stopping inside it." );564 //this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Parent Node '" + roam.parentNode.nodeName + "' is on the _pContainer list. Stopping inside it." ); 565 565 566 566 return this.processRng(rng, search_direction, roam, roam.parentNode, (search_direction == "left"?'AfterBegin':'BeforeEnd'), true, false); 567 567 } 568 else if (this._pExclusions.test(roam.parentNode.nodeName)) 568 else if (this._pExclusions.test(roam.parentNode.nodeName)) 569 569 { 570 570 571 this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Parent Node '" + roam.parentNode.nodeName + "' is on the _pExclusion list." );571 //this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Parent Node '" + roam.parentNode.nodeName + "' is on the _pExclusion list." ); 572 572 573 573 // chop without wrapping 574 574 575 if (this._pBreak.test(roam.parentNode.nodeName)) 575 if (this._pBreak.test(roam.parentNode.nodeName)) 576 576 { 577 577 578 this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Parent Node '" + roam.parentNode.nodeName + "' is on the _pBreak list." );578 //this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Parent Node '" + roam.parentNode.nodeName + "' is on the _pBreak list." ); 579 579 580 580 return this.processRng(rng, search_direction, roam, roam.parentNode, 581 581 (search_direction == "left"?'AfterBegin':'BeforeEnd'), false, (search_direction == "left" ?true:false)); 582 } 583 else 582 } 583 else 584 584 { 585 585 586 this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Parent Node '" + roam.parentNode.nodeName + "' is not on the _pBreak list." );586 //this.ddt._ddt( "enter-paragraphs.js", "371", "processSide(): Parent Node '" + roam.parentNode.nodeName + "' is not on the _pBreak list." ); 587 587 588 588 // the next(roam,search_direction) in this call is redundant since we know it's false … … 592 592 // because it's already wrapped. 593 593 594 return this.processRng(rng, 595 search_direction, 594 return this.processRng(rng, 595 search_direction, 596 596 (roam = roam.parentNode), 597 597 (next(roam,search_direction) ? next(roam,search_direction) : roam.parentNode), 598 (next(roam,search_direction) ? (search_direction == "left"?'AfterEnd':'BeforeBegin') : (search_direction == "left"?'AfterBegin':'BeforeEnd')), 599 false, 598 (next(roam,search_direction) ? (search_direction == "left"?'AfterEnd':'BeforeBegin') : (search_direction == "left"?'AfterBegin':'BeforeEnd')), 599 false, 600 600 false); 601 } 602 } 603 } 604 } 605 606 this.ddt._ddt( "enter-paragraphs.js", "424", "processSide(): bottom" );601 } 602 } 603 } 604 } 605 606 //this.ddt._ddt( "enter-paragraphs.js", "424", "processSide(): bottom" ); 607 607 608 608 }; // end of processSide() … … 618 618 * @param rn Range original selected range 619 619 * @param search_direction string Direction to search in. 620 * @param roam node 620 * @param roam node 621 621 * @param insertion string may be AfterBegin of BeforeEnd 622 622 * @return array 623 623 */ 624 624 625 EnterParagraphs.prototype.processRng = function(rng, search_direction, roam, neighbour, insertion, pWrap, preBr) 626 { 627 628 this.ddt._ddtDumpNode( "enter-paragraphs.js", "398", "processRng(): top - roam arg is:", roam );629 this.ddt._ddtDumpNode( "enter-paragraphs.js", "398", "processRng(): top - neighbor arg is:", neighbour );630 631 this.ddt._ddt( "enter-paragraphs.js", "398", "processRng(): top - insertion arg is: '" + insertion + "'" );625 EnterParagraphs.prototype.processRng = function(rng, search_direction, roam, neighbour, insertion, pWrap, preBr) 626 { 627 628 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "398", "processRng(): top - roam arg is:", roam ); 629 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "398", "processRng(): top - neighbor arg is:", neighbour ); 630 631 //this.ddt._ddt( "enter-paragraphs.js", "398", "processRng(): top - insertion arg is: '" + insertion + "'" ); 632 632 633 633 var node = search_direction == "left" ? rng.startContainer : rng.endContainer; 634 634 var offset = search_direction == "left" ? rng.startOffset : rng.endOffset; 635 635 636 this.ddt._ddtDumpNode( "enter-paragraphs.js", "447", "processRng(): range start (or end) is at offset '" + offset + "' is node :", node );636 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "447", "processRng(): range start (or end) is at offset '" + offset + "' is node :", node ); 637 637 638 638 // Define the range to cut, and extend the selection range to the same boundary … … 643 643 newRng.selectNode(roam); 644 644 645 this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): selecting newRng is:", newRng );646 this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): selecting original rng is:", rng );645 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): selecting newRng is:", newRng ); 646 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): selecting original rng is:", rng ); 647 647 648 648 // extend the range in the given direction. … … 653 653 rng.setStart(newRng.startContainer, newRng.startOffset); 654 654 655 this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): extending direction left - newRng is:", newRng );656 this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): extending direction left - rng is:", rng );657 658 } 655 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): extending direction left - newRng is:", newRng ); 656 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): extending direction left - rng is:", rng ); 657 658 } 659 659 else if ( search_direction == "right" ) 660 660 { … … 663 663 rng.setEnd(newRng.endContainer, newRng.endOffset); 664 664 665 this.ddt._ddt( "enter-paragraphs.js", "522", "processRng(): right - new range start is '" + offset + "' end offset is '" + newRng.endOffset + "'" );665 //this.ddt._ddt( "enter-paragraphs.js", "522", "processRng(): right - new range start is '" + offset + "' end offset is '" + newRng.endOffset + "'" ); 666 666 } 667 667 668 this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): rng is:", rng );669 this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): newRng is:", newRng );668 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): rng is:", rng ); 669 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "522", "processRng(): newRng is:", newRng ); 670 670 671 671 // Clone the range and remove duplicate ids it would otherwise produce … … 673 673 var cnt = newRng.cloneContents(); 674 674 675 this.ddt._ddtDumpNode( "enter-paragraphs.js", "509", "processRng(): culling duplicate ids from:", cnt );675 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "509", "processRng(): culling duplicate ids from:", cnt ); 676 676 677 677 // in this case "init" is an object not a boolen. … … 679 679 this.forEachNodeUnder( cnt, "cullids", "ltr", this.takenIds, false, false); 680 680 681 // Special case, for inserting paragraphs before some blocks when caret is at 682 // their zero offset. 681 // Special case, for inserting paragraphs before some blocks when caret is at 682 // their zero offset. 683 683 // 684 684 // Used to "open up space" in front of a list, table. Usefull if the list is at … … 690 690 pify = pify ? newRng.startContainer : newRng.endContainer; 691 691 692 this.ddt._ddtDumpNode( "enter-paragraphs.js", "521", "processRng(): pify is '" + pify.nodeName + "' pifyOffset is '" + pifyOffset + "':", pify );693 694 if ( this._pifyParent.test(pify.nodeName) && pify.parentNode.childNodes.item(0) == pify ) 695 { 696 while ( !this._pifySibling.test(pify.nodeName) ) 692 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "521", "processRng(): pify is '" + pify.nodeName + "' pifyOffset is '" + pifyOffset + "':", pify ); 693 694 if ( this._pifyParent.test(pify.nodeName) && pify.parentNode.childNodes.item(0) == pify ) 695 { 696 while ( !this._pifySibling.test(pify.nodeName) ) 697 697 { 698 698 pify = pify.parentNode; … … 702 702 // NODE TYPE 11 is DOCUMENT_FRAGMENT NODE 703 703 704 if ( cnt.nodeType == 11 && !cnt.firstChild ) 704 if ( cnt.nodeType == 11 && !cnt.firstChild ) 705 705 { 706 706 cnt.appendChild(editor._doc.createElement(pify.nodeName)); … … 710 710 // error in forEachNode() 711 711 712 this.ddt._ddt( "enter-paragraphs.js", "612", "processRng(): find_fill in cnt." );712 //this.ddt._ddt( "enter-paragraphs.js", "612", "processRng(): find_fill in cnt." ); 713 713 714 714 fill = this.forEachNodeUnder(cnt, "find_fill", "ltr", false ); 715 715 716 this.ddt._ddtDumpNode( "enter-paragraphs.js", "612", "processRng(): fill node:" , fill );717 718 if ( fill && 716 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "612", "processRng(): fill node:" , fill ); 717 718 if ( fill && 719 719 this._pifySibling.test(pify.nodeName) && 720 ( (pifyOffset == 0) || ( pifyOffset == 1 && this._pifyForced.test(pify.nodeName) ) ) ) 721 { 722 723 this.ddt._ddt( "enter-paragraphs.js", "544", "processRng(): pify handling. Creating p tag followed by nbsp tag" );720 ( (pifyOffset == 0) || ( pifyOffset == 1 && this._pifyForced.test(pify.nodeName) ) ) ) 721 { 722 723 //this.ddt._ddt( "enter-paragraphs.js", "544", "processRng(): pify handling. Creating p tag followed by nbsp tag" ); 724 724 725 725 roam = editor._doc.createElement( 'p' ); … … 733 733 // after the list etc. 734 734 735 if ((search_direction == "left" ) && pify.previousSibling) 736 { 737 738 this.ddt._ddt( "enter-paragraphs.js", "682", "processRng(): returning created roam AfterEnd" );735 if ((search_direction == "left" ) && pify.previousSibling) 736 { 737 738 //this.ddt._ddt( "enter-paragraphs.js", "682", "processRng(): returning created roam AfterEnd" ); 739 739 740 740 return new Array(pify.previousSibling, 'AfterEnd', roam); 741 741 } 742 else if (( search_direction == "right") && pify.nextSibling) 743 { 744 745 this.ddt._ddt( "enter-paragraphs.js", "682", "processRng(): returning created roam BeforeBegin" );742 else if (( search_direction == "right") && pify.nextSibling) 743 { 744 745 //this.ddt._ddt( "enter-paragraphs.js", "682", "processRng(): returning created roam BeforeBegin" ); 746 746 747 747 return new Array(pify.nextSibling, 'BeforeBegin', roam); 748 748 } 749 else 750 { 751 752 this.ddt._ddt( "enter-paragraphs.js", "682", "processRng(): returning created roam for direction '" + search_direction + "'" );749 else 750 { 751 752 //this.ddt._ddt( "enter-paragraphs.js", "682", "processRng(): returning created roam for direction '" + search_direction + "'" ); 753 753 754 754 return new Array(pify.parentNode, (search_direction == "left"?'AfterBegin':'BeforeEnd'), roam); … … 759 759 // If our cloned contents are 'content'-less, shove a break in them 760 760 761 if ( fill ) 762 { 763 764 // Ill-concieved? 761 if ( fill ) 762 { 763 764 // Ill-concieved? 765 765 // 766 766 // 3 is a TEXT node and it should be empty. 767 // 768 769 if ( fill.nodeType == 3 ) 770 { 771 // fill = fill.parentNode; 767 // 768 769 if ( fill.nodeType == 3 ) 770 { 771 // fill = fill.parentNode; 772 772 773 773 fill = editor._doc.createDocumentFragment(); 774 774 775 this.ddt._ddtDumpNode( "enter-paragraphs.js", "575", "processRng(): fill.nodeType is 3. Moving up to parent:", fill );776 } 777 778 if ( (fill.nodeType == 1 && !this._elemSolid.test()) || fill.nodeType == 11 ) 779 { 780 781 // FIXME:/CHECKME: When Xinha is switched from WYSIWYG to text mode 775 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "575", "processRng(): fill.nodeType is 3. Moving up to parent:", fill ); 776 } 777 778 if ( (fill.nodeType == 1 && !this._elemSolid.test()) || fill.nodeType == 11 ) 779 { 780 781 // FIXME:/CHECKME: When Xinha is switched from WYSIWYG to text mode 782 782 // HTMLArea.getHTMLWrapper() will strip out the trailing br. Not sure why. 783 783 … … 788 788 789 789 fill.appendChild( pterminator ); 790 791 this.ddt._ddtDumpNode( "enter-paragraphs.js", "583", "processRng(): fill type is 1 and !elemsolid or it's type 11. Appending an nbsp tag:", fill );792 793 } 794 else 795 { 796 797 this.ddt._ddt( "enter-paragraphs.js", "583", "processRng(): inserting a br tag before." );790 791 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "583", "processRng(): fill type is 1 and !elemsolid or it's type 11. Appending an nbsp tag:", fill ); 792 793 } 794 else 795 { 796 797 //this.ddt._ddt( "enter-paragraphs.js", "583", "processRng(): inserting a br tag before." ); 798 798 799 799 // fill.parentNode.insertBefore(editor._doc.createElement('br'),fill); … … 809 809 // YmL: If there was no content replace with fill 810 810 // (previous code did not use fill and we ended up with the 811 // <p>test</p><p></p> because Gecko was finding two empty text nodes 811 // <p>test</p><p></p> because Gecko was finding two empty text nodes 812 812 // when traversing on the right hand side of an empty document. 813 813 … … 815 815 { 816 816 817 this.ddt._ddtDumpNode( "enter-paragraphs.js", "606", "processRng(): no content. Using fill.", fill );817 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "606", "processRng(): no content. Using fill.", fill ); 818 818 819 819 roam = fill; … … 823 823 // And stuff a shiny new object with whatever contents we have 824 824 825 this.ddt._ddt( "enter-paragraphs.js", "606", "processRng(): creating p tag or document fragment - pWrap is '" + pWrap + "' " );826 825 //this.ddt._ddt( "enter-paragraphs.js", "606", "processRng(): creating p tag or document fragment - pWrap is '" + pWrap + "' " ); 826 827 827 roam = (pWrap || (cnt.nodeType == 11 && !cnt.firstChild)) ? editor._doc.createElement('p') : editor._doc.createDocumentFragment(); 828 828 roam.appendChild(cnt); 829 829 } 830 830 831 if (preBr) 832 { 833 this.ddt._ddt( "enter-paragraphs.js", "767", "processRng(): appending a br based on preBr flag" );831 if (preBr) 832 { 833 //this.ddt._ddt( "enter-paragraphs.js", "767", "processRng(): appending a br based on preBr flag" ); 834 834 835 835 roam.appendChild(editor._doc.createElement('br')); 836 836 } 837 837 838 this.ddt._ddtDumpNode( "enter-paragraphs.js", "606", "processRng(): bottom with roam:", roam );839 this.ddt._ddtDumpNode( "enter-paragraphs.js", "606", "processRng(): bottom with neighbour:", neighbour );838 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "606", "processRng(): bottom with roam:", roam ); 839 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "606", "processRng(): bottom with neighbour:", neighbour ); 840 840 841 841 // Return the nearest relative, relative insertion point and fragment to insert … … 852 852 * there is no good way to "get out of" ordered or unordered lists from Javascript. 853 853 * We have to pass the onKeyPress 13 event to the browser so it can take care of 854 * getting us "out of" the list. 855 * 856 * The Gecko engine does a good job of handling all the normal <li> cases except the "press 854 * getting us "out of" the list. 855 * 856 * The Gecko engine does a good job of handling all the normal <li> cases except the "press 857 857 * enter at the first position" where we want a <p> </p> inserted before the list. The 858 858 * built-in behavior is to open up a <li> before the current entry (not good). 859 * 859 * 860 860 * @param rng Range range. 861 861 */ … … 864 864 { 865 865 866 this.ddt._ddtDumpNode( "enter-paragraphs.js", "863", "isNormaListItem(): checking rng for list end:", rng );866 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "863", "isNormaListItem(): checking rng for list end:", rng ); 867 867 868 868 var node, listNode; … … 874 874 { 875 875 876 this.ddt._ddt( "enter-paragraphs.js", "863", "isNormaListItem(): node is a list item");876 //this.ddt._ddt( "enter-paragraphs.js", "863", "isNormaListItem(): node is a list item"); 877 877 878 878 // are we a list item? … … 885 885 { 886 886 887 this.ddt._ddt( "enter-paragraphs.js", "863", "isNormaListItem(): parent is a list item");888 887 //this.ddt._ddt( "enter-paragraphs.js", "863", "isNormaListItem(): parent is a list item"); 888 889 889 // our parent is a list item. 890 890 … … 894 894 else 895 895 { 896 this.ddt._ddt( "enter-paragraphs.js", "863", "isNormaListItem(): not list item");896 //this.ddt._ddt( "enter-paragraphs.js", "863", "isNormaListItem(): not list item"); 897 897 898 898 // neither we nor our parent are a list item. this is not a normal … … 902 902 } 903 903 904 // at this point we have a listNode. Is it the first list item? 904 // at this point we have a listNode. Is it the first list item? 905 905 906 906 if ( ! listNode.previousSibling ) 907 907 { 908 this.ddt._ddt( "enter-paragraphs.js", "839", "isNormaListItem(): we are the first li." );909 910 // are we on the first character of the first li? 908 //this.ddt._ddt( "enter-paragraphs.js", "839", "isNormaListItem(): we are the first li." ); 909 910 // are we on the first character of the first li? 911 911 912 912 if ( rng.startOffset == 0 ) 913 913 { 914 this.ddt._ddt( "enter-paragraphs.js", "839", "isNormaListItem(): we are on the first character." );914 //this.ddt._ddt( "enter-paragraphs.js", "839", "isNormaListItem(): we are on the first character." ); 915 915 916 916 return false; … … 918 918 } 919 919 920 this.ddt._ddt( "enter-paragraphs.js", "839", "isNormaListItem(): this is a normal list item case." );920 //this.ddt._ddt( "enter-paragraphs.js", "839", "isNormaListItem(): this is a normal list item case." ); 921 921 return true; 922 922 … … 924 924 925 925 // ---------------------------------------------------------------------------------- 926 /** 926 /** 927 927 * Called when a key is pressed in the editor 928 928 */ 929 929 930 EnterParagraphs.prototype.__onKeyPress = function(ev) 931 { 932 933 this.ddt._ddt( "enter-paragraphs.js", "517", "__onKeyPress(): top with keyCode '" + ev.keyCode + "'" );930 EnterParagraphs.prototype.__onKeyPress = function(ev) 931 { 932 933 //this.ddt._ddt( "enter-paragraphs.js", "517", "__onKeyPress(): top with keyCode '" + ev.keyCode + "'" ); 934 934 935 935 // If they've hit enter and shift is not pressed, handle it … … 937 937 if (ev.keyCode == 13 && !ev.shiftKey && this.editor._iframe.contentWindow.getSelection) 938 938 { 939 this.ddt._ddt( "enter-paragraphs.js", "517", "__onKeyPress(): calling handleEnter" );939 //this.ddt._ddt( "enter-paragraphs.js", "517", "__onKeyPress(): calling handleEnter" ); 940 940 941 941 return this.handleEnter(ev); 942 942 } 943 943 944 this.ddt._ddt( "enter-paragraphs.js", "517", "__onKeyPress(): bottom" );944 //this.ddt._ddt( "enter-paragraphs.js", "517", "__onKeyPress(): bottom" ); 945 945 946 946 }; // end of _onKeyPress() … … 952 952 */ 953 953 954 EnterParagraphs.prototype.handleEnter = function(ev) 955 { 956 957 this.ddt._ddt( "enter-paragraphs.js", "537", "handleEnter(): top" );954 EnterParagraphs.prototype.handleEnter = function(ev) 955 { 956 957 //this.ddt._ddt( "enter-paragraphs.js", "537", "handleEnter(): top" ); 958 958 959 959 var cursorNode; … … 964 964 var rng = this.editor._createRange(sel); 965 965 966 this.ddt._ddtDumpNode( "enter-paragraphs.js", "757", "handleEnter(): initial range is: ", rng );966 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "757", "handleEnter(): initial range is: ", rng ); 967 967 968 968 // if we are at the end of a list and the node is empty let the browser handle … … 971 971 if ( this.isNormalListItem(rng) ) 972 972 { 973 this.ddt._ddt( "enter-paragraphs.js", "757", "handleEnter(): we are at the end of a list with a blank item. Letting the browser handle it." );973 //this.ddt._ddt( "enter-paragraphs.js", "757", "handleEnter(): we are at the end of a list with a blank item. Letting the browser handle it." ); 974 974 return true; 975 975 } 976 976 977 // as far as I can tell this isn't actually used. 977 // as far as I can tell this isn't actually used. 978 978 979 979 this.takenIds = new Object(); … … 986 986 // [2] roam 987 987 988 this.ddt._ddt( "enter-paragraphs.js", "537", "handleEnter(): calling processSide on left side." );988 //this.ddt._ddt( "enter-paragraphs.js", "537", "handleEnter(): calling processSide on left side." ); 989 989 990 990 var pStart = this.processSide(rng, "left"); 991 991 992 this.ddt._ddtDumpNode( "enter-paragraphs.js", "757", "handleEnter(): after processing left side range is: ", rng );993 994 this.ddt._ddt( "enter-paragraphs.js", "537", "handleEnter(): calling processSide on right side." );992 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "757", "handleEnter(): after processing left side range is: ", rng ); 993 994 //this.ddt._ddt( "enter-paragraphs.js", "537", "handleEnter(): calling processSide on right side." ); 995 995 996 996 var pEnd = this.processSide(rng, "right"); … … 1009 1009 // we'll use this to position the cursor. 1010 1010 1011 this.ddt._ddt( "enter-paragraphs.js", "712", "handleEnter(): looking for cursor position" );1011 //this.ddt._ddt( "enter-paragraphs.js", "712", "handleEnter(): looking for cursor position" ); 1012 1012 1013 1013 var holdEnd = this.forEachNodeUnder( cursorNode, "find_cursorpoint", "ltr", false, true); … … 1020 1020 // Insert our carefully chosen document fragments 1021 1021 1022 if ( pStart ) 1023 { 1024 1025 this.ddt._ddt( "enter-paragraphs.js", "712", "handleEnter(): inserting pEnd" );1022 if ( pStart ) 1023 { 1024 1025 //this.ddt._ddt( "enter-paragraphs.js", "712", "handleEnter(): inserting pEnd" ); 1026 1026 1027 1027 this.insertAdjacentElement(pStart[0], pStart[1], pStart[2]); 1028 1028 } 1029 1029 1030 if ( pEnd && pEnd.nodeType != 1) 1031 { 1032 1033 this.ddt._ddt( "enter-paragraphs.js", "712", "handleEnter(): inserting pEnd" );1030 if ( pEnd && pEnd.nodeType != 1) 1031 { 1032 1033 //this.ddt._ddt( "enter-paragraphs.js", "712", "handleEnter(): inserting pEnd" ); 1034 1034 1035 1035 this.insertAdjacentElement(pEnd[0], pEnd[1], pEnd[2]); … … 1038 1038 // Move the caret in front of the first good text element 1039 1039 1040 if ((holdEnd) && (this._permEmpty.test(holdEnd.nodeName) )) 1041 { 1042 1043 this.ddt._ddt( "enter-paragraphs.js", "712", "handleEnter(): looping to find cursor element." );1040 if ((holdEnd) && (this._permEmpty.test(holdEnd.nodeName) )) 1041 { 1042 1043 //this.ddt._ddt( "enter-paragraphs.js", "712", "handleEnter(): looping to find cursor element." ); 1044 1044 1045 1045 var prodigal = 0; 1046 while ( holdEnd.parentNode.childNodes.item(prodigal) != holdEnd ) 1046 while ( holdEnd.parentNode.childNodes.item(prodigal) != holdEnd ) 1047 1047 { 1048 1048 prodigal++; … … 1051 1051 sel.collapse( holdEnd.parentNode, prodigal); 1052 1052 } 1053 else 1053 else 1054 1054 { 1055 1055 1056 1056 // holdEnd might be false. 1057 1057 1058 try 1058 try 1059 1059 { 1060 1060 sel.collapse(holdEnd, 0); 1061 1061 1062 this.ddt._ddtDumpNode( "enter-paragraphs.js", "1057", "handleEnter(): scrolling to element:", holdEnd );1063 1064 // interestingly, scrollToElement() scroll so the top if holdEnd is a text node. 1065 1062 //this.ddt._ddtDumpNode( "enter-paragraphs.js", "1057", "handleEnter(): scrolling to element:", holdEnd ); 1063 1064 // interestingly, scrollToElement() scroll so the top if holdEnd is a text node. 1065 1066 1066 if ( holdEnd.nodeType == 3 ) 1067 1067 { … … 1071 1071 this.editor.scrollToElement(holdEnd); 1072 1072 } 1073 catch (e) 1073 catch (e) 1074 1074 { 1075 1075 // we could try to place the cursor at the end of the document. 1076 1076 } 1077 1077 } 1078 1078 1079 1079 this.editor.updateToolbar(); 1080 1080
Note: See TracChangeset
for help on using the changeset viewer.