2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2010 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
* Utility functions to work with the DOM.
27
* Move all child nodes from one node to another.
29
MoveChildren : function( source, target, toTargetStart )
31
if ( source == target )
38
while ( (eChild = source.lastChild) )
39
target.insertBefore( source.removeChild( eChild ), target.firstChild ) ;
43
while ( (eChild = source.firstChild) )
44
target.appendChild( source.removeChild( eChild ) ) ;
48
MoveNode : function( source, target, toTargetStart )
51
target.insertBefore( FCKDomTools.RemoveNode( source ), target.firstChild ) ;
53
target.appendChild( FCKDomTools.RemoveNode( source ) ) ;
56
// Remove blank spaces from the beginning and the end of the contents of a node.
57
TrimNode : function( node )
59
this.LTrimNode( node ) ;
60
this.RTrimNode( node ) ;
63
LTrimNode : function( node )
67
while ( (eChildNode = node.firstChild) )
69
if ( eChildNode.nodeType == 3 )
71
var sTrimmed = eChildNode.nodeValue.LTrim() ;
72
var iOriginalLength = eChildNode.nodeValue.length ;
74
if ( sTrimmed.length == 0 )
76
node.removeChild( eChildNode ) ;
79
else if ( sTrimmed.length < iOriginalLength )
81
eChildNode.splitText( iOriginalLength - sTrimmed.length ) ;
82
node.removeChild( node.firstChild ) ;
89
RTrimNode : function( node )
93
while ( (eChildNode = node.lastChild) )
95
if ( eChildNode.nodeType == 3 )
97
var sTrimmed = eChildNode.nodeValue.RTrim() ;
98
var iOriginalLength = eChildNode.nodeValue.length ;
100
if ( sTrimmed.length == 0 )
102
// If the trimmed text node is empty, just remove it.
104
// Use "eChildNode.parentNode" instead of "node" to avoid IE bug (#81).
105
eChildNode.parentNode.removeChild( eChildNode ) ;
108
else if ( sTrimmed.length < iOriginalLength )
110
// If the trimmed text length is less than the original
111
// length, strip all spaces from the end by splitting
112
// the text and removing the resulting useless node.
114
eChildNode.splitText( sTrimmed.length ) ;
115
// Use "node.lastChild.parentNode" instead of "node" to avoid IE bug (#81).
116
node.lastChild.parentNode.removeChild( node.lastChild ) ;
122
if ( !FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsOpera )
124
eChildNode = node.lastChild ;
126
if ( eChildNode && eChildNode.nodeType == 1 && eChildNode.nodeName.toLowerCase() == 'br' )
128
// Use "eChildNode.parentNode" instead of "node" to avoid IE bug (#324).
129
eChildNode.parentNode.removeChild( eChildNode ) ;
134
RemoveNode : function( node, excludeChildren )
136
if ( excludeChildren )
138
// Move all children before the node.
140
while ( (eChild = node.firstChild) )
141
node.parentNode.insertBefore( node.removeChild( eChild ), node ) ;
144
return node.parentNode.removeChild( node ) ;
147
GetFirstChild : function( node, childNames )
149
// If childNames is a string, transform it in a Array.
150
if ( typeof ( childNames ) == 'string' )
151
childNames = [ childNames ] ;
153
var eChild = node.firstChild ;
156
if ( eChild.nodeType == 1 && eChild.tagName.Equals.apply( eChild.tagName, childNames ) )
159
eChild = eChild.nextSibling ;
165
GetLastChild : function( node, childNames )
167
// If childNames is a string, transform it in a Array.
168
if ( typeof ( childNames ) == 'string' )
169
childNames = [ childNames ] ;
171
var eChild = node.lastChild ;
174
if ( eChild.nodeType == 1 && ( !childNames || eChild.tagName.Equals( childNames ) ) )
177
eChild = eChild.previousSibling ;
184
* Gets the previous element (nodeType=1) in the source order. Returns
185
* "null" If no element is found.
186
* @param {Object} currentNode The node to start searching from.
187
* @param {Boolean} ignoreSpaceTextOnly Sets how text nodes will be
188
* handled. If set to "true", only white spaces text nodes
189
* will be ignored, while non white space text nodes will stop
190
* the search, returning null. If "false" or omitted, all
191
* text nodes are ignored.
192
* @param {string[]} stopSearchElements An array of element names that
193
* will cause the search to stop when found, returning null.
194
* May be omitted (or null).
195
* @param {string[]} ignoreElements An array of element names that
196
* must be ignored during the search.
198
GetPreviousSourceElement : function( currentNode, ignoreSpaceTextOnly, stopSearchElements, ignoreElements )
203
if ( stopSearchElements && currentNode.nodeType == 1 && currentNode.nodeName.IEquals( stopSearchElements ) )
206
if ( currentNode.previousSibling )
207
currentNode = currentNode.previousSibling ;
209
return this.GetPreviousSourceElement( currentNode.parentNode, ignoreSpaceTextOnly, stopSearchElements, ignoreElements ) ;
211
while ( currentNode )
213
if ( currentNode.nodeType == 1 )
215
if ( stopSearchElements && currentNode.nodeName.IEquals( stopSearchElements ) )
218
if ( !ignoreElements || !currentNode.nodeName.IEquals( ignoreElements ) )
221
else if ( ignoreSpaceTextOnly && currentNode.nodeType == 3 && currentNode.nodeValue.RTrim().length > 0 )
224
if ( currentNode.lastChild )
225
currentNode = currentNode.lastChild ;
227
return this.GetPreviousSourceElement( currentNode, ignoreSpaceTextOnly, stopSearchElements, ignoreElements ) ;
234
* Gets the next element (nodeType=1) in the source order. Returns
235
* "null" If no element is found.
236
* @param {Object} currentNode The node to start searching from.
237
* @param {Boolean} ignoreSpaceTextOnly Sets how text nodes will be
238
* handled. If set to "true", only white spaces text nodes
239
* will be ignored, while non white space text nodes will stop
240
* the search, returning null. If "false" or omitted, all
241
* text nodes are ignored.
242
* @param {string[]} stopSearchElements An array of element names that
243
* will cause the search to stop when found, returning null.
244
* May be omitted (or null).
245
* @param {string[]} ignoreElements An array of element names that
246
* must be ignored during the search.
248
GetNextSourceElement : function( currentNode, ignoreSpaceTextOnly, stopSearchElements, ignoreElements, startFromSibling )
250
while( ( currentNode = this.GetNextSourceNode( currentNode, startFromSibling ) ) ) // Only one "=".
252
if ( currentNode.nodeType == 1 )
254
if ( stopSearchElements && currentNode.nodeName.IEquals( stopSearchElements ) )
257
if ( ignoreElements && currentNode.nodeName.IEquals( ignoreElements ) )
258
return this.GetNextSourceElement( currentNode, ignoreSpaceTextOnly, stopSearchElements, ignoreElements ) ;
262
else if ( ignoreSpaceTextOnly && currentNode.nodeType == 3 && currentNode.nodeValue.RTrim().length > 0 )
270
* Get the next DOM node available in source order.
272
GetNextSourceNode : function( currentNode, startFromSibling, nodeType, stopSearchNode )
279
if ( !startFromSibling && currentNode.firstChild )
280
node = currentNode.firstChild ;
283
if ( stopSearchNode && currentNode == stopSearchNode )
286
node = currentNode.nextSibling ;
288
if ( !node && ( !stopSearchNode || stopSearchNode != currentNode.parentNode ) )
289
return this.GetNextSourceNode( currentNode.parentNode, true, nodeType, stopSearchNode ) ;
292
if ( nodeType && node && node.nodeType != nodeType )
293
return this.GetNextSourceNode( node, false, nodeType, stopSearchNode ) ;
299
* Get the next DOM node available in source order.
301
GetPreviousSourceNode : function( currentNode, startFromSibling, nodeType, stopSearchNode )
308
if ( !startFromSibling && currentNode.lastChild )
309
node = currentNode.lastChild ;
312
if ( stopSearchNode && currentNode == stopSearchNode )
315
node = currentNode.previousSibling ;
317
if ( !node && ( !stopSearchNode || stopSearchNode != currentNode.parentNode ) )
318
return this.GetPreviousSourceNode( currentNode.parentNode, true, nodeType, stopSearchNode ) ;
321
if ( nodeType && node && node.nodeType != nodeType )
322
return this.GetPreviousSourceNode( node, false, nodeType, stopSearchNode ) ;
327
// Inserts a element after a existing one.
328
InsertAfterNode : function( existingNode, newNode )
330
return existingNode.parentNode.insertBefore( newNode, existingNode.nextSibling ) ;
333
GetParents : function( node )
335
var parents = new Array() ;
339
parents.unshift( node ) ;
340
node = node.parentNode ;
346
GetCommonParents : function( node1, node2 )
348
var p1 = this.GetParents( node1 ) ;
349
var p2 = this.GetParents( node2 ) ;
351
for ( var i = 0 ; i < p1.length ; i++ )
353
if ( p1[i] == p2[i] )
354
retval.push( p1[i] ) ;
359
GetCommonParentNode : function( node1, node2, tagList )
363
tagList = [ tagList ] ;
364
while ( tagList.length > 0 )
365
tagMap[tagList.pop().toLowerCase()] = 1 ;
367
var commonParents = this.GetCommonParents( node1, node2 ) ;
368
var currentParent = null ;
369
while ( ( currentParent = commonParents.pop() ) )
371
if ( tagMap[currentParent.nodeName.toLowerCase()] )
372
return currentParent ;
377
GetIndexOf : function( node )
379
var currentNode = node.parentNode ? node.parentNode.firstChild : null ;
380
var currentIndex = -1 ;
382
while ( currentNode )
386
if ( currentNode == node )
387
return currentIndex ;
389
currentNode = currentNode.nextSibling ;
397
EnforcePaddingNode : function( doc, tagName )
399
// In IE it can happen when the page is reloaded that doc or doc.body is null, so exit here
402
if ( !doc || !doc.body )
410
this.CheckAndRemovePaddingNode( doc, tagName, true ) ;
413
if ( doc.body.lastChild && ( doc.body.lastChild.nodeType != 1
414
|| doc.body.lastChild.tagName.toLowerCase() == tagName.toLowerCase() ) )
422
var node = doc.createElement( tagName ) ;
423
if ( FCKBrowserInfo.IsGecko && FCKListsLib.NonEmptyBlockElements[ tagName ] )
424
FCKTools.AppendBogusBr( node ) ;
425
this.PaddingNode = node ;
426
if ( doc.body.childNodes.length == 1
427
&& doc.body.firstChild.nodeType == 1
428
&& doc.body.firstChild.tagName.toLowerCase() == 'br'
429
&& ( doc.body.firstChild.getAttribute( '_moz_dirty' ) != null
430
|| doc.body.firstChild.getAttribute( 'type' ) == '_moz' ) )
431
doc.body.replaceChild( node, doc.body.firstChild ) ;
433
doc.body.appendChild( node ) ;
436
CheckAndRemovePaddingNode : function( doc, tagName, dontRemove )
438
var paddingNode = this.PaddingNode ;
442
// If the padding node is changed, remove its status as a padding node.
445
if ( paddingNode.parentNode != doc.body
446
|| paddingNode.tagName.toLowerCase() != tagName
447
|| ( paddingNode.childNodes.length > 1 )
448
|| ( paddingNode.firstChild && paddingNode.firstChild.nodeValue != '\xa0'
449
&& String(paddingNode.firstChild.tagName).toLowerCase() != 'br' ) )
451
this.PaddingNode = null ;
457
this.PaddingNode = null ;
461
// Now we're sure the padding node exists, and it is unchanged, and it
462
// isn't the only node in doc.body, remove it.
465
if ( paddingNode.parentNode.childNodes.length > 1 )
466
paddingNode.parentNode.removeChild( paddingNode ) ;
467
this.PaddingNode = null ;
471
HasAttribute : function( element, attributeName )
473
if ( element.hasAttribute )
474
return element.hasAttribute( attributeName ) ;
477
var att = element.attributes[ attributeName ] ;
478
return ( att != undefined && att.specified ) ;
483
* Checks if an element has "specified" attributes.
485
HasAttributes : function( element )
487
var attributes = element.attributes ;
489
for ( var i = 0 ; i < attributes.length ; i++ )
491
if ( FCKBrowserInfo.IsIE )
493
var attributeNodeName = attributes[i].nodeName ;
495
if ( attributeNodeName.StartsWith( '_fck' ) )
498
* There are places in the FCKeditor code where HTML element objects
499
* get values stored as properties (e.g. _fckxhtmljob). In Internet
500
* Explorer, these are interpreted as attempts to set attributes on
503
* http://msdn.microsoft.com/en-us/library/ms533026(VS.85).aspx#Accessing_Element_Pr
505
* Counting these as HTML attributes cripples
506
* FCK.Style.RemoveFromRange() once FCK.GetData() has been called.
508
* The above conditional prevents these internal properties being
509
* counted as attributes.
511
* refs #2156 and #2834
517
if ( attributeNodeName == 'class' )
519
// IE has a strange bug. If calling removeAttribute('className'),
520
// the attributes collection will still contain the "class"
521
// attribute, which will be marked as "specified", even if the
522
// outerHTML of the element is not displaying the class attribute.
523
// Note : I was not able to reproduce it outside the editor,
524
// but I've faced it while working on the TC of #1391.
525
if ( element.className.length > 0 )
530
if ( attributes[i].specified )
538
* Remove an attribute from an element.
540
RemoveAttribute : function( element, attributeName )
542
if ( FCKBrowserInfo.IsIE && attributeName.toLowerCase() == 'class' )
543
attributeName = 'className' ;
545
return element.removeAttribute( attributeName, 0 ) ;
549
* Removes an array of attributes from an element
551
RemoveAttributes : function (element, aAttributes )
553
for ( var i = 0 ; i < aAttributes.length ; i++ )
554
this.RemoveAttribute( element, aAttributes[i] );
557
GetAttributeValue : function( element, att )
561
if ( typeof att == 'string' )
562
att = element.attributes[ att ] ;
564
attName = att.nodeName ;
566
if ( att && att.specified )
568
// IE returns "null" for the nodeValue of a "style" attribute.
569
if ( attName == 'style' )
570
return element.style.cssText ;
571
// There are two cases when the nodeValue must be used:
572
// - for the "class" attribute (all browsers).
573
// - for events attributes (IE only).
574
else if ( attName == 'class' || attName.indexOf('on') == 0 )
575
return att.nodeValue ;
578
// Use getAttribute to get its value exactly as it is
580
return element.getAttribute( attName, 2 ) ;
587
* Checks whether one element contains the other.
589
Contains : function( mainElement, otherElement )
591
// IE supports contains, but only for element nodes.
592
if ( mainElement.contains && otherElement.nodeType == 1 )
593
return mainElement.contains( otherElement ) ;
595
while ( ( otherElement = otherElement.parentNode ) ) // Only one "="
597
if ( otherElement == mainElement )
604
* Breaks a parent element in the position of one of its contained elements.
605
* For example, in the following case:
606
* <b>This <i>is some<span /> sample</i> test text</b>
607
* If element = <span />, we have these results:
608
* <b>This <i>is some</i><span /><i> sample</i> test text</b> (If parent = <i>)
609
* <b>This <i>is some</i></b><span /><b><i> sample</i> test text</b> (If parent = <b>)
611
BreakParent : function( element, parent, reusableRange )
613
var range = reusableRange || new FCKDomRange( FCKTools.GetElementWindow( element ) ) ;
615
// We'll be extracting part of this element, so let's use our
616
// range to get the correct piece.
617
range.SetStart( element, 4 ) ;
618
range.SetEnd( parent, 4 ) ;
621
var docFrag = range.ExtractContents() ;
623
// Move the element outside the broken element.
624
range.InsertNode( element.parentNode.removeChild( element ) ) ;
626
// Re-insert the extracted piece after the element.
627
docFrag.InsertAfterNode( element ) ;
629
range.Release( !!reusableRange ) ;
633
* Retrieves a uniquely identifiable tree address of a DOM tree node.
634
* The tree address returns is an array of integers, with each integer
635
* indicating a child index from a DOM tree node, starting from
636
* document.documentElement.
638
* For example, assuming <body> is the second child from <html> (<head>
639
* being the first), and we'd like to address the third child under the
640
* fourth child of body, the tree address returned would be:
643
* The tree address cannot be used for finding back the DOM tree node once
644
* the DOM tree structure has been modified.
646
GetNodeAddress : function( node, normalized )
649
while ( node && node != FCKTools.GetElementDocument( node ).documentElement )
651
var parentNode = node.parentNode ;
652
var currentIndex = -1 ;
653
for( var i = 0 ; i < parentNode.childNodes.length ; i++ )
655
var candidate = parentNode.childNodes[i] ;
656
if ( normalized === true &&
657
candidate.nodeType == 3 &&
658
candidate.previousSibling &&
659
candidate.previousSibling.nodeType == 3 )
662
if ( parentNode.childNodes[i] == node )
665
retval.unshift( currentIndex ) ;
666
node = node.parentNode ;
672
* The reverse transformation of FCKDomTools.GetNodeAddress(). This
673
* function returns the DOM node pointed to by its index address.
675
GetNodeFromAddress : function( doc, addr, normalized )
677
var cursor = doc.documentElement ;
678
for ( var i = 0 ; i < addr.length ; i++ )
680
var target = addr[i] ;
683
cursor = cursor.childNodes[target] ;
687
var currentIndex = -1 ;
688
for (var j = 0 ; j < cursor.childNodes.length ; j++ )
690
var candidate = cursor.childNodes[j] ;
691
if ( normalized === true &&
692
candidate.nodeType == 3 &&
693
candidate.previousSibling &&
694
candidate.previousSibling.nodeType == 3 )
697
if ( currentIndex == target )
707
CloneElement : function( element )
709
element = element.cloneNode( false ) ;
711
// The "id" attribute should never be cloned to avoid duplication.
712
element.removeAttribute( 'id', false ) ;
717
ClearElementJSProperty : function( element, attrName )
719
if ( FCKBrowserInfo.IsIE )
720
element.removeAttribute( attrName ) ;
722
delete element[attrName] ;
725
SetElementMarker : function ( markerObj, element, attrName, value)
727
var id = String( parseInt( Math.random() * 0xffffffff, 10 ) ) ;
728
element._FCKMarkerId = id ;
729
element[attrName] = value ;
730
if ( ! markerObj[id] )
731
markerObj[id] = { 'element' : element, 'markers' : {} } ;
732
markerObj[id]['markers'][attrName] = value ;
735
ClearElementMarkers : function( markerObj, element, clearMarkerObj )
737
var id = element._FCKMarkerId ;
740
this.ClearElementJSProperty( element, '_FCKMarkerId' ) ;
741
for ( var j in markerObj[id]['markers'] )
742
this.ClearElementJSProperty( element, j ) ;
743
if ( clearMarkerObj )
744
delete markerObj[id] ;
747
ClearAllMarkers : function( markerObj )
749
for ( var i in markerObj )
750
this.ClearElementMarkers( markerObj, markerObj[i]['element'], true ) ;
754
* Convert a DOM list tree into a data structure that is easier to
755
* manipulate. This operation should be non-intrusive in the sense that it
756
* does not change the DOM tree, with the exception that it may add some
757
* markers to the list item nodes when markerObj is specified.
759
ListToArray : function( listNode, markerObj, baseArray, baseIndentLevel, grandparentNode )
761
if ( ! listNode.nodeName.IEquals( ['ul', 'ol'] ) )
764
if ( ! baseIndentLevel )
765
baseIndentLevel = 0 ;
768
// Iterate over all list items to get their contents and look for inner lists.
769
for ( var i = 0 ; i < listNode.childNodes.length ; i++ )
771
var listItem = listNode.childNodes[i] ;
772
if ( ! listItem.nodeName.IEquals( 'li' ) )
774
var itemObj = { 'parent' : listNode, 'indent' : baseIndentLevel, 'contents' : [] } ;
775
if ( ! grandparentNode )
777
itemObj.grandparent = listNode.parentNode ;
778
if ( itemObj.grandparent && itemObj.grandparent.nodeName.IEquals( 'li' ) )
779
itemObj.grandparent = itemObj.grandparent.parentNode ;
782
itemObj.grandparent = grandparentNode ;
784
this.SetElementMarker( markerObj, listItem, '_FCK_ListArray_Index', baseArray.length ) ;
785
baseArray.push( itemObj ) ;
786
for ( var j = 0 ; j < listItem.childNodes.length ; j++ )
788
var child = listItem.childNodes[j] ;
789
if ( child.nodeName.IEquals( ['ul', 'ol'] ) )
790
// Note the recursion here, it pushes inner list items with
791
// +1 indentation in the correct order.
792
this.ListToArray( child, markerObj, baseArray, baseIndentLevel + 1, itemObj.grandparent ) ;
794
itemObj.contents.push( child ) ;
800
// Convert our internal representation of a list back to a DOM forest.
801
ArrayToList : function( listArray, markerObj, baseIndex )
803
if ( baseIndex == undefined )
805
if ( ! listArray || listArray.length < baseIndex + 1 )
807
var doc = FCKTools.GetElementDocument( listArray[baseIndex].parent ) ;
808
var retval = doc.createDocumentFragment() ;
809
var rootNode = null ;
810
var currentIndex = baseIndex ;
811
var indentLevel = Math.max( listArray[baseIndex].indent, 0 ) ;
812
var currentListItem = null ;
815
var item = listArray[currentIndex] ;
816
if ( item.indent == indentLevel )
818
if ( ! rootNode || listArray[currentIndex].parent.nodeName != rootNode.nodeName )
820
rootNode = listArray[currentIndex].parent.cloneNode( false ) ;
821
retval.appendChild( rootNode ) ;
823
currentListItem = doc.createElement( 'li' ) ;
824
rootNode.appendChild( currentListItem ) ;
825
for ( var i = 0 ; i < item.contents.length ; i++ )
826
currentListItem.appendChild( item.contents[i].cloneNode( true ) ) ;
829
else if ( item.indent == Math.max( indentLevel, 0 ) + 1 )
831
var listData = this.ArrayToList( listArray, null, currentIndex ) ;
832
currentListItem.appendChild( listData.listNode ) ;
833
currentIndex = listData.nextIndex ;
835
else if ( item.indent == -1 && baseIndex == 0 && item.grandparent )
837
var currentListItem ;
838
if ( item.grandparent.nodeName.IEquals( ['ul', 'ol'] ) )
839
currentListItem = doc.createElement( 'li' ) ;
842
if ( FCKConfig.EnterMode.IEquals( ['div', 'p'] ) && ! item.grandparent.nodeName.IEquals( 'td' ) )
843
currentListItem = doc.createElement( FCKConfig.EnterMode ) ;
845
currentListItem = doc.createDocumentFragment() ;
847
for ( var i = 0 ; i < item.contents.length ; i++ )
848
currentListItem.appendChild( item.contents[i].cloneNode( true ) ) ;
849
if ( currentListItem.nodeType == 11 )
851
if ( currentListItem.lastChild &&
852
currentListItem.lastChild.getAttribute &&
853
currentListItem.lastChild.getAttribute( 'type' ) == '_moz' )
854
currentListItem.removeChild( currentListItem.lastChild );
855
currentListItem.appendChild( doc.createElement( 'br' ) ) ;
857
if ( currentListItem.nodeName.IEquals( FCKConfig.EnterMode ) && currentListItem.firstChild )
859
this.TrimNode( currentListItem ) ;
860
if ( FCKListsLib.BlockBoundaries[currentListItem.firstChild.nodeName.toLowerCase()] )
862
var tmp = doc.createDocumentFragment() ;
863
while ( currentListItem.firstChild )
864
tmp.appendChild( currentListItem.removeChild( currentListItem.firstChild ) ) ;
865
currentListItem = tmp ;
868
if ( FCKBrowserInfo.IsGeckoLike && currentListItem.nodeName.IEquals( ['div', 'p'] ) )
869
FCKTools.AppendBogusBr( currentListItem ) ;
870
retval.appendChild( currentListItem ) ;
877
if ( listArray.length <= currentIndex || Math.max( listArray[currentIndex].indent, 0 ) < indentLevel )
883
// Clear marker attributes for the new list tree made of cloned nodes, if any.
886
var currentNode = retval.firstChild ;
887
while ( currentNode )
889
if ( currentNode.nodeType == 1 )
890
this.ClearElementMarkers( markerObj, currentNode ) ;
891
currentNode = this.GetNextSourceNode( currentNode ) ;
895
return { 'listNode' : retval, 'nextIndex' : currentIndex } ;
899
* Get the next sibling node for a node. If "includeEmpties" is false,
900
* only element or non empty text nodes are returned.
902
GetNextSibling : function( node, includeEmpties )
904
node = node.nextSibling ;
906
while ( node && !includeEmpties && node.nodeType != 1 && ( node.nodeType != 3 || node.nodeValue.length == 0 ) )
907
node = node.nextSibling ;
913
* Get the previous sibling node for a node. If "includeEmpties" is false,
914
* only element or non empty text nodes are returned.
916
GetPreviousSibling : function( node, includeEmpties )
918
node = node.previousSibling ;
920
while ( node && !includeEmpties && node.nodeType != 1 && ( node.nodeType != 3 || node.nodeValue.length == 0 ) )
921
node = node.previousSibling ;
927
* Checks if an element has no "useful" content inside of it
928
* node tree. No "useful" content means empty text node or a signle empty
930
* elementCheckCallback may point to a function that returns a boolean
931
* indicating that a child element must be considered in the element check.
933
CheckIsEmptyElement : function( element, elementCheckCallback )
935
var child = element.firstChild ;
940
if ( child.nodeType == 1 )
942
if ( elementChild || !FCKListsLib.InlineNonEmptyElements[ child.nodeName.toLowerCase() ] )
945
if ( !elementCheckCallback || elementCheckCallback( child ) === true )
946
elementChild = child ;
948
else if ( child.nodeType == 3 && child.nodeValue.length > 0 )
951
child = child.nextSibling ;
954
return elementChild ? this.CheckIsEmptyElement( elementChild, elementCheckCallback ) : true ;
957
SetElementStyles : function( element, styleDict )
959
var style = element.style ;
960
for ( var styleName in styleDict )
961
style[ styleName ] = styleDict[ styleName ] ;
964
SetOpacity : function( element, opacity )
966
if ( FCKBrowserInfo.IsIE )
968
opacity = Math.round( opacity * 100 ) ;
969
element.style.filter = ( opacity > 100 ? '' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')' ) ;
972
element.style.opacity = opacity ;
975
GetCurrentElementStyle : function( element, propertyName )
977
if ( FCKBrowserInfo.IsIE )
978
return element.currentStyle[ propertyName ] ;
980
return element.ownerDocument.defaultView.getComputedStyle( element, '' ).getPropertyValue( propertyName ) ;
983
GetPositionedAncestor : function( element )
985
var currentElement = element ;
987
while ( currentElement != FCKTools.GetElementDocument( currentElement ).documentElement )
989
if ( this.GetCurrentElementStyle( currentElement, 'position' ) != 'static' )
990
return currentElement ;
992
if ( currentElement == FCKTools.GetElementDocument( currentElement ).documentElement
993
&& currentWindow != w )
994
currentElement = currentWindow.frameElement ;
996
currentElement = currentElement.parentNode ;
1003
* Current implementation for ScrollIntoView (due to #1462 and #2279). We
1004
* don't have a complete implementation here, just the things that fit our
1007
ScrollIntoView : function( element, alignTop )
1009
// Get the element window.
1010
var window = FCKTools.GetElementWindow( element ) ;
1011
var windowHeight = FCKTools.GetViewPaneSize( window ).Height ;
1013
// Starts the offset that will be scrolled with the negative value of
1014
// the visible window height.
1015
var offset = windowHeight * -1 ;
1017
// Appends the height it we are about to align the bottoms.
1018
if ( alignTop === false )
1020
offset += element.offsetHeight || 0 ;
1022
// Consider the margin in the scroll, which is ok for our current
1023
// needs, but needs investigation if we will be using this function
1025
offset += parseInt( this.GetCurrentElementStyle( element, 'marginBottom' ) || 0, 10 ) || 0 ;
1028
// Appends the offsets for the entire element hierarchy.
1029
var elementPosition = FCKTools.GetDocumentPosition( window, element ) ;
1030
offset += elementPosition.y ;
1032
// Scroll the window to the desired position, if not already visible.
1033
var currentScroll = FCKTools.GetScrollPosition( window ).Y ;
1034
if ( offset > 0 && ( offset > currentScroll || offset < currentScroll - windowHeight ) )
1035
window.scrollTo( 0, offset ) ;
1039
* Check if the element can be edited inside the browser.
1041
CheckIsEditable : function( element )
1043
// Get the element name.
1044
var nodeName = element.nodeName.toLowerCase() ;
1046
// Get the element DTD (defaults to span for unknown elements).
1047
var childDTD = FCK.DTD[ nodeName ] || FCK.DTD.span ;
1049
// In the DTD # == text node.
1050
return ( childDTD['#'] && !FCKListsLib.NonEditableElements[ nodeName ] ) ;
1053
GetSelectedDivContainers : function()
1055
var currentBlocks = [] ;
1056
var range = new FCKDomRange( FCK.EditorWindow ) ;
1057
range.MoveToSelection() ;
1059
var startNode = range.GetTouchedStartNode() ;
1060
var endNode = range.GetTouchedEndNode() ;
1061
var currentNode = startNode ;
1063
if ( startNode == endNode )
1065
while ( endNode.nodeType == 1 && endNode.lastChild )
1066
endNode = endNode.lastChild ;
1067
endNode = FCKDomTools.GetNextSourceNode( endNode ) ;
1070
while ( currentNode && currentNode != endNode )
1072
if ( currentNode.nodeType != 3 || !/^[ \t\n]*$/.test( currentNode.nodeValue ) )
1074
var path = new FCKElementPath( currentNode ) ;
1075
var blockLimit = path.BlockLimit ;
1076
if ( blockLimit && blockLimit.nodeName.IEquals( 'div' ) && currentBlocks.IndexOf( blockLimit ) == -1 )
1077
currentBlocks.push( blockLimit ) ;
1080
currentNode = FCKDomTools.GetNextSourceNode( currentNode ) ;
1083
return currentBlocks ;