Вход Регистрация
Файл: fckeditor/editor/_source/classes/fckdomrange_ie.js
Строк: 280
<?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 ==
 *
 * Class for working with a selection range, much like the W3C DOM Range, but
 * it is not intended to be an implementation of the W3C interface.
 * (IE Implementation)
 */

FCKDomRange.prototype.MoveToSelection = function()
{
    
this.Releasetrue ) ;

    
this._Range = new FCKW3CRangethis.Window.document ) ;

    var 
oSel this.Window.document.selection ;

    if ( 
oSel.type != 'Control' )
    {
        var 
eMarkerStart    this._GetSelectionMarkerTagtrue ) ;
        var 
eMarkerEnd        this._GetSelectionMarkerTagfalse ) ;

        if ( !
eMarkerStart && !eMarkerEnd )
        {
            
this._Range.setStartthis.Window.document.body) ;
            
this._UpdateElementInfo() ;
            return ;
        }

        
// Set the start boundary.
        
this._Range.setStarteMarkerStart.parentNodeFCKDomTools.GetIndexOfeMarkerStart ) ) ;
        
eMarkerStart.parentNode.removeChildeMarkerStart ) ;

        
// Set the end boundary.
        
this._Range.setEndeMarkerEnd.parentNodeFCKDomTools.GetIndexOfeMarkerEnd ) ) ;
        
eMarkerEnd.parentNode.removeChildeMarkerEnd ) ;

        
this._UpdateElementInfo() ;
    }
    else
    {
        var 
oControl oSel.createRange().item(0) ;

        if ( 
oControl )
        {
            
this._Range.setStartBeforeoControl ) ;
            
this._Range.setEndAfteroControl ) ;
            
this._UpdateElementInfo() ;
        }
    }
}

FCKDomRange.prototype.Select = function( forceExpand )
{
    if ( 
this._Range )
        
this.SelectBookmarkthis.CreateBookmarktrue ), forceExpand ) ;
}

// Not compatible with bookmark created with CreateBookmark2.
// The bookmark nodes will be deleted from the document.
FCKDomRange.prototype.SelectBookmark = function( bookmarkforceExpand )
{
    var 
bIsCollapsed this.CheckIsCollapsed() ;
    var 
bIsStartMakerAlone ;
    var 
dummySpan ;

    
// Create marker tags for the start and end boundaries.
    
var eStartMarker this.GetBookmarkNodebookmarktrue ) ;

    if ( !
eStartMarker )
        return ;

    var 
eEndMarker ;
    if ( !
bIsCollapsed )
        
eEndMarker this.GetBookmarkNodebookmarkfalse ) ;

    
// Create the main range which will be used for the selection.
    
var oIERange this.Window.document.body.createTextRange() ;

    
// Position the range at the start boundary.
    
oIERange.moveToElementTexteStartMarker ) ;
    
oIERange.moveStart'character') ;

    if ( 
eEndMarker )
    {
        
// Create a tool range for the end.
        
var oIERangeEnd this.Window.document.body.createTextRange() ;

        
// Position the tool range at the end.
        
oIERangeEnd.moveToElementTexteEndMarker ) ;

        
// Move the end boundary of the main range to match the tool range.
        
oIERange.setEndPoint'EndToEnd'oIERangeEnd ) ;
        
oIERange.moveEnd'character', -) ;
    }
    else
    {
        
bIsStartMakerAlone = ( forceExpand || !eStartMarker.previousSibling || eStartMarker.previousSibling.nodeName.toLowerCase() == 'br' ) && !eStartMarker.nextSibing ;

        
// Append a temporary <span>&#65279;</span> before the selection.
        // This is needed to avoid IE destroying selections inside empty
        // inline elements, like <b></b> (#253).
        // It is also needed when placing the selection right after an inline
        // element to avoid the selection moving inside of it.
        
dummySpan this.Window.document.createElement'span' ) ;
        
dummySpan.innerHTML '&#65279;' ;    // Zero Width No-Break Space (U+FEFF). See #1359.
        
eStartMarker.parentNode.insertBeforedummySpaneStartMarker ) ;

        if ( 
bIsStartMakerAlone )
        {
            
// To expand empty blocks or line spaces after <br>, we need
            // instead to have any char, which will be later deleted using the
            // selection.
            // ufeff = Zero Width No-Break Space (U+FEFF). See #1359.
            
eStartMarker.parentNode.insertBeforethis.Window.document.createTextNode'ufeff' ), eStartMarker ) ;
        }
    }

    if ( !
this._Range )
        
this._Range this.CreateRange() ;

    
// Remove the markers (reset the position, because of the changes in the DOM tree).
    
this._Range.setStartBeforeeStartMarker ) ;
    
eStartMarker.parentNode.removeChildeStartMarker ) ;

    if ( 
bIsCollapsed )
    {
        if ( 
bIsStartMakerAlone )
        {
            
// Move the selection start to include the temporary &#65279;.
            
oIERange.moveStart'character', -) ;

            
oIERange.select() ;

            
// Remove our temporary stuff.
            
this.Window.document.selection.clear() ;
        }
        else
            
oIERange.select() ;

        
FCKDomTools.RemoveNodedummySpan ) ;
    }
    else
    {
        
this._Range.setEndBeforeeEndMarker ) ;
        
eEndMarker.parentNode.removeChildeEndMarker ) ;
        
oIERange.select() ;
    }
}

FCKDomRange.prototype._GetSelectionMarkerTag = function( toStart )
{
    var 
doc this.Window.document ;
    var 
selection doc.selection ;

    
// Get a range for the start boundary.
    
var oRange ;

    
// IE may throw an "unspecified error" on some cases (it happened when
    // loading _samples/default.html), so try/catch.
    
try
    {
        
oRange selection.createRange() ;
    }
    catch (
e)
    {
        return 
null ;
    }

    
// IE might take the range object to the main window instead of inside the editor iframe window.
    // This is known to happen when the editor window has not been selected before (See #933).
    // We need to avoid that.
    
if ( oRange.parentElement().document != doc )
        return 
null ;

    
oRange.collapsetoStart === true ) ;

    
// Paste a marker element at the collapsed range and get it from the DOM.
    
var sMarkerId 'fck_dom_range_temp_' + (new Date()).valueOf() + '_' Math.floor(Math.random()*1000) ;
    
oRange.pasteHTML'<span id="' sMarkerId '"></span>' ) ;

    return 
doc.getElementByIdsMarkerId ) ;
}
?>
Онлайн: 0
Реклама