2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2009 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Class for working with a selection range, much like the W3C DOM Range, but
22
* it is not intended to be an implementation of the W3C interface.
25
var FCKDomRange = function( sourceWindow )
27
this.Window = sourceWindow ;
31
FCKDomRange.prototype =
34
_UpdateElementInfo : function()
36
var innerRange = this._Range ;
39
this.Release( true ) ;
42
// For text nodes, the node itself is the StartNode.
43
var eStart = innerRange.startContainer ;
45
var oElementPath = new FCKElementPath( eStart ) ;
46
this.StartNode = eStart.nodeType == 3 ? eStart : eStart.childNodes[ innerRange.startOffset ] ;
47
this.StartContainer = eStart ;
48
this.StartBlock = oElementPath.Block ;
49
this.StartBlockLimit = oElementPath.BlockLimit ;
51
if ( innerRange.collapsed )
53
this.EndNode = this.StartNode ;
54
this.EndContainer = this.StartContainer ;
55
this.EndBlock = this.StartBlock ;
56
this.EndBlockLimit = this.StartBlockLimit ;
60
var eEnd = innerRange.endContainer ;
63
oElementPath = new FCKElementPath( eEnd ) ;
65
// The innerRange.endContainer[ innerRange.endOffset ] is not
66
// usually part of the range, but the marker for the range end. So,
67
// let's get the previous available node as the real end.
69
if ( innerRange.endOffset == 0 )
71
while ( eEndNode && !eEndNode.previousSibling )
72
eEndNode = eEndNode.parentNode ;
75
eEndNode = eEndNode.previousSibling ;
77
else if ( eEndNode.nodeType == 1 )
78
eEndNode = eEndNode.childNodes[ innerRange.endOffset - 1 ] ;
80
this.EndNode = eEndNode ;
81
this.EndContainer = eEnd ;
82
this.EndBlock = oElementPath.Block ;
83
this.EndBlockLimit = oElementPath.BlockLimit ;
90
CreateRange : function()
92
return new FCKW3CRange( this.Window.document ) ;
95
DeleteContents : function()
99
this._Range.deleteContents() ;
100
this._UpdateElementInfo() ;
104
ExtractContents : function()
108
var docFrag = this._Range.extractContents() ;
109
this._UpdateElementInfo() ;
115
CheckIsCollapsed : function()
118
return this._Range.collapsed ;
123
Collapse : function( toStart )
126
this._Range.collapse( toStart ) ;
128
this._UpdateElementInfo() ;
133
var oClone = FCKTools.CloneObject( this ) ;
136
oClone._Range = this._Range.cloneRange() ;
141
MoveToNodeContents : function( targetNode )
144
this._Range = this.CreateRange() ;
146
this._Range.selectNodeContents( targetNode ) ;
148
this._UpdateElementInfo() ;
151
MoveToElementStart : function( targetElement )
153
this.SetStart(targetElement,1) ;
154
this.SetEnd(targetElement,1) ;
157
// Moves to the first editing point inside a element. For example, in a
158
// element tree like "<p><b><i></i></b> Text</p>", the start editing point
159
// is "<p><b><i>^</i></b> Text</p>" (inside <i>).
160
MoveToElementEditStart : function( targetElement )
162
var editableElement ;
164
while ( targetElement && targetElement.nodeType == 1 )
166
if ( FCKDomTools.CheckIsEditable( targetElement ) )
167
editableElement = targetElement ;
168
else if ( editableElement )
169
break ; // If we already found an editable element, stop the loop.
171
targetElement = targetElement.firstChild ;
174
if ( editableElement )
175
this.MoveToElementStart( editableElement ) ;
178
InsertNode : function( node )
181
this._Range.insertNode( node ) ;
184
CheckIsEmpty : function()
186
if ( this.CheckIsCollapsed() )
189
// Inserts the contents of the range in a div tag.
190
var eToolDiv = this.Window.document.createElement( 'div' ) ;
191
this._Range.cloneContents().AppendTo( eToolDiv ) ;
193
FCKDomTools.TrimNode( eToolDiv ) ;
195
return ( eToolDiv.innerHTML.length == 0 ) ;
199
* Checks if the start boundary of the current range is "visually" (like a
200
* selection caret) at the beginning of the block. It means that some
201
* things could be brefore the range, like spaces or empty inline elements,
202
* but it would still be considered at the beginning of the block.
204
CheckStartOfBlock : function()
206
var cache = this._Cache ;
207
var bIsStartOfBlock = cache.IsStartOfBlock ;
209
if ( bIsStartOfBlock != undefined )
210
return bIsStartOfBlock ;
212
// Take the block reference.
213
var block = this.StartBlock || this.StartBlockLimit ;
215
var container = this._Range.startContainer ;
216
var offset = this._Range.startOffset ;
221
// First, check the start container. If it is a text node, get the
222
// substring of the node value before the range offset.
223
if ( container.nodeType == 3 )
225
var textValue = container.nodeValue.substr( 0, offset ).Trim() ;
227
// If we have some text left in the container, we are not at
228
// the end for the block.
229
if ( textValue.length != 0 )
230
return cache.IsStartOfBlock = false ;
233
currentNode = container.childNodes[ offset - 1 ] ;
236
// We'll not have a currentNode if the container was a text node, or
237
// the offset is zero.
239
currentNode = FCKDomTools.GetPreviousSourceNode( container, true, null, block ) ;
241
while ( currentNode )
243
switch ( currentNode.nodeType )
246
// It's not an inline element.
247
if ( !FCKListsLib.InlineChildReqElements[ currentNode.nodeName.toLowerCase() ] )
248
return cache.IsStartOfBlock = false ;
253
// It's a text node with real text.
254
if ( currentNode.nodeValue.Trim().length > 0 )
255
return cache.IsStartOfBlock = false ;
258
currentNode = FCKDomTools.GetPreviousSourceNode( currentNode, false, null, block ) ;
261
return cache.IsStartOfBlock = true ;
265
* Checks if the end boundary of the current range is "visually" (like a
266
* selection caret) at the end of the block. It means that some things
267
* could be after the range, like spaces, empty inline elements, or a
268
* single <br>, but it would still be considered at the end of the block.
270
CheckEndOfBlock : function( refreshSelection )
272
var isEndOfBlock = this._Cache.IsEndOfBlock ;
274
if ( isEndOfBlock != undefined )
275
return isEndOfBlock ;
277
// Take the block reference.
278
var block = this.EndBlock || this.EndBlockLimit ;
280
var container = this._Range.endContainer ;
281
var offset = this._Range.endOffset ;
284
// First, check the end container. If it is a text node, get the
285
// substring of the node value after the range offset.
286
if ( container.nodeType == 3 )
288
var textValue = container.nodeValue ;
289
if ( offset < textValue.length )
291
textValue = textValue.substr( offset ) ;
293
// If we have some text left in the container, we are not at
294
// the end for the block.
295
if ( textValue.Trim().length != 0 )
296
return this._Cache.IsEndOfBlock = false ;
300
currentNode = container.childNodes[ offset ] ;
302
// We'll not have a currentNode if the container was a text node, of
303
// the offset is out the container children limits (after it probably).
305
currentNode = FCKDomTools.GetNextSourceNode( container, true, null, block ) ;
309
while ( currentNode )
311
switch ( currentNode.nodeType )
314
var nodeName = currentNode.nodeName.toLowerCase() ;
316
// It's an inline element.
317
if ( FCKListsLib.InlineChildReqElements[ nodeName ] )
320
// It is the first <br> found.
321
if ( nodeName == 'br' && !hadBr )
327
return this._Cache.IsEndOfBlock = false ;
330
// It's a text node with real text.
331
if ( currentNode.nodeValue.Trim().length > 0 )
332
return this._Cache.IsEndOfBlock = false ;
335
currentNode = FCKDomTools.GetNextSourceNode( currentNode, false, null, block ) ;
338
if ( refreshSelection )
341
return this._Cache.IsEndOfBlock = true ;
344
// This is an "intrusive" way to create a bookmark. It includes <span> tags
345
// in the range boundaries. The advantage of it is that it is possible to
346
// handle DOM mutations when moving back to the bookmark.
347
// Attention: the inclusion of nodes in the DOM is a design choice and
348
// should not be changed as there are other points in the code that may be
349
// using those nodes to perform operations. See GetBookmarkNode.
350
// For performance, includeNodes=true if intended to SelectBookmark.
351
CreateBookmark : function( includeNodes )
353
// Create the bookmark info (random IDs).
356
StartId : (new Date()).valueOf() + Math.floor(Math.random()*1000) + 'S',
357
EndId : (new Date()).valueOf() + Math.floor(Math.random()*1000) + 'E'
360
var oDoc = this.Window.document ;
365
// For collapsed ranges, add just the start marker.
366
if ( !this.CheckIsCollapsed() )
368
eEndSpan = oDoc.createElement( 'span' ) ;
369
eEndSpan.style.display = 'none' ;
370
eEndSpan.id = oBookmark.EndId ;
371
eEndSpan.setAttribute( '_fck_bookmark', true ) ;
373
// For IE, it must have something inside, otherwise it may be
374
// removed during DOM operations.
375
// if ( FCKBrowserInfo.IsIE )
376
eEndSpan.innerHTML = ' ' ;
378
oClone = this.Clone() ;
379
oClone.Collapse( false ) ;
380
oClone.InsertNode( eEndSpan ) ;
383
eStartSpan = oDoc.createElement( 'span' ) ;
384
eStartSpan.style.display = 'none' ;
385
eStartSpan.id = oBookmark.StartId ;
386
eStartSpan.setAttribute( '_fck_bookmark', true ) ;
388
// For IE, it must have something inside, otherwise it may be removed
389
// during DOM operations.
390
// if ( FCKBrowserInfo.IsIE )
391
eStartSpan.innerHTML = ' ' ;
393
oClone = this.Clone() ;
394
oClone.Collapse( true ) ;
395
oClone.InsertNode( eStartSpan ) ;
399
oBookmark.StartNode = eStartSpan ;
400
oBookmark.EndNode = eEndSpan ;
403
// Update the range position.
406
this.SetStart( eStartSpan, 4 ) ;
407
this.SetEnd( eEndSpan, 3 ) ;
410
this.MoveToPosition( eStartSpan, 4 ) ;
415
// This one should be a part of a hypothetic "bookmark" object.
416
GetBookmarkNode : function( bookmark, start )
418
var doc = this.Window.document ;
421
return bookmark.StartNode || doc.getElementById( bookmark.StartId ) ;
423
return bookmark.EndNode || doc.getElementById( bookmark.EndId ) ;
426
MoveToBookmark : function( bookmark, preserveBookmark )
428
var eStartSpan = this.GetBookmarkNode( bookmark, true ) ;
429
var eEndSpan = this.GetBookmarkNode( bookmark, false ) ;
431
this.SetStart( eStartSpan, 3 ) ;
433
if ( !preserveBookmark )
434
FCKDomTools.RemoveNode( eStartSpan ) ;
436
// If collapsed, the end span will not be available.
439
this.SetEnd( eEndSpan, 3 ) ;
441
if ( !preserveBookmark )
442
FCKDomTools.RemoveNode( eEndSpan ) ;
445
this.Collapse( true ) ;
447
this._UpdateElementInfo() ;
450
// Non-intrusive bookmark algorithm
451
CreateBookmark2 : function()
453
// If there is no range then get out of here.
454
// It happens on initial load in Safari #962 and if the editor it's hidden also in Firefox
456
return { "Start" : 0, "End" : 0 } ;
458
// First, we record down the offset values
461
"Start" : [ this._Range.startOffset ],
462
"End" : [ this._Range.endOffset ]
464
// Since we're treating the document tree as normalized, we need to backtrack the text lengths
465
// of previous text nodes into the offset value.
466
var curStart = this._Range.startContainer.previousSibling ;
467
var curEnd = this._Range.endContainer.previousSibling ;
469
// Also note that the node that we use for "address base" would change during backtracking.
470
var addrStart = this._Range.startContainer ;
471
var addrEnd = this._Range.endContainer ;
472
while ( curStart && curStart.nodeType == 3 && addrStart.nodeType == 3 )
474
bookmark.Start[0] += curStart.length ;
475
addrStart = curStart ;
476
curStart = curStart.previousSibling ;
478
while ( curEnd && curEnd.nodeType == 3 && addrEnd.nodeType == 3 )
480
bookmark.End[0] += curEnd.length ;
482
curEnd = curEnd.previousSibling ;
485
// If the object pointed to by the startOffset and endOffset are text nodes, we need
486
// to backtrack and add in the text offset to the bookmark addresses.
487
if ( addrStart.nodeType == 1 && addrStart.childNodes[bookmark.Start[0]] && addrStart.childNodes[bookmark.Start[0]].nodeType == 3 )
489
var curNode = addrStart.childNodes[bookmark.Start[0]] ;
491
while ( curNode.previousSibling && curNode.previousSibling.nodeType == 3 )
493
curNode = curNode.previousSibling ;
494
offset += curNode.length ;
496
addrStart = curNode ;
497
bookmark.Start[0] = offset ;
499
if ( addrEnd.nodeType == 1 && addrEnd.childNodes[bookmark.End[0]] && addrEnd.childNodes[bookmark.End[0]].nodeType == 3 )
501
var curNode = addrEnd.childNodes[bookmark.End[0]] ;
503
while ( curNode.previousSibling && curNode.previousSibling.nodeType == 3 )
505
curNode = curNode.previousSibling ;
506
offset += curNode.length ;
509
bookmark.End[0] = offset ;
512
// Then, we record down the precise position of the container nodes
513
// by walking up the DOM tree and counting their childNode index
514
bookmark.Start = FCKDomTools.GetNodeAddress( addrStart, true ).concat( bookmark.Start ) ;
515
bookmark.End = FCKDomTools.GetNodeAddress( addrEnd, true ).concat( bookmark.End ) ;
519
MoveToBookmark2 : function( bookmark )
521
// Reverse the childNode counting algorithm in CreateBookmark2()
522
var curStart = FCKDomTools.GetNodeFromAddress( this.Window.document, bookmark.Start.slice( 0, -1 ), true ) ;
523
var curEnd = FCKDomTools.GetNodeFromAddress( this.Window.document, bookmark.End.slice( 0, -1 ), true ) ;
525
// Generate the W3C Range object and update relevant data
526
this.Release( true ) ;
527
this._Range = new FCKW3CRange( this.Window.document ) ;
528
var startOffset = bookmark.Start[ bookmark.Start.length - 1 ] ;
529
var endOffset = bookmark.End[ bookmark.End.length - 1 ] ;
530
while ( curStart.nodeType == 3 && startOffset > curStart.length )
532
if ( ! curStart.nextSibling || curStart.nextSibling.nodeType != 3 )
534
startOffset -= curStart.length ;
535
curStart = curStart.nextSibling ;
537
while ( curEnd.nodeType == 3 && endOffset > curEnd.length )
539
if ( ! curEnd.nextSibling || curEnd.nextSibling.nodeType != 3 )
541
endOffset -= curEnd.length ;
542
curEnd = curEnd.nextSibling ;
544
this._Range.setStart( curStart, startOffset ) ;
545
this._Range.setEnd( curEnd, endOffset ) ;
546
this._UpdateElementInfo() ;
549
MoveToPosition : function( targetElement, position )
551
this.SetStart( targetElement, position ) ;
552
this.Collapse( true ) ;
556
* Moves the position of the start boundary of the range to a specific position
557
* relatively to a element.
559
* 1 = After Start <target>^contents</target>
560
* 2 = Before End <target>contents^</target>
561
* 3 = Before Start ^<target>contents</target>
562
* 4 = After End <target>contents</target>^
564
SetStart : function( targetElement, position, noInfoUpdate )
566
var oRange = this._Range ;
568
oRange = this._Range = this.CreateRange() ;
572
case 1 : // After Start <target>^contents</target>
573
oRange.setStart( targetElement, 0 ) ;
576
case 2 : // Before End <target>contents^</target>
577
oRange.setStart( targetElement, targetElement.childNodes.length ) ;
580
case 3 : // Before Start ^<target>contents</target>
581
oRange.setStartBefore( targetElement ) ;
584
case 4 : // After End <target>contents</target>^
585
oRange.setStartAfter( targetElement ) ;
589
this._UpdateElementInfo() ;
593
* Moves the position of the start boundary of the range to a specific position
594
* relatively to a element.
596
* 1 = After Start <target>^contents</target>
597
* 2 = Before End <target>contents^</target>
598
* 3 = Before Start ^<target>contents</target>
599
* 4 = After End <target>contents</target>^
601
SetEnd : function( targetElement, position, noInfoUpdate )
603
var oRange = this._Range ;
605
oRange = this._Range = this.CreateRange() ;
609
case 1 : // After Start <target>^contents</target>
610
oRange.setEnd( targetElement, 0 ) ;
613
case 2 : // Before End <target>contents^</target>
614
oRange.setEnd( targetElement, targetElement.childNodes.length ) ;
617
case 3 : // Before Start ^<target>contents</target>
618
oRange.setEndBefore( targetElement ) ;
621
case 4 : // After End <target>contents</target>^
622
oRange.setEndAfter( targetElement ) ;
626
this._UpdateElementInfo() ;
629
Expand : function( unit )
631
var oNode, oSibling ;
635
// Expand the range to include all inline parent elements if we are
636
// are in their boundary limits.
637
// For example (where [ ] are the range limits):
638
// Before => Some <b>[<i>Some sample text]</i></b>.
639
// After => Some [<b><i>Some sample text</i></b>].
640
case 'inline_elements' :
641
// Expand the start boundary.
642
if ( this._Range.startOffset == 0 )
644
oNode = this._Range.startContainer ;
646
if ( oNode.nodeType != 1 )
647
oNode = oNode.previousSibling ? null : oNode.parentNode ;
651
while ( FCKListsLib.InlineNonEmptyElements[ oNode.nodeName.toLowerCase() ] )
653
this._Range.setStartBefore( oNode ) ;
655
if ( oNode != oNode.parentNode.firstChild )
658
oNode = oNode.parentNode ;
663
// Expand the end boundary.
664
oNode = this._Range.endContainer ;
665
var offset = this._Range.endOffset ;
667
if ( ( oNode.nodeType == 3 && offset >= oNode.nodeValue.length ) || ( oNode.nodeType == 1 && offset >= oNode.childNodes.length ) || ( oNode.nodeType != 1 && oNode.nodeType != 3 ) )
669
if ( oNode.nodeType != 1 )
670
oNode = oNode.nextSibling ? null : oNode.parentNode ;
674
while ( FCKListsLib.InlineNonEmptyElements[ oNode.nodeName.toLowerCase() ] )
676
this._Range.setEndAfter( oNode ) ;
678
if ( oNode != oNode.parentNode.lastChild )
681
oNode = oNode.parentNode ;
688
case 'block_contents' :
689
case 'list_contents' :
690
var boundarySet = FCKListsLib.BlockBoundaries ;
691
if ( unit == 'list_contents' || FCKConfig.EnterMode == 'br' )
692
boundarySet = FCKListsLib.ListBoundaries ;
694
if ( this.StartBlock && FCKConfig.EnterMode != 'br' && unit == 'block_contents' )
695
this.SetStart( this.StartBlock, 1 ) ;
698
// Get the start node for the current range.
699
oNode = this._Range.startContainer ;
701
// If it is an element, get the node right before of it (in source order).
702
if ( oNode.nodeType == 1 )
704
var lastNode = oNode.childNodes[ this._Range.startOffset ] ;
706
oNode = FCKDomTools.GetPreviousSourceNode( lastNode, true ) ;
708
oNode = oNode.lastChild || oNode ;
711
// We must look for the left boundary, relative to the range
712
// start, which is limited by a block element.
714
&& ( oNode.nodeType != 1
715
|| ( oNode != this.StartBlockLimit
716
&& !boundarySet[ oNode.nodeName.toLowerCase() ] ) ) )
718
this._Range.setStartBefore( oNode ) ;
719
oNode = oNode.previousSibling || oNode.parentNode ;
723
if ( this.EndBlock && FCKConfig.EnterMode != 'br' && unit == 'block_contents' && this.EndBlock.nodeName.toLowerCase() != 'li' )
724
this.SetEnd( this.EndBlock, 2 ) ;
727
oNode = this._Range.endContainer ;
728
if ( oNode.nodeType == 1 )
729
oNode = oNode.childNodes[ this._Range.endOffset ] || oNode.lastChild ;
731
// We must look for the right boundary, relative to the range
732
// end, which is limited by a block element.
734
&& ( oNode.nodeType != 1
735
|| ( oNode != this.StartBlockLimit
736
&& !boundarySet[ oNode.nodeName.toLowerCase() ] ) ) )
738
this._Range.setEndAfter( oNode ) ;
739
oNode = oNode.nextSibling || oNode.parentNode ;
742
// In EnterMode='br', the end <br> boundary element must
743
// be included in the expanded range.
744
if ( oNode && oNode.nodeName.toLowerCase() == 'br' )
745
this._Range.setEndAfter( oNode ) ;
748
this._UpdateElementInfo() ;
753
* Split the block element for the current range. It deletes the contents
754
* of the range and splits the block in the collapsed position, resulting
755
* in two sucessive blocks. The range is then positioned in the middle of
758
* It returns and object with the following properties:
759
* - PreviousBlock : a reference to the block element that preceeds
760
* the range after the split.
761
* - NextBlock : a reference to the block element that follows the
762
* range after the split.
763
* - WasStartOfBlock : a boolean indicating that the range was
764
* originaly at the start of the block.
765
* - WasEndOfBlock : a boolean indicating that the range was originaly
766
* at the end of the block.
768
* If the range was originaly at the start of the block, no split will happen
769
* and the PreviousBlock value will be null. The same is valid for the
770
* NextBlock value if the range was at the end of the block.
772
SplitBlock : function( forceBlockTag )
774
var blockTag = forceBlockTag || FCKConfig.EnterMode ;
777
this.MoveToSelection() ;
779
// The range boundaries must be in the same "block limit" element.
780
if ( this.StartBlockLimit == this.EndBlockLimit )
782
// Get the current blocks.
783
var eStartBlock = this.StartBlock ;
784
var eEndBlock = this.EndBlock ;
785
var oElementPath = null ;
787
if ( blockTag != 'br' )
791
eStartBlock = this.FixBlock( true, blockTag ) ;
792
eEndBlock = this.EndBlock ; // FixBlock may have fixed the EndBlock too.
796
eEndBlock = this.FixBlock( false, blockTag ) ;
799
// Get the range position.
800
var bIsStartOfBlock = ( eStartBlock != null && this.CheckStartOfBlock() ) ;
801
var bIsEndOfBlock = ( eEndBlock != null && this.CheckEndOfBlock() ) ;
803
// Delete the current contents.
804
if ( !this.CheckIsEmpty() )
805
this.DeleteContents() ;
807
if ( eStartBlock && eEndBlock && eStartBlock == eEndBlock )
811
oElementPath = new FCKElementPath( this.StartContainer ) ;
812
this.MoveToPosition( eEndBlock, 4 ) ;
815
else if ( bIsStartOfBlock )
817
oElementPath = new FCKElementPath( this.StartContainer ) ;
818
this.MoveToPosition( eStartBlock, 3 ) ;
823
// Extract the contents of the block from the selection point to the end of its contents.
824
this.SetEnd( eStartBlock, 2 ) ;
825
var eDocFrag = this.ExtractContents() ;
827
// Duplicate the block element after it.
828
eEndBlock = eStartBlock.cloneNode( false ) ;
829
eEndBlock.removeAttribute( 'id', false ) ;
831
// Place the extracted contents in the duplicated block.
832
eDocFrag.AppendTo( eEndBlock ) ;
834
FCKDomTools.InsertAfterNode( eStartBlock, eEndBlock ) ;
836
this.MoveToPosition( eStartBlock, 4 ) ;
838
// In Gecko, the last child node must be a bogus <br>.
839
// Note: bogus <br> added under <ul> or <ol> would cause lists to be incorrectly rendered.
840
if ( FCKBrowserInfo.IsGecko &&
841
! eStartBlock.nodeName.IEquals( ['ul', 'ol'] ) )
842
FCKTools.AppendBogusBr( eStartBlock ) ;
847
PreviousBlock : eStartBlock,
848
NextBlock : eEndBlock,
849
WasStartOfBlock : bIsStartOfBlock,
850
WasEndOfBlock : bIsEndOfBlock,
851
ElementPath : oElementPath
858
// Transform a block without a block tag in a valid block (orphan text in the body or td, usually).
859
FixBlock : function( isStart, blockTag )
861
// Bookmark the range so we can restore it later.
862
var oBookmark = this.CreateBookmark() ;
864
// Collapse the range to the requested ending boundary.
865
this.Collapse( isStart ) ;
867
// Expands it to the block contents.
868
this.Expand( 'block_contents' ) ;
870
// Create the fixed block.
871
var oFixedBlock = this.Window.document.createElement( blockTag ) ;
873
// Move the contents of the temporary range to the fixed block.
874
this.ExtractContents().AppendTo( oFixedBlock ) ;
875
FCKDomTools.TrimNode( oFixedBlock ) ;
877
// If the fixed block is empty (not counting bookmark nodes)
878
// Add a <br /> inside to expand it.
879
if ( FCKDomTools.CheckIsEmptyElement(oFixedBlock, function( element ) { return element.getAttribute('_fck_bookmark') != 'true' ; } )
880
&& FCKBrowserInfo.IsGeckoLike )
881
FCKTools.AppendBogusBr( oFixedBlock ) ;
883
// Insert the fixed block into the DOM.
884
this.InsertNode( oFixedBlock ) ;
886
// Move the range back to the bookmarked place.
887
this.MoveToBookmark( oBookmark ) ;
892
Release : function( preserveWindow )
894
if ( !preserveWindow )
897
this.StartNode = null ;
898
this.StartContainer = null ;
899
this.StartBlock = null ;
900
this.StartBlockLimit = null ;
901
this.EndNode = null ;
902
this.EndContainer = null ;
903
this.EndBlock = null ;
904
this.EndBlockLimit = null ;
909
CheckHasRange : function()
911
return !!this._Range ;
914
GetTouchedStartNode : function()
916
var range = this._Range ;
917
var container = range.startContainer ;
919
if ( range.collapsed || container.nodeType != 1 )
922
return container.childNodes[ range.startOffset ] || container ;
925
GetTouchedEndNode : function()
927
var range = this._Range ;
928
var container = range.endContainer ;
930
if ( range.collapsed || container.nodeType != 1 )
933
return container.childNodes[ range.endOffset - 1 ] || container ;