Вход Регистрация
Файл: plugins/p_fckeditor/fckeditor/editor/dialog/fck_replace.html
Строк: 715
<?php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * 
FCKeditor The text editor for Internet http://www.fckeditor.net
 
Copyright (C2003-2010 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 ==
 *
 * 
"Find" and "Replace" dialog box window.
-->
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
    <
title></title>
    <
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <
meta content="noindex, nofollow" name="robots" />
    <
script src="common/fck_dialog_common.js" type="text/javascript"></script>
    <
script type="text/javascript">

var 
dialog    window.parent ;
var 
oEditor dialog.InnerDialogLoaded() ;
var 
dialogArguments dialog.Args() ;

var 
FCKLang oEditor.FCKLang ;
var 
FCKDomTools oEditor.FCKDomTools ;
var 
FCKDomRange oEditor.FCKDomRange ;
var 
FCKListsLib oEditor.FCKListsLib ;
var 
FCKTools oEditor.FCKTools ;
var 
EditorDocument oEditor.FCK.EditorDocument ;
var 
HighlightStyle oEditor.FCKStyles.GetStyle'_FCK_SelectionHighlight' )  ;

dialog.AddTab'Find'FCKLang.DlgFindTitle ) ;
dialog.AddTab'Replace'FCKLang.DlgReplaceTitle ) ;
var 
idMap = {} ;

function 
OnDialogTabChangetabCode )
{
    
ShowE'divFind', ( tabCode == 'Find' ) ) ;
    
ShowE'divReplace', ( tabCode == 'Replace' ) ) ;
    
idMap['FindText'] = 'txtFind' tabCode ;
    
idMap['CheckCase'] = 'chkCase' tabCode ;
    
idMap['CheckWord'] = 'chkWord' tabCode ;

    if ( 
tabCode == 'Replace' )
        
dialog.SetAutoSizetrue ) ;
}

GetNextNonEmptyTextNode = function( nodestopNode )
{
    while ( ( 
node FCKDomTools.GetNextSourceNodenodefalse3stopNode ) ) && node && node.length )
        
;
    return 
node ;
}

CharacterCursor = function( arg )
{
    if ( 
arg.nodeType && arg.nodeType == )
    {
        
this._textNode GetNextNonEmptyTextNodearg.bodyarg.documentElement ) ;
        
this._offset ;
        
this._doc arg ;
    }
    else
    {
        
this._textNode arguments[0] ;
        
this._offset arguments[1] ;
        
this._doc FCKTools.GetElementDocumentarguments[0] ) ;
    }
}
CharacterCursor.prototype =
{
    
GetCharacter : function()
    {
        return ( 
this._textNode && this._textNode.nodeValue.charAtthis._offset ) ) || null ;
    },

    
// Non-normalized.
    
GetTextNode : function()
    {
        return 
this._textNode ;
    },

    
// Non-normalized.
    
GetIndex : function()
    {
        return 
this._offset ;
    },

    
// Return value means whehther we've crossed a line break or a paragraph boundary.
    
MoveNext : function()
    {
        if ( 
this._offset this._textNode.length )
        {
            
this._offset++ ;
            return 
false ;
        }

        var 
crossed false ;
        var 
curNode this._textNode ;
        while ( ( 
curNode FCKDomTools.GetNextSourceNodecurNode ) )
                && 
curNode && ( curNode.nodeType != || curNode.length ) )
        {
            var 
tag curNode.nodeName.toLowerCase() ;
            if ( 
FCKListsLib.BlockElements[tag] || tag == 'br' )
                
crossed true ;
        }

        
this._textNode curNode ;
        
this._offset ;
        return 
crossed ;
    },

    
// Return value means whehther we've crossed a line break or a paragraph boundary.
    
MoveBack : function()
    {
        if ( 
this._offset && this._textNode.length )
        {
            
this._offset Math.minthis._offset 1this._textNode.length ) ;
            return 
false ;
        }

        var 
crossed false ;
        var 
curNode this._textNode ;
        while ( ( 
curNode FCKDomTools.GetPreviousSourceNodecurNode ) )
                && 
curNode && ( curNode.nodeType != || curNode.length ) )
        {
            var 
tag curNode.nodeName.toLowerCase() ;
            if ( 
FCKListsLib.BlockElements[tag] || tag == 'br' )
                
crossed true ;
        }

        
this._textNode curNode ;
        
this._offset curNode && curNode.length ;
        return 
crossed ;
    },

    Clone : function()
    {
        return new 
CharacterCursorthis._textNodethis._offset ) ;
    }
} ;

CharacterRange = function( initCursormaxLength )
{
    
this._cursors initCursor.push initCursor : [initCursor] ;
    
this._maxLength maxLength ;
    
this._highlightRange null ;
}
CharacterRange.prototype =
{
    
ToDomRange : function()
    {
        var 
firstCursor this._cursors[0] ;
        var 
lastCursor this._cursorsthis._cursors.length ] ;
        var 
domRange = new FCKDomRangeFCKTools.GetElementWindowfirstCursor.GetTextNode() ) ) ;
        var 
w3cRange domRange._Range domRange.CreateRange() ;
        
w3cRange.setStartfirstCursor.GetTextNode(), firstCursor.GetIndex() ) ;
        
w3cRange.setEndlastCursor.GetTextNode(), lastCursor.GetIndex() + ) ;
        
domRange._UpdateElementInfo() ;
        return 
domRange ;
    },

    
Highlight : function()
    {
        if ( 
this._cursors.length )
            return ;

        var 
domRange this.ToDomRange() ;
        
HighlightStyle.ApplyToRangedomRangefalsetrue ) ;
        
this._highlightRange domRange ;

        var 
charRange CharacterRange.CreateFromDomRangedomRange ) ;
        var 
focusNode domRange.StartNode ;
        if ( 
focusNode.nodeType != )
            
focusNode focusNode.parentNode ;
        
FCKDomTools.ScrollIntoViewfocusNodefalse ) ;
        
this._cursors charRange._cursors ;
    },

    
RemoveHighlight : function()
    {
        if ( 
this._highlightRange )
        {
            
HighlightStyle.RemoveFromRangethis._highlightRangefalsetrue ) ;
            var 
charRange CharacterRange.CreateFromDomRangethis._highlightRange ) ;
            
this._cursors charRange._cursors ;
            
this._highlightRange null ;
        }
    },

    
GetHighlightDomRange : function()
    {
        return 
this._highlightRange;
    },

    
MoveNext : function()
    {
        var 
next this._cursorsthis._cursors.length ].Clone() ;
        var 
retval next.MoveNext() ;
        if ( 
retval )
            
this._cursors = [] ;
        
this._cursors.pushnext ) ;
        if ( 
this._cursors.length this._maxLength )
            
this._cursors.shift() ;
        return 
retval ;
    },

    
MoveBack : function()
    {
        var 
prev this._cursors[0].Clone() ;
        var 
retval prev.MoveBack() ;
        if ( 
retval )
            
this._cursors = [] ;
        
this._cursors.unshiftprev ) ;
        if ( 
this._cursors.length this._maxLength )
            
this._cursors.pop() ;
        return 
retval ;
    },

    
GetEndCharacter : function()
    {
        if ( 
this._cursors.length )
            return 
null ;
        var 
retval this._cursorsthis._cursors.length ].GetCharacter() ;
        return 
retval ;
    },

    
GetNextRange : function( len )
    {
        if ( 
this._cursors.length == )
            return 
null ;
        var 
cur this._cursorsthis._cursors.length ].Clone() ;
        
cur.MoveNext() ;
        return new 
CharacterRangecurlen ) ;
    },

    
GetCursors : function()
    {
        return 
this._cursors ;
    }
} ;

CharacterRange.CreateFromDomRange = function( domRange )
{
    var 
w3cRange domRange._Range ;
    var 
startContainer w3cRange.startContainer ;
    var 
endContainer w3cRange.endContainer ;
    var 
startTextNodestartIndexendTextNodeendIndex ;

    if ( 
startContainer.nodeType == )
    {
        
startTextNode startContainer ;
        
startIndex w3cRange.startOffset ;
    }
    else if ( 
domRange.StartNode.nodeType == )
    {
        
startTextNode domRange.StartNode ;
        
startIndex ;
    }
    else
    {
        
startTextNode GetNextNonEmptyTextNodedomRange.StartNodedomRange.StartNode.parentNode ) ;
        if ( !
startTextNode )
            return 
null ;
        
startIndex ;
    }

    if ( 
endContainer.nodeType == && w3cRange.endOffset )
    {
        
endTextNode endContainer ;
        
endIndex w3cRange.endOffset ;
    }
    else
    {
        
endTextNode domRange.EndNode ;
        while ( 
endTextNode.nodeType != )
            
endTextNode endTextNode.lastChild ;
        
endIndex endTextNode.length ;
    }

    var 
cursors = [] ;
    var 
current = new CharacterCursorstartTextNodestartIndex ) ;
    
cursors.pushcurrent ) ;
    if ( !( 
current.GetTextNode() == endTextNode && current.GetIndex() == endIndex ) && !domRange.CheckIsEmpty() )
    {
        do
        {
            
current current.Clone() ;
            
current.MoveNext() ;
            
cursors.pushcurrent ) ;
        }
        while ( !( 
current.GetTextNode() == endTextNode && current.GetIndex() == endIndex ) ) ;
    }

    return new 
CharacterRangecursorscursors.length ) ;
}

// Knuth-Morris-Pratt Algorithm for stream input
KMP_NOMATCH ;
KMP_ADVANCED ;
KMP_MATCHED ;
KmpMatch = function( patternignoreCase )
{
    var 
overlap = [ -] ;
    for ( var 
pattern.length i++ )
    {
        
overlap.pushoverlap[i] + ) ;
        while ( 
overlap] > && pattern.charAt) != pattern.charAtoverlap] - ) )
            
overlap] = overlapoverlap] - ] + ;
    }
    
this._Overlap overlap ;
    
this._State ;
    
this._IgnoreCase = ( ignoreCase === true ) ;
    if ( 
ignoreCase )
        
this.Pattern pattern.toLowerCase();
    else
        
this.Pattern pattern ;
}
KmpMatch.prototype = {
    
FeedCharacter : function( )
    {
        if ( 
this._IgnoreCase )
            
c.toLowerCase();

        while ( 
true )
        {
            if ( 
== this.Pattern.charAtthis._State ) )
            {
                
this._State++ ;
                if ( 
this._State == this.Pattern.length )
                {
                    
// found a match, start over, don't care about partial matches involving the current match
                    
this._State 0;
                    return 
KMP_MATCHED;
                }
                return 
KMP_ADVANCED ;
            }
            else if ( 
this._State == )
                return 
KMP_NOMATCH;
            else
                
this._State this._Overlapthis._State ];
        }

        return 
null ;
    },

    
Reset : function()
    {
        
this._State ;
    }
};

// Place a range at the start of document.
function OnLoad()
{
    
// First of all, translate the dialog box texts.
    
oEditor.FCKLanguageManager.TranslatePagedocument ) ;

    
// Show the appropriate tab at startup.
    
if ( dialogArguments.CustomValue == 'Find' )
    {
        
dialog.SetSelectedTab'Find' ) ;
        
dialog.SetAutoSizetrue ) ;
    }
    else
        
dialog.SetSelectedTab'Replace' ) ;

    
SelectField'txtFind' dialogArguments.CustomValue ) ;
}

function 
btnStat()
{
    
GetE('btnReplace').disabled =
        
GetE('btnReplaceAll').disabled =
            
GetE('btnFind').disabled =
                ( 
GetE(idMap["FindText"]).value.length == ) ;
}

function 
btnStatDelayed()
{
    
setTimeoutbtnStat) ;
}

function 
GetSearchString()
{
    return 
GetE(idMap['FindText']).value ;
}

function 
GetReplaceString()
{
    return 
GetE("txtReplace").value ;
}

function 
GetCheckCase()
{
    return !! ( 
GetE(idMap['CheckCase']).checked ) ;
}

function 
GetMatchWord()
{
    return !! ( 
GetE(idMap['CheckWord']).checked ) ;
}

/* Is this character a unicode whitespace or a punctuation mark?
 * References:
 * http://unicode.org/Public/UNIDATA/PropList.txt (whitespaces)
 * http://php.chinaunix.net/manual/tw/ref.regex.php (punctuation marks)
 */
function CheckIsWordSeparator)
{
    if ( !
)
        return 
true;
    var 
code c.charCodeAt);
    if ( 
code >= && code <= 0xd )
        return 
true;
    if ( 
code >= 0x2000 && code <= 0x200a )
        return 
true;
    switch ( 
code )
    {
        case 
0x20:
        case 
0x85:
        case 
0xa0:
        case 
0x1680:
        case 
0x180e:
        case 
0x2028:
        case 
0x2029:
        case 
0x202f:
        case 
0x205f:
        case 
0x3000:
            return 
true;
        default:
    }
    return /[.,
"'?!;:]/.test( c ) ;
}

FindRange = null ;
function _Find()
{
    var searchString = GetSearchString() ;
    if ( !FindRange )
        FindRange = new CharacterRange( new CharacterCursor( EditorDocument ), searchString.length ) ;
    else
    {
        FindRange.RemoveHighlight() ;
        FindRange = FindRange.GetNextRange( searchString.length ) ;
    }
    var matcher = new KmpMatch( searchString, ! GetCheckCase() ) ;
    var matchState = KMP_NOMATCH ;
    var character = '%' ;

    while ( character != null )
    {
        while ( ( character = FindRange.GetEndCharacter() ) )
        {
            matchState = matcher.FeedCharacter( character ) ;
            if ( matchState == KMP_MATCHED )
                break ;
            if ( FindRange.MoveNext() )
                matcher.Reset() ;
        }

        if ( matchState == KMP_MATCHED )
        {
            if ( GetMatchWord() )
            {
                var cursors = FindRange.GetCursors() ;
                var head = cursors[ cursors.length - 1 ].Clone() ;
                var tail = cursors[0].Clone() ;
                if ( !head.MoveNext() && !CheckIsWordSeparator( head.GetCharacter() ) )
                    continue ;
                if ( !tail.MoveBack() && !CheckIsWordSeparator( tail.GetCharacter() ) )
                    continue ;
            }

            FindRange.Highlight() ;
            return true ;
        }
    }

    FindRange = null ;
    return false ;
}

function Find()
{
    if ( ! _Find() )
        alert( FCKLang.DlgFindNotFoundMsg ) ;
}

function Replace()
{
    var saveUndoStep = function( selectRange )
    {
        var ieRange ;
        if ( oEditor.FCKBrowserInfo.IsIE )
            ieRange = document.selection.createRange() ;

        selectRange.Select() ;
        oEditor.FCKUndo.SaveUndoStep() ;
        var cloneRange = selectRange.Clone() ;
        cloneRange.Collapse( false ) ;
        cloneRange.Select() ;

        if ( ieRange )
            setTimeout( function(){ ieRange.select() ; }, 1 ) ;
    }

    if ( FindRange && FindRange.GetHighlightDomRange() )
    {
        var range = FindRange.GetHighlightDomRange() ;
        var bookmark = range.CreateBookmark() ;
        FindRange.RemoveHighlight() ;
        range.MoveToBookmark( bookmark ) ;

        saveUndoStep( range ) ;
        range.DeleteContents() ;
        range.InsertNode( EditorDocument.createTextNode( GetReplaceString() ) ) ;
        range._UpdateElementInfo() ;

        FindRange = CharacterRange.CreateFromDomRange( range ) ;
    }
    else
    {
        if ( ! _Find() )
        {
            FindRange && FindRange.RemoveHighlight() ;
            alert( FCKLang.DlgFindNotFoundMsg ) ;
        }
    }
}

function ReplaceAll()
{
    oEditor.FCKUndo.SaveUndoStep() ;
    var replaceCount = 0 ;

    while ( _Find() )
    {
        var range = FindRange.GetHighlightDomRange() ;
        var bookmark = range.CreateBookmark() ;
        FindRange.RemoveHighlight() ;
        range.MoveToBookmark( bookmark) ;

        range.DeleteContents() ;
        range.InsertNode( EditorDocument.createTextNode( GetReplaceString() ) ) ;
        range._UpdateElementInfo() ;

        FindRange = CharacterRange.CreateFromDomRange( range ) ;
        replaceCount++ ;
    }
    if ( replaceCount == 0 )
    {
        FindRange && FindRange.RemoveHighlight() ;
        alert( FCKLang.DlgFindNotFoundMsg ) ;
    }
    dialog.Cancel() ;
}

window.onunload = function()
{
    if ( FindRange )
    {
        FindRange.RemoveHighlight() ;
        FindRange.ToDomRange().Select() ;
    }
}
    </script>
</head>
<body onload="
OnLoad()" style="overflowhidden">
    <div id="
divFind" style="displaynone">
        <table cellspacing="
3" cellpadding="2" width="100%" border="0">
            <tr>
                <td nowrap="
nowrap">
                    <label for="
txtFindFind" fcklang="DlgReplaceFindLbl">
                        Find what:</label>
                </td>
                <td width="
100%">
                    <input id="
txtFindFind" onkeyup="btnStat()" oninput="btnStat()" onpaste="btnStatDelayed()" style="width100%" tabindex="1"
                        type="
text" />
                </td>
                <td>
                    <input id="
btnFind" style="width80px" disabled="disabled" onclick="Find();"
                        type="
button" value="Find" fcklang="DlgFindFindBtn" />
                </td>
            </tr>
            <tr>
                <td valign="
bottom" colspan="3">
                    &nbsp;<input id="
chkCaseFind" tabindex="3" type="checkbox" /><label for="chkCaseFind" fcklang="DlgReplaceCaseChk">Match
                        case</label>
                    <br />
                    &nbsp;<input id="
chkWordFind" tabindex="4" type="checkbox" /><label for="chkWordFind" fcklang="DlgReplaceWordChk">Match
                        whole word</label>
                </td>
            </tr>
        </table>
    </div>
    <div id="
divReplace" style="display:none">
        <table cellspacing="
3" cellpadding="2" width="100%" border="0">
            <tr>
                <td nowrap="
nowrap">
                    <label for="
txtFindReplace" fcklang="DlgReplaceFindLbl">
                        Find what:</label>
                </td>
                <td width="
100%">
                    <input id="
txtFindReplace" onkeyup="btnStat()" oninput="btnStat()" onpaste="btnStatDelayed()" style="width100%" tabindex="1"
                        type="
text" />
                </td>
                <td>
                    <input id="
btnReplace" style="width80px" disabled="disabled" onclick="Replace();"
                        type="
button" value="Replace" fcklang="DlgReplaceReplaceBtn" />
                </td>
            </tr>
            <tr>
                <td valign="
top" nowrap="nowrap">
                    <label for="
txtReplace" fcklang="DlgReplaceReplaceLbl">
                        Replace with:</label>
                </td>
                <td valign="
top">
                    <input id="
txtReplace" style="width100%" tabindex="2" type="text" />
                </td>
                <td>
                    <input id="
btnReplaceAll" style="width80px" disabled="disabled" onclick="ReplaceAll()" type="button"
                        value="
Replace All" fcklang="DlgReplaceReplAllBtn" />
                </td>
            </tr>
            <tr>
                <td valign="
bottom" colspan="3">
                    &nbsp;<input id="
chkCaseReplace" tabindex="3" type="checkbox" /><label for="chkCaseReplace" fcklang="DlgReplaceCaseChk">Match
                        case</label>
                    <br />
                    &nbsp;<input id="
chkWordReplace" tabindex="4" type="checkbox" /><label for="chkWordReplace" fcklang="DlgReplaceWordChk">Match
                        whole word</label>
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
?>
Онлайн: 0
Реклама