Вход Регистрация
Файл: upload/static/jscript/editarea/highlight.js
Строк: 735
<?php
// change_to: "on" or "off"
    
EditArea.prototype.change_highlight= function(change_to){
        if(
this.settings["syntax"].length==&& change_to==false){
            
this.switchClassSticky(_$("highlight"), 'editAreaButtonDisabled'true);
            
this.switchClassSticky(_$("reset_highlight"), 'editAreaButtonDisabled'true);
            return 
false;
        }
        
        if(
this.do_highlight==change_to)
            return 
false;
    
            
        
this.getIESelection();
        var 
pos_startthis.textarea.selectionStart;
        var 
pos_endthis.textarea.selectionEnd;
        
        if(
this.do_highlight===true || change_to==false)
            
this.disable_highlight();
        else
            
this.enable_highlight();
        
this.textarea.focus();
        
this.textarea.selectionStart pos_start;
        
this.textarea.selectionEnd pos_end;
        
this.setIESelection();
                
    };
    
    
EditArea.prototype.disable_highlight= function(displayOnly){
        var 
tthisa=t.textareanew_Objold_classnew_class;
            
        
t.selection_field.innerHTML="";
        
t.selection_field_text.innerHTML="";
        
t.content_highlight.style.visibility="hidden";
        
// replacing the node is far more faster than deleting it's content in firefox
        
new_Objt.content_highlight.cloneNode(false);
        
new_Obj.innerHTML"";            
        
t.content_highlight.parentNode.insertBefore(new_Objt.content_highlight);
        
t.content_highlight.parentNode.removeChild(t.content_highlight);    
        
t.content_highlightnew_Obj;
        
old_classparent.getAttributea,"class" );
        if(
old_class){
            
new_classold_class.replace"hidden","" );
            
parent.setAttributea"class"new_class );
        }
    
        
a.style.backgroundColor="transparent";    // needed in order to see the bracket finders
        
        //var icon= document.getElementById("highlight");
        //setAttribute(icon, "class", getAttribute(icon, "class").replace(/ selected/g, "") );
        //t.restoreClass(icon);
        //t.switchClass(icon,'editAreaButtonNormal');
        
t.switchClassSticky(_$("highlight"), 'editAreaButtonNormal'true);
        
t.switchClassSticky(_$("reset_highlight"), 'editAreaButtonDisabled'true);
    
        
t.do_highlight=false;
    
        
t.switchClassSticky(_$("change_smooth_selection"), 'editAreaButtonSelected'true);
        if(
typeof(t.smooth_selection_before_highlight)!="undefined" && t.smooth_selection_before_highlight===false){
            
t.change_smooth_selection_mode(false);
        }
        
    
//    this.textarea.style.backgroundColor="#FFFFFF";
    
};

    
EditArea.prototype.enable_highlight= function(){
        var 
t=thisa=t.textareanew_class;
        
t.show_waiting_screen();
            
        
t.content_highlight.style.visibility="visible";
        
new_class    =parent.getAttribute(a,"class")+" hidden";
        
parent.setAttributea"class"new_class );
        
        
// IE can't manage mouse click outside text range without this
        
if( t.isIE )
            
a.style.backgroundColor="#FFFFFF";    

        
t.switchClassSticky(_$("highlight"), 'editAreaButtonSelected'false);
        
t.switchClassSticky(_$("reset_highlight"), 'editAreaButtonNormal'false);
        
        
t.smooth_selection_before_highlight=t.smooth_selection;
        if(!
t.smooth_selection)
            
t.change_smooth_selection_mode(true);
        
t.switchClassSticky(_$("change_smooth_selection"), 'editAreaButtonDisabled'true);
        
        
        
t.do_highlight=true;
        
t.resync_highlight();
                    
        
t.hide_waiting_screen();    
    };
    
    
/**
     * Ask to update highlighted text
     * @param Array infos - Array of datas returned by EditArea.get_selection_infos()
     */
    
EditArea.prototype.maj_highlight= function(infos){
        
// for speed mesure
        
var debug_opti="",tps_start= new Date().getTime(), tps_middle_opti=new Date().getTime();
        var 
t=thishightlighted_textupdated_highlight;    
        var 
textToHighlight=infos["full_text"], doSyntaxOpti falsedoHtmlOpti falsestay_begin=""stay_end=""trace_new trace_last;
        
        if(
t.last_text_to_highlight==infos["full_text"] && t.resync_highlight!==true)
            return;
                    
        
//  OPTIMISATION: will search to update only changed lines
        
if(t.reload_highlight===true){
            
t.reload_highlight=false;
        }else if(
textToHighlight.length==0){
            
textToHighlight="n ";
        }else{
            
// get text change datas
            
changes t.checkTextEvolution(t.last_text_to_highlight,textToHighlight);
            
            
// check if it can only reparse the changed text
            
trace_new        t.get_syntax_trace(changes.newTextLine).replace(/r/g'');
            
trace_last        t.get_syntax_trace(changes.lastTextLine).replace(/r/g'');
            
doSyntaxOpti    = ( trace_new == trace_last );
            
            
// check if the difference comes only from a new line created 
            // => we have to remember that the editor can automaticaly add tabulation or space after the new line) 
            
if( !doSyntaxOpti && trace_new == "n"+trace_last && /^[ ts]*nts]*$/.testchanges.newText.replace(/r/g'') ) && changes.lastText =="" )
            {
                
doSyntaxOpti    true;
            }
            
            
// we do the syntax optimisation
            
if( doSyntaxOpti ){
                        
                
tps_middle_opti=new Date().getTime();    
            
                
stay_begint.last_hightlighted_text.split("n").slice(0changes.lineStart).join("n");
                if(
changes.lineStart>0)
                    
stay_begin+= "n";
                
stay_endt.last_hightlighted_text.split("n").slice(changes.lineLastEnd+1).join("n");
                if(
stay_end.length>0)
                    
stay_end"n"+stay_end;
                    
                
// Final check to see that we're not in the middle of span tags
                
if( stay_begin.split('<span').length != stay_begin.split('</span').length 
                    
|| stay_end.split('<span').length != stay_end.split('</span').length )
                {
                    
doSyntaxOpti    false;
                    
stay_end        '';
                    
stay_begin        '';
                }
                else
                {
                    if(
stay_begin.length==&& changes.posLastEnd==-1)
                        
changes.newTextLine+="n";
                    
textToHighlight=changes.newTextLine;
                }
            }
            if(
t.settings["debug"]){
                var 
ch =changes;
                
debug_opti= ( doSyntaxOpti?"Optimisation""No optimisation" )
                    +
" start: "+ch.posStart +"("+ch.lineStart+")"
                    
+" end_new: "ch.posNewEnd+"("+ch.lineNewEnd+")"
                    
+" end_last: "ch.posLastEnd+"("+ch.lineLastEnd+")"
                    
+"nchanged_text: "+ch.newText+" => trace: "+trace_new
                    
+"nchanged_last_text: "+ch.lastText+" => trace: "+trace_last
                    
//debug_opti+= "nchanged: "+ infos["full_text"].substring(ch.posStart, ch.posNewEnd);
                    
"nchanged_line: "+ch.newTextLine
                    
"nlast_changed_line: "+ch.lastTextLine
                    
+"nstay_begin: "stay_begin.slice(-100)
                    +
"nstay_end: "stay_end.substr0100 );
                    
//debug_opti="start: "+stay_begin_len+ "("+nb_line_start_unchanged+") end: "+ (stay_end_len)+ "("+(splited.length-nb_line_end_unchanged)+") ";
                    //debug_opti+="changed: "+ textToHighlight.substring(stay_begin_len, textToHighlight.length-stay_end_len)+" n";
                    
                    //debug_opti+="changed: "+ stay_begin.substr(stay_begin.length-200)+ "----------"+ textToHighlight+"------------------"+ stay_end.substr(0,200) +"n";
                    
+"n";
            }
    
            
            
// END OPTIMISATION
        
}

        
tps_end_opti    = new Date().getTime();    
                
        
// apply highlight
        
updated_highlight    t.colorize_text(textToHighlight);
        
tpsAfterReg            = new Date().getTime();
        
        
/***
         * see if we can optimize for updating only the required part of the HTML code
         * 
         * The goal here will be to find the text node concerned by the modification and to update it
         */
        //-------------------------------------------
        // 
        
if( doSyntaxOpti )
        {
            try
            {
                var 
replacedBlocinbStart ''nbEnd ''newHtmllengthOldlengthNew;
                
replacedBloc        t.last_hightlighted_text.substringstay_begin.lengtht.last_hightlighted_text.length stay_end.length );
                
                
lengthOld    replacedBloc.length;
                
lengthNew    updated_highlight.length;
                
                
// find the identical caracters at the beginning
                
for( i=0lengthOld && lengthNew && replacedBloc.charAt(i) == updated_highlight.charAt(i) ; i++ )
                {
                }
                
nbStart i;
                
// find the identical caracters at the end
                
for( i=0nbStart lengthOld && nbStart lengthNew && replacedBloc.charAt(lengthOld-i-1) == updated_highlight.charAt(lengthNew-i-1) ; i++ )
                {
                }
                
nbEnd    i;
                
                
// get the changes
                
lastHtml    replacedBloc.substringnbStartlengthOld nbEnd );
                
newHtml        updated_highlight.substringnbStartlengthNew nbEnd );
                
                
                
// We can do the optimisation only if we havn't touch to span elements
                
if( newHtml.indexOf('<span') == -&& newHtml.indexOf('</span') == -
                    
&& lastHtml.indexOf('<span') == -&& lastHtml.indexOf('</span') == -)
                {
                    var 
beginStrnbOpendedSpannbClosedSpannbUnchangedCharsspantextNode;
                    
doHtmlOpti        true;
                    
beginStr        t.last_hightlighted_text.substr0stay_begin.length nbStart );
            
                    
nbOpendedSpan    beginStr.split('<span').length 1;
                    
nbClosedSpan    beginStr.split('</span').length 1;
                    
// retrieve the previously opened span (Add 1 for the first level span?)
                    
span             t.content_highlight.getElementsByTagName('span')[ nbOpendedSpan ];
                    
                    
//--------[
                    // get the textNode to update
                    
                    // if we're inside a span, we'll take the one that is opened (can be a parent of the current span)
                    
parentSpan        span;
                    
maxStartOffset    maxEndOffset 0;
                    
                    
// it will be in the child of the root node 
                    
if( nbOpendedSpan == nbClosedSpan )
                    {
                        while( 
parentSpan.parentNode != t.content_highlight && parentSpan.parentNode.tagName != 'PRE' )
                        {
                            
parentSpan    parentSpan.parentNode;
                        }
                    }
                    
// get the last opened span
                    
else
                    {
                        
maxStartOffset    maxEndOffset beginStr.length 1;
                        
// move to parent node for each closed span found after the lastest open span
                        
nbClosed beginStr.substrMath.max0beginStr.lastIndexOf'<span'maxStartOffset ) ) ).split('</span').length 1;
                        while( 
nbClosed )
                        {
                            
nbClosed--;
                            
parentSpan parentSpan.parentNode;
                        }
                        
                        
// find the position of the last opended tag
                        
while( parentSpan.parentNode != t.content_highlight && parentSpan.parentNode.tagName != 'PRE' && ( tmpMaxStartOffset Math.max0beginStr.lastIndexOf'<span'maxStartOffset ) ) ) < ( tmpMaxEndOffset Math.max0beginStr.lastIndexOf'</span'maxEndOffset ) ) ) )
                        {
                            
maxStartOffset    tmpMaxStartOffset;
                            
maxEndOffset    tmpMaxEndOffset;
                        }
                    }
                    
// Note: maxEndOffset is no more used but maxStartOffset will be used
                    
                    
if( parentSpan.parentNode == t.content_highlight || parentSpan.parentNode.tagName == 'PRE' )
                    {
                        
maxStartOffset    Math.max0beginStr.indexOf'<span' ) );
                    }
                    
                    
// find the matching text node (this will be one that will be at the end of the beginStr
                    
if( maxStartOffset == beginStr.length )
                    {
                        
nbSubSpanBefore    0;
                    }
                    else
                    {
                        
lastEndPos                 Math.max0beginStr.lastIndexOf'>'maxStartOffset ) );
        
                        
// count the number of sub spans
                        
nbSubSpanBefore            beginStr.substrlastEndPos ).split('<span').length-1;
                    }
                    
                    
// there is no sub-span before
                    
if( nbSubSpanBefore == )
                    {
                        
textNode    parentSpan.firstChild;
                    }
                    
// we need to find where is the text node modified
                    
else
                    {
                        
// take the last direct child (no sub-child)
                        
lastSubSpan    parentSpan.getElementsByTagName('span')[ nbSubSpanBefore ];
                        while( 
lastSubSpan.parentNode != parentSpan )
                        {
                            
lastSubSpan    lastSubSpan.parentNode;
                        }

                        
// associate to next text node following the last sub span
                        
if( lastSubSpan.nextSibling == null || lastSubSpan.nextSibling.nodeType != )
                        {
                            
textNode    document.createTextNode('');
                            
lastSubSpan.parentNode.insertBeforetextNodelastSubSpan.nextSibling );
                        }
                        else
                        {
                            
textNode    lastSubSpan.nextSibling;
                        }
                    }
                    
//--------]
                    
                    
                    //--------[
                    // update the textNode content
                    
                    // number of caracters after the last opened of closed span
                    
nbUnchangedChars beginStr.length Math.max0beginStr.lastIndexOf'>' ) + );
                    
                    
//    console.log( span, textNode, nbOpendedSpan,nbClosedSpan,  span.nextSibling, textNode.length, nbUnchangedChars, lastHtml, lastHtml.length, newHtml, newHtml.length );
                    //    alert( textNode.parentNode.className +'-'+ textNode.parentNode.tagName+"n"+ textNode.data +"n"+ nbUnchangedChars +"n"+ lastHtml.length +"n"+ newHtml +"n"+ newHtml.length  );
                    
                    // IE only manage r for cariage return in textNode and not n or rn
                    
if( t.isIE )
                    {
                        
nbUnchangedChars    -= ( beginStr.substrbeginStr.length nbUnchangedChars ).split("n").length );
                        
//alert( textNode.data.replace(/r/g, '_r').replace(/n/g, '_n')); 
                        
textNode.replaceDatanbUnchangedCharslastHtml.replace(/n/g'').lengthnewHtml.replace(/n/g'') );
                    }
                    else
                    {
                        
textNode.replaceDatanbUnchangedCharslastHtml.lengthnewHtml );
                    }
                    
//--------]
                
}
            }
            
// an exception shouldn't occured but if replaceData failed at least it won't break everything
            
catch( )
            {
        
//        throw e;
        //        console.log( e );
                
doHtmlOpti    false;
            }
            
        }
        
/*** END HTML update's optimisation ***/
        // end test
        
    //            console.log(  (TPS6-TPS5), (TPS5-TPS4), (TPS4-TPS3), (TPS3-TPS2), (TPS2-TPS1), _CPT );
        // get the new highlight content
        
tpsAfterOpti2        = new Date().getTime();
        
hightlighted_text    stay_begin updated_highlight stay_end;
        if( !
doHtmlOpti )
        {
            
// update the content of the highlight div by first updating a clone node (as there is no display in the same time for t node it's quite faster (5*))
            
var new_Objt.content_highlight.cloneNode(false);
            if( ( 
t.isIE && t.isIE ) || ( t.isOpera && t.isOpera 9.6 ) )
                
new_Obj.innerHTML"<pre><span class='"t.settings["syntax"] +"'>" hightlighted_text "</span></pre>";    
            else
                
new_Obj.innerHTML"<span class='"t.settings["syntax"] +"'>"hightlighted_text +"</span>";
    
            
t.content_highlight.parentNode.replaceChild(new_Objt.content_highlight);
        
            
t.content_highlightnew_Obj;
        }
        
        
t.last_text_to_highlightinfos["full_text"];
        
t.last_hightlighted_texthightlighted_text;
        
        
tps3=new Date().getTime();
    
        if(
t.settings["debug"]){
            
//lineNumber=tab_text.length;
            //t.debug.value+=" nNB char: "+_$("src").value.length+" Nb line: "+ lineNumber;
        
            
t.debug.value"Tps optimisation "+(tps_end_opti-tps_start)
                +
" | tps reg exp: "+ (tpsAfterReg-tps_end_opti)
                +
" | tps opti HTML : "+ (tpsAfterOpti2-tpsAfterReg) + ' '+ ( doHtmlOpti 'yes' 'no' )
                +
" | tps update highlight content: "+ (tps3-tpsAfterOpti2)
                +
" | tpsTotal: "+ (tps3-tps_start)
                + 
"("+tps3+")n"debug_opti;
        
//    t.debug.value+= "highlightn"+hightlighted_text;*/
        
}
        
    };
    
    
EditArea.prototype.resync_highlight= function(reload_now){
        
this.reload_highlight=true;
        
this.last_text_to_highlight="";
        
this.focus();        
        if(
reload_now)
            
this.check_line_selection(false); 
    };
?>
Онлайн: 3
Реклама