tags:

views:

195

answers:

6

Hello!

I've been tasked with rewriting the Javascript engine currently powering my customer's internal website. While reviewing the code I've come across this function flvFPW1 which I do not recognize, nor can I decipher the code(my Javascript knowledge is modest at best). A Google search gives me a few hits, but most if not all page hits are from the Javascript used on that particular page. In other words, I cannot find a description for this function, even though it is obviously used by others.

Can someone here enlighten me?

Thanks / Fredrik

A: 

I don't think it is a built in function, so it is just some function one of your team wrote.

It might be a function that Dreamweaver adds to a page to do something though...

rikh
+1  A: 

on your site, type in this in the location bar:

javascript:alert(flvFPW1);

it will report the function code

scunliffe
Exactly what I had in mind.
some
A: 

Install Firefox (http://www.mozilla.com/en-US/firefox/) and the FireBug extension(https://addons.mozilla.org/en-US/firefox/addon/1843). Use FireBug's DOM tab to find the function and click on it in the right column. It will take you to the file/line that the function is defined on.

Or open the HTML page in your favorite powerful text editor (like TextPad or TextMate) and do a Search/Find for the function name.

If you're saying that you've found the function but can't actually understand it, then you should probably paste the code in your question.

spilth
A: 

Google yields:

function flvFPW1() { // v1.3
    // Copyright 2002, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
    var v1 = arguments, v2 = v1[2].split(","), v3 = (v1.length > 3) ? v1[3] : false, v4 = (v1.length > 4) ? parseInt(v1[4]) : 0, v5 = (v1.length > 5) ? parseInt(v1[5]) : 0, v6, v7 = 0, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18;
    if (v4 > 1) {
        v10 = screen.width;
        for (v6 = 0; v6 < v2.length; v6++) {
            v18 = v2[v6].split("=");
            if (v18[0] == "width") {
                v8 = parseInt(v18[1]);
            }
            if (v18[0] == "left") {
                v9 = parseInt(v18[1]);
                v11 = v6;
            }
        }
        if (v4 == 2) {
            v7 = (v10 - v8) / 2;
            v11 = v2.length;
        } else if (v4 == 3) {
            v7 = v10 - v8 - v9;
        }
        v2[v11] = "left=" + v7;
    }
    if (v5 > 1) {
        v14 = screen.height;
        for (v6 = 0; v6 < v2.length; v6++) {
            v18 = v2[v6].split("=");
            if (v18[0] == "height") {
                v12 = parseInt(v18[1]);
            }
            if (v18[0] == "top") {
                v13 = parseInt(v18[1]);
                v15 = v6;
            }
        }
        if (v5 == 2) {
            v7 = (v14 - v12) / 2;
            v15 = v2.length;
        } else if (v5 == 3) {
            v7 = v14 - v12 - v13;
        }
        v2[v15] = "top=" + v7;
    }
    v16 = v2.join(",");
    v17 = window.open(v1[0], v1[1], v16);
    if (v3) {
        v17.focus();
    }
    document.MM_returnValue = false;
}

The URL in the comment leads to:

FlevOOware - Dreamweaver Extensions - Popup Link

Ates Goral
+4  A: 

My own research agrees that it's a dreamweaver extension: I found code for version 1.44 (scroll down some on this page) rather than 1.3:

function flvFPW1(){//v1.44
var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,
v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16;v11=
new Array("width,left,"+v4,"height,top,"+v5);for (i=0;i<v11.length;i++){v12=v11[i].split(",");l_iTarget=parseInt(v12[2]);
if (l_iTarget>1||v1[2].indexOf("%")>-1){v13=eval("screen."+v12[0]);
for (v6=0;v6<v2.length;v6++){v10=v2[v6].split("=");
if (v10[0]==v12[0]){v14=parseInt(v10[1]);if (v10[1].indexOf("%")>-1){v14=(v14/100)*v13;v2[v6]=v12[0]+"="+v14;}}
if (v10[0]==v12[1]){v16=parseInt(v10[1]);v15=v6;}}
if (l_iTarget==2){v7=(v13-v14)/2;v15=v2.length;}
else if (l_iTarget==3){v7=v13-v14-v16;}v2[v15]=v12[1]+"="+v7;}}v8=v2.join(",");v9=window.open(v1[0],v1[1],v8);
if (v3){v9.focus();}document.MM_returnValue=false;return v9;}

Which was, of course, passed through a compressor to save bandwidth making it very hard to read. I spent a little bit of time un-obfuscating it before I realized that I could get better results by adding "dreamweaver" to my search string. Doing that I was able to find some more interesting documentation:

http://www.flevooware.nl/dreamweaver/extdetails.asp?extID=8 (short description) http://satsuki.altervista.org/basibloggers/source40.txt (full script code, in italian)

In short: it's basically just a wrapper for window.open. Here's the progress I made translating the code:

function flvFPW1()
{//v1.44
 var v1=arguments;  // pass v1[0] and v1[1] directly to window.open
 var arg3=v1[2].split(",");
 var focusNewWindow=(v1.length>3)?v1[3]:false;
 var newWindowWidth=(v1.length>4)?parseInt(v1[4]):0;
 var newWindowHeight=(v1.length>5)?parseInt(v1[5]):0;

 var adjustedWindowPosition=0,result,keyValuePair,AxisProperty;
 var windowSize,sizeValue,arg3Index,anchorValue;

 var hwArray= new Array("width,left,"+newWindowWidth,"height,top,"+newWindowHeight);
 for (i=0;i<hwArray.length;i++)  // x-axis, then y-axis
 {
  AxisProperty=hwArray[i].split(","); // {"width", "left", 0}  or {"height", "top", 0}
  l_iTarget=parseInt(AxisProperty[2]);  // l_iTarget defined where?

  if (l_iTarget>1||v1[2].indexOf("%")>-1)  
  {
   screenSize=eval("screen."+AxisProperty[0]); // x or y size of the window
   for (var i=0;i<arg3.length;i++)
   {
    keyValuePair=arg3[i].split("=");
    if (keyValuePair[0]==AxisProperty[0]) // if the key is (width|height)
    {
     sizeValue=parseInt(keyValuePair[1]);
     if (keyValuePair[1].indexOf("%")>-1)
     {
      sizeValue=(sizeValue/100)* screenSize;
      arg3[i]=AxisProperty[0]+"="+sizeValue;
     }
    }

    if (keyValuePair[0]==AxisProperty[1])  // if the key is (left|top)
    {
     anchorValue=parseInt(keyValuePair[1]);
     arg3Index=i;
    }
   }
   if (l_iTarget==2)
   {
    adjustedWindowPosition=(screenSize-sizeValue)/2; // will center the window on this axix
    arg3Index=arg3.length;
   }
   else if (l_iTarget==3)
   {
    adjustedWindowPosition= screenSize-sizeValue-anchorValue;
   }
   arg3[arg3Index]=AxisProperty[1]+"="+adjustedWindowPosition;  // (left|top) = value
  }
 }
 var newArg3=arg3.join(",");
 result=window.open(v1[0],v1[1],newArg3);
 if (focusNewWindow)
 {
  result.focus();
 }

 document.MM_returnValue=false;
 return result;
}
Joel Coehoorn
To the rescue: http://www.howtocreate.co.uk/tutorials/jsexamples/JSTidy.html
Ates Goral
That much didn't take long: what I've been doing is also giving the variables meaningful names and adding comments.
Joel Coehoorn
A: 

Thanks for helping out guys! spilth: Yes I found the function in the js-file but couldn't comprehend the code. Since I found the same function on several other pages that were not related to my customer's page I assumed its purpose would already be known by other people.. so I didn't bother with posting the code. I will next time though.

Best Regards

westmark