Вход Регистрация
Файл: fckeditor/editor/_source/internals/fcktools_gecko.js
Строк: 390
<?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. (Gecko version).
 */

FCKTools.CancelEvent = function( )
{
    if ( 
)
        
e.preventDefault() ;
}

FCKTools.DisableSelection = function( element )
{
    if ( 
FCKBrowserInfo.IsGecko )
        
element.style.MozUserSelect        'none' ;    // Gecko only.
    
else if ( FCKBrowserInfo.IsSafari )
        
element.style.KhtmlUserSelect    'none' ;    // WebKit only.
    
else
        
element.style.userSelect        'none' ;    // CSS3 (not supported yet).
}

// Appends a CSS file to a document.
FCKTools._AppendStyleSheet = function( documentElementcssFileUrl )
{
    var 
documentElement.createElement'LINK' ) ;
    
e.rel    'stylesheet' ;
    
e.type    'text/css' ;
    
e.href    cssFileUrl ;
    
documentElement.getElementsByTagName("HEAD")[0].appendChild) ;
    return 
;
}

// Appends a CSS style string to a document.
FCKTools.AppendStyleString = function( documentElementcssStyles )
{
    if ( !
cssStyles )
        return 
null ;

    var 
documentElement.createElement"STYLE" ) ;
    
e.appendChilddocumentElement.createTextNodecssStyles ) ) ;
    
documentElement.getElementsByTagName"HEAD" )[0].appendChild) ;
    return 
;
}

// Removes all attributes and values from the element.
FCKTools.ClearElementAttributes = function( element )
{
    
// Loop throw all attributes in the element
    
for ( var element.attributes.length i++ )
    {
        
// Remove the element by name.
        
element.removeAttributeelement.attributes[i].name) ;    // 0 : Case Insensitive
    
}
}

// Returns an Array of strings with all defined in the elements inside another element.
FCKTools.GetAllChildrenIds = function( parentElement )
{
    
// Create the array that will hold all Ids.
    
var aIds = new Array() ;

    
// Define a recursive function that search for the Ids.
    
var fGetIds = function( parent )
    {
        for ( var 
parent.childNodes.length i++ )
        {
            var 
sId parent.childNodes[i].id ;

            
// Check if the Id is defined for the element.
            
if ( sId && sId.length aIdsaIds.length ] = sId ;

            
// Recursive call.
            
fGetIdsparent.childNodes[i] ) ;
        }
    }

    
// Start the recursive calls.
    
fGetIdsparentElement ) ;

    return 
aIds ;
}

// Replaces a tag with its contents. For example "<span>My <b>tag</b></span>"
// will be replaced with "My <b>tag</b>".
FCKTools.RemoveOuterTags = function( )
{
    var 
oFragment e.ownerDocument.createDocumentFragment() ;

    for ( var 
e.childNodes.length i++ )
        
oFragment.appendChilde.childNodes[i].cloneNode(true) ) ;

    
e.parentNode.replaceChildoFragment) ;
}

FCKTools.CreateXmlObject = function( object )
{
    switch ( object )
    {
        case 
'XmlHttp' :
            return new 
XMLHttpRequest() ;

        case 
'DOMDocument' :
            
// Originaly, we were had the following here:
            // return document.implementation.createDocument( '', '', null ) ;
            // But that doesn't work if we're running under domain relaxation mode, so we need a workaround.
            // See http://ajaxian.com/archives/xml-messages-with-cross-domain-json about the trick we're using.
            
var doc = ( new DOMParser() ).parseFromString'<tmp></tmp>''text/xml' ) ;
            
FCKDomTools.RemoveNodedoc.firstChild ) ;
            return 
doc ;
    }
    return 
null ;
}

FCKTools.GetScrollPosition = function( relativeWindow )
{
    return { 
relativeWindow.pageXOffsetrelativeWindow.pageYOffset } ;
}

FCKTools.AddEventListener = function( sourceObjecteventNamelistener )
{
    
sourceObject.addEventListenereventNamelistenerfalse ) ;
}

FCKTools.RemoveEventListener = function( sourceObjecteventNamelistener )
{
    
sourceObject.removeEventListenereventNamelistenerfalse ) ;
}

// Listeners attached with this function cannot be detached.
FCKTools.AddEventListenerEx = function( sourceObjecteventNamelistenerparamsArray )
{
    
sourceObject.addEventListener(
        
eventName,
        function( 
)
        {
            
listener.applysourceObject, [ ].concatparamsArray || [] ) ) ;
        },
        
false
    
) ;
}

// Returns and object with the "Width" and "Height" properties.
FCKTools.GetViewPaneSize = function( win )
{
    return { 
Width win.innerWidthHeight win.innerHeight } ;
}

FCKTools.SaveStyles = function( element )
{
    var 
data FCKTools.ProtectFormStyleselement ) ;

    var 
oSavedStyles = new Object() ;

    if ( 
element.className.length )
    {
        
oSavedStyles.Class = element.className ;
        
element.className '' ;
    }

    var 
sInlineStyle element.getAttribute'style' ) ;

    if ( 
sInlineStyle && sInlineStyle.length )
    {
        
oSavedStyles.Inline sInlineStyle ;
        
element.setAttribute'style''') ;    // 0 : Case Insensitive
    
}

    
FCKTools.RestoreFormStyleselementdata ) ;
    return 
oSavedStyles ;
}

FCKTools.RestoreStyles = function( elementsavedStyles )
{
    var 
data FCKTools.ProtectFormStyleselement ) ;
    
element.className savedStyles.Class || '' ;

    if ( 
savedStyles.Inline )
        
element.setAttribute'style'savedStyles.Inline) ;    // 0 : Case Insensitive
    
else
        
element.removeAttribute'style') ;
    
FCKTools.RestoreFormStyleselementdata ) ;
}

FCKTools.RegisterDollarFunction = function( targetWindow )
{
    
targetWindow.$ = function( id )
    {
        return 
targetWindow.document.getElementByIdid ) ;
    } ;
}

FCKTools.AppendElement = function( targetelementName )
{
    return 
target.appendChildtarget.ownerDocument.createElementelementName ) ) ;
}

// Get the coordinates of an element.
//        @el : The element to get the position.
//        @relativeWindow: The window to which we want the coordinates relative to.
FCKTools.GetElementPosition = function( elrelativeWindow )
{
    
// Initializes the Coordinates object that will be returned by the function.
    
var = { X:0Y:} ;

    var 
oWindow relativeWindow || window ;

    var 
oOwnerWindow FCKTools.GetElementWindowel ) ;

    var 
previousElement null ;
    
// Loop throw the offset chain.
    
while ( el )
    {
        var 
sPosition oOwnerWindow.getComputedStyle(el'').position ;

        
// Check for non "static" elements.
        // 'FCKConfig.FloatingPanelsZIndex' -- Submenus are under a positioned IFRAME.
        
if ( sPosition && sPosition != 'static' && el.style.zIndex != FCKConfig.FloatingPanelsZIndex )
            break ;

        
/*
        FCKDebug.Output( el.tagName + ":" + "offset=" + el.offsetLeft + "," + el.offsetTop + "  "
                + "scroll=" + el.scrollLeft + "," + el.scrollTop ) ;
        */

        
c.+= el.offsetLeft el.scrollLeft ;
        
c.+= el.offsetTop el.scrollTop  ;

        
// Backtrack due to offsetParent's calculation by the browser ignores scrollLeft and scrollTop.
        // Backtracking is not needed for Opera
        
if ( ! FCKBrowserInfo.IsOpera )
        {
            var 
scrollElement previousElement ;
            while ( 
scrollElement && scrollElement != el )
            {
                
c.-= scrollElement.scrollLeft ;
                
c.-= scrollElement.scrollTop ;
                
scrollElement scrollElement.parentNode ;
            }
        }

        
previousElement el ;
        if ( 
el.offsetParent )
            
el el.offsetParent ;
        else
        {
            if ( 
oOwnerWindow != oWindow )
            {
                
el oOwnerWindow.frameElement ;
                
previousElement null ;
                if ( 
el )
                    
oOwnerWindow FCKTools.GetElementWindowel ) ;
            }
            else
            {
                
c.+= el.scrollLeft ;
                
c.+= el.scrollTop  ;
                break ;
            }
        }
    }

    
// Return the Coordinates object
    
return ;
}
?>
Онлайн: 3
Реклама