Вход Регистрация
Файл: fckeditor/editor/_source/internals/fckdomtools.js
Строк: 1542
<?php

/*
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * Utility functions to work with the DOM.
 */

var FCKDomTools =
{
    
/**
     * Move all child nodes from one node to another.
     */
    
MoveChildren : function( sourcetargettoTargetStart )
    {
        if ( 
source == target )
            return ;

        var 
eChild ;

        if ( 
toTargetStart )
        {
            while ( (
eChild source.lastChild) )
                
target.insertBeforesource.removeChildeChild ), target.firstChild ) ;
        }
        else
        {
            while ( (
eChild source.firstChild) )
                
target.appendChildsource.removeChildeChild ) ) ;
        }
    },

    
MoveNode : function( sourcetargettoTargetStart )
    {
        if ( 
toTargetStart )
            
target.insertBeforeFCKDomTools.RemoveNodesource ), target.firstChild ) ;
        else
            
target.appendChildFCKDomTools.RemoveNodesource ) ) ;
    },

    
// Remove blank spaces from the beginning and the end of the contents of a node.
    
TrimNode : function( node )
    {
        
this.LTrimNodenode ) ;
        
this.RTrimNodenode ) ;
    },

    
LTrimNode : function( node )
    {
        var 
eChildNode ;

        while ( (
eChildNode node.firstChild) )
        {
            if ( 
eChildNode.nodeType == )
            {
                var 
sTrimmed eChildNode.nodeValue.LTrim() ;
                var 
iOriginalLength eChildNode.nodeValue.length ;

                if ( 
sTrimmed.length == )
                {
                    
node.removeChildeChildNode ) ;
                    continue ;
                }
                else if ( 
sTrimmed.length iOriginalLength )
                {
                    
eChildNode.splitTextiOriginalLength sTrimmed.length ) ;
                    
node.removeChildnode.firstChild ) ;
                }
            }
            break ;
        }
    },

    
RTrimNode : function( node )
    {
        var 
eChildNode ;

        while ( (
eChildNode node.lastChild) )
        {
            if ( 
eChildNode.nodeType == )
            {
                var 
sTrimmed eChildNode.nodeValue.RTrim() ;
                var 
iOriginalLength eChildNode.nodeValue.length ;

                if ( 
sTrimmed.length == )
                {
                    
// If the trimmed text node is empty, just remove it.

                    // Use "eChildNode.parentNode" instead of "node" to avoid IE bug (#81).
                    
eChildNode.parentNode.removeChildeChildNode ) ;
                    continue ;
                }
                else if ( 
sTrimmed.length iOriginalLength )
                {
                    
// If the trimmed text length is less than the original
                    // length, strip all spaces from the end by splitting
                    // the text and removing the resulting useless node.

                    
eChildNode.splitTextsTrimmed.length ) ;
                    
// Use "node.lastChild.parentNode" instead of "node" to avoid IE bug (#81).
                    
node.lastChild.parentNode.removeChildnode.lastChild ) ;
                }
            }
            break ;
        }

        if ( !
FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsOpera )
        {
            
eChildNode node.lastChild ;

            if ( 
eChildNode && eChildNode.nodeType == && eChildNode.nodeName.toLowerCase() == 'br' )
            {
                
// Use "eChildNode.parentNode" instead of "node" to avoid IE bug (#324).
                
eChildNode.parentNode.removeChildeChildNode ) ;
            }
        }
    },

    
RemoveNode : function( nodeexcludeChildren )
    {
        if ( 
excludeChildren )
        {
            
// Move all children before the node.
            
var eChild ;
            while ( (
eChild node.firstChild) )
                
node.parentNode.insertBeforenode.removeChildeChild ), node ) ;
        }

        return 
node.parentNode.removeChildnode ) ;
    },

    
GetFirstChild : function( nodechildNames )
    {
        
// If childNames is a string, transform it in a Array.
        
if ( typeof childNames ) == 'string' )
            
childNames = [ childNames ] ;

        var 
eChild node.firstChild ;
        while( 
eChild )
        {
            if ( 
eChild.nodeType == && eChild.tagName.Equals.applyeChild.tagNamechildNames ) )
                return 
eChild ;

            
eChild eChild.nextSibling ;
        }

        return 
null ;
    },

    
GetLastChild : function( nodechildNames )
    {
        
// If childNames is a string, transform it in a Array.
        
if ( typeof childNames ) == 'string' )
            
childNames = [ childNames ] ;

        var 
eChild node.lastChild ;
        while( 
eChild )
        {
            if ( 
eChild.nodeType == && ( !childNames || eChild.tagName.EqualschildNames ) ) )
                return 
eChild ;

            
eChild eChild.previousSibling ;
        }

        return 
null ;
    },

    
/*
     * Gets the previous element (nodeType=1) in the source order. Returns
     * "null" If no element is found.
     *        @param {Object} currentNode The node to start searching from.
     *        @param {Boolean} ignoreSpaceTextOnly Sets how text nodes will be
     *                handled. If set to "true", only white spaces text nodes
     *                will be ignored, while non white space text nodes will stop
     *                the search, returning null. If "false" or omitted, all
     *                text nodes are ignored.
     *        @param {string[]} stopSearchElements An array of element names that
     *                will cause the search to stop when found, returning null.
     *                May be omitted (or null).
     *        @param {string[]} ignoreElements An array of element names that
     *                must be ignored during the search.
     */
    
GetPreviousSourceElement : function( currentNodeignoreSpaceTextOnlystopSearchElementsignoreElements )
    {
        if ( !
currentNode )
            return 
null ;

        if ( 
stopSearchElements && currentNode.nodeType == && currentNode.nodeName.IEqualsstopSearchElements ) )
            return 
null ;

        if ( 
currentNode.previousSibling )
            
currentNode currentNode.previousSibling ;
        else
            return 
this.GetPreviousSourceElementcurrentNode.parentNodeignoreSpaceTextOnlystopSearchElementsignoreElements ) ;

        while ( 
currentNode )
        {
            if ( 
currentNode.nodeType == )
            {
                if ( 
stopSearchElements && currentNode.nodeName.IEqualsstopSearchElements ) )
                    break ;

                if ( !
ignoreElements || !currentNode.nodeName.IEqualsignoreElements ) )
                    return 
currentNode ;
            }
            else if ( 
ignoreSpaceTextOnly && currentNode.nodeType == && currentNode.nodeValue.RTrim().length )
                break ;

            if ( 
currentNode.lastChild )
                
currentNode currentNode.lastChild ;
            else
                return 
this.GetPreviousSourceElementcurrentNodeignoreSpaceTextOnlystopSearchElementsignoreElements ) ;
        }

        return 
null ;
    },

    
/*
     * Gets the next element (nodeType=1) in the source order. Returns
     * "null" If no element is found.
     *        @param {Object} currentNode The node to start searching from.
     *        @param {Boolean} ignoreSpaceTextOnly Sets how text nodes will be
     *                handled. If set to "true", only white spaces text nodes
     *                will be ignored, while non white space text nodes will stop
     *                the search, returning null. If "false" or omitted, all
     *                text nodes are ignored.
     *        @param {string[]} stopSearchElements An array of element names that
     *                will cause the search to stop when found, returning null.
     *                May be omitted (or null).
     *        @param {string[]} ignoreElements An array of element names that
     *                must be ignored during the search.
     */
    
GetNextSourceElement : function( currentNodeignoreSpaceTextOnlystopSearchElementsignoreElementsstartFromSibling )
    {
        while( ( 
currentNode this.GetNextSourceNodecurrentNodestartFromSibling ) ) )    // Only one "=".
        
{
            if ( 
currentNode.nodeType == )
            {
                if ( 
stopSearchElements && currentNode.nodeName.IEqualsstopSearchElements ) )
                    break ;

                if ( 
ignoreElements && currentNode.nodeName.IEqualsignoreElements ) )
                    return 
this.GetNextSourceElementcurrentNodeignoreSpaceTextOnlystopSearchElementsignoreElements ) ;

                return 
currentNode ;
            }
            else if ( 
ignoreSpaceTextOnly && currentNode.nodeType == && currentNode.nodeValue.RTrim().length )
                break ;
        }

        return 
null ;
    },

    
/*
     * Get the next DOM node available in source order.
     */
    
GetNextSourceNode : function( currentNodestartFromSiblingnodeTypestopSearchNode )
    {
        if ( !
currentNode )
            return 
null ;

        var 
node ;

        if ( !
startFromSibling && currentNode.firstChild )
            
node currentNode.firstChild ;
        else
        {
            if ( 
stopSearchNode && currentNode == stopSearchNode )
                return 
null ;

            
node currentNode.nextSibling ;

            if ( !
node && ( !stopSearchNode || stopSearchNode != currentNode.parentNode ) )
                return 
this.GetNextSourceNodecurrentNode.parentNodetruenodeTypestopSearchNode ) ;
        }

        if ( 
nodeType && node && node.nodeType != nodeType )
            return 
this.GetNextSourceNodenodefalsenodeTypestopSearchNode ) ;

        return 
node ;
    },

    
/*
     * Get the next DOM node available in source order.
     */
    
GetPreviousSourceNode : function( currentNodestartFromSiblingnodeTypestopSearchNode )
    {
        if ( !
currentNode )
            return 
null ;

        var 
node ;

        if ( !
startFromSibling && currentNode.lastChild )
            
node currentNode.lastChild ;
        else
        {
            if ( 
stopSearchNode && currentNode == stopSearchNode )
                return 
null ;

            
node currentNode.previousSibling ;

            if ( !
node && ( !stopSearchNode || stopSearchNode != currentNode.parentNode ) )
                return 
this.GetPreviousSourceNodecurrentNode.parentNodetruenodeTypestopSearchNode ) ;
        }

        if ( 
nodeType && node && node.nodeType != nodeType )
            return 
this.GetPreviousSourceNodenodefalsenodeTypestopSearchNode ) ;

        return 
node ;
    },

    
// Inserts a element after a existing one.
    
InsertAfterNode : function( existingNodenewNode )
    {
        return 
existingNode.parentNode.insertBeforenewNodeexistingNode.nextSibling ) ;
    },

    
GetParents : function( node )
    {
        var 
parents = new Array() ;

        while ( 
node )
        {
            
parents.unshiftnode ) ;
            
node node.parentNode ;
        }

        return 
parents ;
    },

    
GetCommonParents : function( node1node2 )
    {
        var 
p1 this.GetParentsnode1 ) ;
        var 
p2 this.GetParentsnode2 ) ;
        var 
retval = [] ;
        for ( var 
p1.length i++ )
        {
            if ( 
p1[i] == p2[i] )
                
retval.pushp1[i] ) ;
        }
        return 
retval ;
    },

    
GetCommonParentNode : function( node1node2tagList )
    {
        var 
tagMap = {} ;
        if ( ! 
tagList.pop )
            
tagList = [ tagList ] ;
        while ( 
tagList.length )
            
tagMap[tagList.pop().toLowerCase()] = ;

        var 
commonParents this.GetCommonParentsnode1node2 ) ;
        var 
currentParent null ;
        while ( ( 
currentParent commonParents.pop() ) )
        {
            if ( 
tagMap[currentParent.nodeName.toLowerCase()] )
                return 
currentParent ;
        }
        return 
null ;
    },

    
GetIndexOf : function( node )
    {
        var 
currentNode node.parentNode node.parentNode.firstChild null ;
        var 
currentIndex = -;

        while ( 
currentNode )
        {
            
currentIndex++ ;

            if ( 
currentNode == node )
                return 
currentIndex ;

            
currentNode currentNode.nextSibling ;
        }

        return -
;
    },

    
PaddingNode null,

    
EnforcePaddingNode : function( doctagName )
    {
        
// In IE it can happen when the page is reloaded that doc or doc.body is null, so exit here
        
try
        {
            if ( !
doc || !doc.body )
                return ;
        }
        catch (
e)
        {
            return ;
        }

        
this.CheckAndRemovePaddingNodedoctagNametrue ) ;
        try
        {
            if ( 
doc.body.lastChild && ( doc.body.lastChild.nodeType != 1
                    
|| doc.body.lastChild.tagName.toLowerCase() == tagName.toLowerCase() ) )
                return ;
        }
        catch (
e)
        {
            return ;
        }

        var 
node doc.createElementtagName ) ;
        if ( 
FCKBrowserInfo.IsGecko && FCKListsLib.NonEmptyBlockElementstagName ] )
            
FCKTools.AppendBogusBrnode ) ;
        
this.PaddingNode node ;
        if ( 
doc.body.childNodes.length == 1
                
&& doc.body.firstChild.nodeType == 1
                
&& doc.body.firstChild.tagName.toLowerCase() == 'br'
                
&& ( doc.body.firstChild.getAttribute'_moz_dirty' ) != null
                    
|| doc.body.firstChild.getAttribute'type' ) == '_moz' ) )
            
doc.body.replaceChildnodedoc.body.firstChild ) ;
        else
            
doc.body.appendChildnode ) ;
    },

    
CheckAndRemovePaddingNode : function( doctagNamedontRemove )
    {
        var 
paddingNode this.PaddingNode ;
        if ( ! 
paddingNode )
            return ;

        
// If the padding node is changed, remove its status as a padding node.
        
try
        {
            if ( 
paddingNode.parentNode != doc.body
                
|| paddingNode.tagName.toLowerCase() != tagName
                
|| ( paddingNode.childNodes.length )
                || ( 
paddingNode.firstChild && paddingNode.firstChild.nodeValue != 'xa0'
                    
&& String(paddingNode.firstChild.tagName).toLowerCase() != 'br' ) )
            {
                
this.PaddingNode null ;
                return ;
            }
        }
        catch (
e)
        {
                
this.PaddingNode null ;
                return ;
        }

        
// Now we're sure the padding node exists, and it is unchanged, and it
        // isn't the only node in doc.body, remove it.
        
if ( !dontRemove )
        {
            if ( 
paddingNode.parentNode.childNodes.length )
                
paddingNode.parentNode.removeChildpaddingNode ) ;
            
this.PaddingNode null ;
        }
    },

    
HasAttribute : function( elementattributeName )
    {
        if ( 
element.hasAttribute )
            return 
element.hasAttributeattributeName ) ;
        else
        {
            var 
att element.attributesattributeName ] ;
            return ( 
att != undefined && att.specified ) ;
        }
    },

    
/**
     * Checks if an element has "specified" attributes.
     */
    
HasAttributes : function( element )
    {
        var 
attributes element.attributes ;

        for ( var 
attributes.length i++ )
        {
            if ( 
FCKBrowserInfo.IsIE && attributes[i].nodeName == 'class' )
            {
                
// IE has a strange bug. If calling removeAttribute('className'),
                // the attributes collection will still contain the "class"
                // attribute, which will be marked as "specified", even if the
                // outerHTML of the element is not displaying the class attribute.
                // Note : I was not able to reproduce it outside the editor,
                // but I've faced it while working on the TC of #1391.
                
if ( element.className.length )
                    return 
true ;
            }
            else if ( 
attributes[i].specified )
                return 
true ;
        }

        return 
false ;
    },

    
/**
     * Remove an attribute from an element.
     */
    
RemoveAttribute : function( elementattributeName )
    {
        if ( 
FCKBrowserInfo.IsIE && attributeName.toLowerCase() == 'class' )
            
attributeName 'className' ;

        return 
element.removeAttributeattributeName) ;
    },

    
/**
     * Removes an array of attributes from an element
     */
    
RemoveAttributes : function (elementaAttributes )
    {
        for ( var 
aAttributes.length i++ )
            
this.RemoveAttributeelementaAttributes[i] );
    },

    
GetAttributeValue : function( elementatt )
    {
        var 
attName att ;

        if ( 
typeof att == 'string' )
            
att element.attributesatt ] ;
        else
            
attName att.nodeName ;

        if ( 
att && att.specified )
        {
            
// IE returns "null" for the nodeValue of a "style" attribute.
            
if ( attName == 'style' )
                return 
element.style.cssText ;
            
// There are two cases when the nodeValue must be used:
            //        - for the "class" attribute (all browsers).
            //        - for events attributes (IE only).
            
else if ( attName == 'class' || attName.indexOf('on') == )
                return 
att.nodeValue ;
            else
            {
                
// Use getAttribute to get its value  exactly as it is
                // defined.
                
return element.getAttributeattName) ;
            }
        }
        return 
null ;
    },

    
/**
     * Checks whether one element contains the other.
     */
    
Contains : function( mainElementotherElement )
    {
        
// IE supports contains, but only for element nodes.
        
if ( mainElement.contains && otherElement.nodeType == )
            return 
mainElement.containsotherElement ) ;

        while ( ( 
otherElement otherElement.parentNode ) )    // Only one "="
        
{
            if ( 
otherElement == mainElement )
                return 
true ;
        }
        return 
false ;
    },

    
/**
     * Breaks a parent element in the position of one of its contained elements.
     * For example, in the following case:
     *        <b>This <i>is some<span /> sample</i> test text</b>
     * If element = <span />, we have these results:
     *        <b>This <i>is some</i><span /><i> sample</i> test text</b>            (If parent = <i>)
     *        <b>This <i>is some</i></b><span /><b><i> sample</i> test text</b>    (If parent = <b>)
     */
    
BreakParent : function( elementparentreusableRange )
    {
        var 
range reusableRange || new FCKDomRangeFCKTools.GetElementWindowelement ) ) ;

        
// We'll be extracting part of this element, so let's use our
        // range to get the correct piece.
        
range.SetStartelement) ;
        
range.SetEndparent) ;

        
// Extract it.
        
var docFrag range.ExtractContents() ;

        
// Move the element outside the broken element.
        
range.InsertNodeelement.parentNode.removeChildelement ) ) ;

        
// Re-insert the extracted piece after the element.
        
docFrag.InsertAfterNodeelement ) ;

        
range.Release( !!reusableRange ) ;
    },

    
/**
     * Retrieves a uniquely identifiable tree address of a DOM tree node.
     * The tree address returns is an array of integers, with each integer
     * indicating a child index from a DOM tree node, starting from
     * document.documentElement.
     *
     * For example, assuming <body> is the second child from <html> (<head>
     * being the first), and we'd like to address the third child under the
     * fourth child of body, the tree address returned would be:
     * [1, 3, 2]
     *
     * The tree address cannot be used for finding back the DOM tree node once
     * the DOM tree structure has been modified.
     */
    
GetNodeAddress : function( nodenormalized )
    {
        var 
retval = [] ;
        while ( 
node && node != FCKTools.GetElementDocumentnode ).documentElement )
        {
            var 
parentNode node.parentNode ;
            var 
currentIndex = -;
            for( var 
parentNode.childNodes.length i++ )
            {
                var 
candidate parentNode.childNodes[i] ;
                if ( 
normalized === true &&
                        
candidate.nodeType == &&
                        
candidate.previousSibling &&
                        
candidate.previousSibling.nodeType == )
                    continue;
                
currentIndex++ ;
                if ( 
parentNode.childNodes[i] == node )
                    break ;
            }
            
retval.unshiftcurrentIndex ) ;
            
node node.parentNode ;
        }
        return 
retval ;
    },

    
/**
     * The reverse transformation of FCKDomTools.GetNodeAddress(). This
     * function returns the DOM node pointed to by its index address.
     */
    
GetNodeFromAddress : function( docaddrnormalized )
    {
        var 
cursor doc.documentElement ;
        for ( var 
addr.length i++ )
        {
            var 
target addr[i] ;
            if ( ! 
normalized )
            {
                
cursor cursor.childNodes[target] ;
                continue ;
            }

            var 
currentIndex = -;
            for (var 
cursor.childNodes.length j++ )
            {
                var 
candidate cursor.childNodes[j] ;
                if ( 
normalized === true &&
                        
candidate.nodeType == &&
                        
candidate.previousSibling &&
                        
candidate.previousSibling.nodeType == )
                    continue ;
                
currentIndex++ ;
                if ( 
currentIndex == target )
                {
                    
cursor candidate ;
                    break ;
                }
            }
        }
        return 
cursor ;
    },

    
CloneElement : function( element )
    {
        
element element.cloneNodefalse ) ;

        
// The "id" attribute should never be cloned to avoid duplication.
        
element.removeAttribute'id'false ) ;

        return 
element ;
    },

    
ClearElementJSProperty : function( elementattrName )
    {
        if ( 
FCKBrowserInfo.IsIE )
            
element.removeAttributeattrName ) ;
        else
            
delete element[attrName] ;
    },

    
SetElementMarker : function ( markerObjelementattrNamevalue)
    {
        var 
id StringparseIntMath.random() * 0xffffffff10 ) ) ;
        
element._FCKMarkerId id ;
        
element[attrName] = value ;
        if ( ! 
markerObj[id] )
            
markerObj[id] = { 'element' element'markers' : {} } ;
        
markerObj[id]['markers'][attrName] = value ;
    },

    
ClearElementMarkers : function( markerObjelementclearMarkerObj )
    {
        var 
id element._FCKMarkerId ;
        if ( ! 
id )
            return ;
        
this.ClearElementJSPropertyelement'_FCKMarkerId' ) ;
        for ( var 
j in markerObj[id]['markers'] )
            
this.ClearElementJSPropertyelement) ;
        if ( 
clearMarkerObj )
            
delete markerObj[id] ;
    },

    
ClearAllMarkers : function( markerObj )
    {
        for ( var 
i in markerObj )
            
this.ClearElementMarkersmarkerObjmarkerObj[i]['element'], true ) ;
    },

    
/**
     * Convert a DOM list tree into a data structure that is easier to
     * manipulate. This operation should be non-intrusive in the sense that it
     * does not change the DOM tree, with the exception that it may add some
     * markers to the list item nodes when markerObj is specified.
     */
    
ListToArray : function( listNodemarkerObjbaseArraybaseIndentLevelgrandparentNode )
    {
        if ( ! 
listNode.nodeName.IEquals( ['ul''ol'] ) )
            return [] ;

        if ( ! 
baseIndentLevel )
            
baseIndentLevel ;
        if ( ! 
baseArray )
            
baseArray = [] ;
        
// Iterate over all list items to get their contents and look for inner lists.
        
for ( var listNode.childNodes.length i++ )
        {
            var 
listItem listNode.childNodes[i] ;
            if ( ! 
listItem.nodeName.IEquals'li' ) )
                continue ;
            var 
itemObj = { 'parent' listNode'indent' baseIndentLevel'contents' : [] } ;
            if ( ! 
grandparentNode )
            {
                
itemObj.grandparent listNode.parentNode ;
                if ( 
itemObj.grandparent && itemObj.grandparent.nodeName.IEquals'li' ) )
                    
itemObj.grandparent itemObj.grandparent.parentNode ;
            }
            else
                
itemObj.grandparent grandparentNode ;
            if ( 
markerObj )
                
this.SetElementMarkermarkerObjlistItem'_FCK_ListArray_Index'baseArray.length ) ;
            
baseArray.pushitemObj ) ;
            for ( var 
listItem.childNodes.length j++ )
            {
                var 
child listItem.childNodes[j] ;
                if ( 
child.nodeName.IEquals( ['ul''ol'] ) )
                    
// Note the recursion here, it pushes inner list items with
                    // +1 indentation in the correct order.
                    
this.ListToArraychildmarkerObjbaseArraybaseIndentLevel 1itemObj.grandparent ) ;
                else
                    
itemObj.contents.pushchild ) ;
            }
        }
        return 
baseArray ;
    },

    
// Convert our internal representation of a list back to a DOM forest.
    
ArrayToList : function( listArraymarkerObjbaseIndex )
    {
        if ( 
baseIndex == undefined )
            
baseIndex ;
        if ( ! 
listArray || listArray.length baseIndex )
            return 
null ;
        var 
doc FCKTools.GetElementDocumentlistArray[baseIndex].parent ) ;
        var 
retval doc.createDocumentFragment() ;
        var 
rootNode null ;
        var 
currentIndex baseIndex ;
        var 
indentLevel Math.maxlistArray[baseIndex].indent) ;
        var 
currentListItem null ;
        while ( 
true )
        {
            var 
item listArray[currentIndex] ;
            if ( 
item.indent == indentLevel )
            {
                if ( ! 
rootNode || listArray[currentIndex].parent.nodeName != rootNode.nodeName )
                {
                    
rootNode listArray[currentIndex].parent.cloneNodefalse ) ;
                    
retval.appendChildrootNode ) ;
                }
                
currentListItem doc.createElement'li' ) ;
                
rootNode.appendChildcurrentListItem ) ;
                for ( var 
item.contents.length i++ )
                    
currentListItem.appendChilditem.contents[i].cloneNodetrue ) ) ;
                
currentIndex++ ;
            }
            else if ( 
item.indent == Math.maxindentLevel) + )
            {
                var 
listData this.ArrayToListlistArraynullcurrentIndex ) ;
                
currentListItem.appendChildlistData.listNode ) ;
                
currentIndex listData.nextIndex ;
            }
            else if ( 
item.indent == -&& baseIndex == && item.grandparent )
            {
                var 
currentListItem ;
                if ( 
item.grandparent.nodeName.IEquals( ['ul''ol'] ) )
                    
currentListItem doc.createElement'li' ) ;
                else
                {
                    if ( 
FCKConfig.EnterMode.IEquals( ['div''p'] ) && ! item.grandparent.nodeName.IEquals'td' ) )
                        
currentListItem doc.createElementFCKConfig.EnterMode ) ;
                    else
                        
currentListItem doc.createDocumentFragment() ;
                }
                for ( var 
item.contents.length i++ )
                    
currentListItem.appendChilditem.contents[i].cloneNodetrue ) ) ;
                if ( 
currentListItem.nodeType == 11 )
                {
                    if ( 
currentListItem.lastChild &&
                            
currentListItem.lastChild.getAttribute &&
                            
currentListItem.lastChild.getAttribute'type' ) == '_moz' )
                        
currentListItem.removeChildcurrentListItem.lastChild );
                    
currentListItem.appendChilddoc.createElement'br' ) ) ;
                }
                if ( 
currentListItem.nodeName.IEqualsFCKConfig.EnterMode ) && currentListItem.firstChild )
                {
                    
this.TrimNodecurrentListItem ) ;
                    if ( 
FCKListsLib.BlockBoundaries[currentListItem.firstChild.nodeName.toLowerCase()] )
                    {
                        var 
tmp doc.createDocumentFragment() ;
                        while ( 
currentListItem.firstChild )
                            
tmp.appendChildcurrentListItem.removeChildcurrentListItem.firstChild ) ) ;
                        
currentListItem tmp ;
                    }
                }
                if ( 
FCKBrowserInfo.IsGeckoLike && currentListItem.nodeName.IEquals( ['div''p'] ) )
                    
FCKTools.AppendBogusBrcurrentListItem ) ;
                
retval.appendChildcurrentListItem ) ;
                
rootNode null ;
                
currentIndex++ ;
            }
            else
                return 
null ;

            if ( 
listArray.length <= currentIndex || Math.maxlistArray[currentIndex].indent) < indentLevel )
            {
                break ;
            }
        }

        
// Clear marker attributes for the new list tree made of cloned nodes, if any.
        
if ( markerObj )
        {
            var 
currentNode retval.firstChild ;
            while ( 
currentNode )
            {
                if ( 
currentNode.nodeType == )
                    
this.ClearElementMarkersmarkerObjcurrentNode ) ;
                
currentNode this.GetNextSourceNodecurrentNode ) ;
            }
        }

        return { 
'listNode' retval'nextIndex' currentIndex } ;
    },

    
/**
     * Get the next sibling node for a node. If "includeEmpties" is false,
     * only element or non empty text nodes are returned.
     */
    
GetNextSibling : function( nodeincludeEmpties )
    {
        
node node.nextSibling ;

        while ( 
node && !includeEmpties && node.nodeType != && ( node.nodeType != || node.nodeValue.length == ) )
            
node node.nextSibling ;

        return 
node ;
    },

    
/**
     * Get the previous sibling node for a node. If "includeEmpties" is false,
     * only element or non empty text nodes are returned.
     */
    
GetPreviousSibling : function( nodeincludeEmpties )
    {
        
node node.previousSibling ;

        while ( 
node && !includeEmpties && node.nodeType != && ( node.nodeType != || node.nodeValue.length == ) )
            
node node.previousSibling ;

        return 
node ;
    },

    
/**
     * Checks if an element has no "useful" content inside of it
     * node tree. No "useful" content means empty text node or a signle empty
     * inline node.
     * elementCheckCallback may point to a function that returns a boolean
     * indicating that a child element must be considered in the element check.
     */
    
CheckIsEmptyElement : function( elementelementCheckCallback )
    {
        var 
child element.firstChild ;
        var 
elementChild ;

        while ( 
child )
        {
            if ( 
child.nodeType == )
            {
                if ( 
elementChild || !FCKListsLib.InlineNonEmptyElementschild.nodeName.toLowerCase() ] )
                    return 
false ;

                if ( !
elementCheckCallback || elementCheckCallbackchild ) === true )
                    
elementChild child ;
            }
            else if ( 
child.nodeType == && child.nodeValue.length )
                return 
false ;

            
child child.nextSibling ;
        }

        return 
elementChild this.CheckIsEmptyElementelementChildelementCheckCallback ) : true ;
    },

    
SetElementStyles : function( elementstyleDict )
    {
        var 
style element.style ;
        for ( var 
styleName in styleDict )
            
stylestyleName ] = styleDictstyleName ] ;
    },

    
SetOpacity : function( elementopacity )
    {
        if ( 
FCKBrowserInfo.IsIE )
        {
            
opacity Math.roundopacity 100 ) ;
            
element.style.filter = ( opacity 100 '' 'progid:DXImageTransform.Microsoft.Alpha(opacity=' opacity ')' ) ;
        }
        else
            
element.style.opacity opacity ;
    },

    
GetCurrentElementStyle : function( elementpropertyName )
    {
        if ( 
FCKBrowserInfo.IsIE )
            return 
element.currentStylepropertyName ] ;
        else
            return 
element.ownerDocument.defaultView.getComputedStyleelement'' ).getPropertyValuepropertyName ) ;
    },

    
GetPositionedAncestor : function( element )
    {
        var 
currentElement element ;

        while ( 
currentElement != FCKTools.GetElementDocumentcurrentElement ).documentElement )
        {
            if ( 
this.GetCurrentElementStylecurrentElement'position' ) != 'static' )
                return 
currentElement ;

            if ( 
currentElement == FCKTools.GetElementDocumentcurrentElement ).documentElement
                    
&& currentWindow != )
                
currentElement currentWindow.frameElement ;
            else
                
currentElement currentElement.parentNode ;
        }

        return 
null ;
    },

    
/**
     * Current implementation for ScrollIntoView (due to #1462 and #2279). We
     * don't have a complete implementation here, just the things that fit our
     * needs.
     */
    
ScrollIntoView : function( elementalignTop )
    {
        
// Get the element window.
        
var window FCKTools.GetElementWindowelement ) ;
        var 
windowHeight FCKTools.GetViewPaneSizewindow ).Height ;

        
// Starts the offset that will be scrolled with the negative value of
        // the visible window height.
        
var offset windowHeight * -;

        
// Appends the height it we are about to align the bottoms.
        
if ( alignTop === false )
        {
            
offset += element.offsetHeight || ;

            
// Consider the margin in the scroll, which is ok for our current
            // needs, but needs investigation if we will be using this function
            // in other places.
            
offset += parseIntthis.GetCurrentElementStyleelement'marginBottom' ) || 010 ) || ;
        }

        
// Appends the offsets for the entire element hierarchy.
        
var elementPosition FCKTools.GetDocumentPositionwindowelement ) ;
        
offset += elementPosition.;

        
// Scroll the window to the desired position, if not already visible.
        
var currentScroll FCKTools.GetScrollPositionwindow ).;
        if ( 
offset && ( offset currentScroll || offset currentScroll windowHeight ) )
            
window.scrollTo0offset ) ;
    },

    
/**
     * Check if the element can be edited inside the browser.
     */
    
CheckIsEditable : function( element )
    {
        
// Get the element name.
        
var nodeName element.nodeName.toLowerCase() ;

        
// Get the element DTD (defaults to span for unknown elements).
        
var childDTD FCK.DTDnodeName ] || FCK.DTD.span ;

        
// In the DTD # == text node.
        
return ( childDTD['#'] && !FCKListsLib.NonEditableElementsnodeName ] ) ;
    },

    
GetSelectedDivContainers : function()
    {
        var 
currentBlocks = [] ;
        var 
range = new FCKDomRangeFCK.EditorWindow ) ;
        
range.MoveToSelection() ;

        var 
startNode range.GetTouchedStartNode() ;
        var 
endNode range.GetTouchedEndNode() ;
        var 
currentNode startNode ;

        if ( 
startNode == endNode )
        {
            while ( 
endNode.nodeType == && endNode.lastChild )
                
endNode endNode.lastChild ;
            
endNode FCKDomTools.GetNextSourceNodeendNode ) ;
        }

        while ( 
currentNode && currentNode != endNode )
        {
            if ( 
currentNode.nodeType != || !/^[ tn]*$/.testcurrentNode.nodeValue ) )
            {
                var 
path = new FCKElementPathcurrentNode ) ;
                var 
blockLimit path.BlockLimit ;
                if ( 
blockLimit && blockLimit.nodeName.IEquals'div' ) && currentBlocks.IndexOfblockLimit ) == -)
                    
currentBlocks.pushblockLimit ) ;
            }

            
currentNode FCKDomTools.GetNextSourceNodecurrentNode ) ;
        }

        return 
currentBlocks ;
    }
} ;
?>
Онлайн: 0
Реклама