Link to home
Start Free TrialLog in
Avatar of louisiana_blues
louisiana_blues

asked on

Can an expert tell me what the following asp.net ajax jscript code does?

SInce I can't find a javascript or an ASP.NET AJAX forum here (Why???), I guess this is the best place to ask an ASP.NET AJAX javascript  question! ;-)

I hope an expert can comment the following scriptlet of javascript code (from the ajax htmleditor control in AjaxControlToolkit), and tell me what's going on.  I haven't a clue, mainly because of the prominent regex.

500 pts to the expert that can answer the question!  Thanks.
checkState : function() {
        if(!AjaxControlToolkit.HTMLEditor.ToolbarButton.FontName.callBaseMethod(this, "checkState")) return false;
    
        var editor = this._designPanel;
        var param =null;
        try{param = (Function.createDelegate(editor, AjaxControlToolkit.HTMLEditor._queryCommandValue))("fontname");} catch(e){}
 
        if(!editor._FontNotSet)
        if(!param || param.length==0) {
            param = AjaxControlToolkit.HTMLEditor.getStyle(editor._doc.body,"font-family");
        }
 
        var el   = this._select;
        var i=0;
        if(param && param.length > 0) {
            var seek = param.toLowerCase().split(",")[0].replace(/^(['"])/,"").replace(/(['"])$/,"");
 
            for(i=0; i< el.options.length; i++) {
                var cur = el.options.item(i).value.toLowerCase().split(",")[0];
                if(cur==seek) break
            }
            if(i==el.options.length) {
                try {
                    var newopt = document.createElement("OPTION");
                    newopt.value = param.replace(/^(['"])/,"").replace(/(['"])$/,"");
                    newopt.text  = param.split(",")[0].replace(/^(['"])/,"").replace(/(['"])$/,"");
                    el.add(newopt,(AjaxControlToolkit.HTMLEditor.isIE)?i:null);
                    $addHandler(newopt, "click", this._onclick_option$delegate);
                } catch(e) {
                    i = 0;
                }
            }
        }
        el.selectedIndex = i;
    }

Open in new window

Avatar of mark_martens
mark_martens

What i can see in this is that the html editor field is created. After that it checks if the input in the field has characters like /(['"])$/ and replaces them with "" (nothing).

I think this is a bit of code to avoid SQL injection into your database. Or validating the input against characters not allowed and removing them out of the input.

But i am not a java specialist.
Avatar of louisiana_blues

ASKER

Hey mark:

Well, I'm hoping to hear from an expert at some point, but you're on the right track I think.  However, what does the whole second part of the code do?  What's going on w/the loop w/the 'OPTION' element stuff?
ASKER CERTIFIED SOLUTION
Avatar of mark_martens
mark_martens

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Some feedback on this would be appreciated.
Thanks!  Sorry...my dad is ill and it's been hard to keep track of these things...