Questions

Will a Javascript programmer please decipher the following?

Tags:
+
0 Votes
Locked

Will a Javascript programmer please decipher the following?

Tink!
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

What does the above code actually do? By the way I had to insert a space into 2 areas where the code read: since TR deciphers that as italics tag. LOL

Thanks! Tink
  • +
    0 Votes
    robo_dev

    This is a Macromedia DreamWeaver JavaScript script that specifies the Swap Image behavior for rollovers (and hides the Swap Image function from browsers that don't support JavaScript).

    adobe DOT com/support/dreamweaver/programs/navbar_overview/navbar_overview04.html

    +
    0 Votes
    Tink!

    Well then, here I thought the original creators of this webpage were brilliant programmers - only to find out that they were probably using a software that assisted them in creating the scripts. lol.

    What I need to know, since I am reverse engineering this code, is what part does the above code play in the Swap Image process? I already have the other parts that actually do the swapping, I want to know what "object" is this findObj function actually looking for?

    Or - in simpler terms - how does the Rollover script tell which image it needs to swap?

    +
    0 Votes
    Tink!

    I figured out how to get the rollover script to single out each different rollover...and it has nothing to do with the above script.

    Can you explain the commands that are used in this script?

    +
    0 Votes
    richardhx

    Searching using google for "Explain MM_findObj" brings up some fairly good possibles.
    If you look at the code you can see that it is all about locating an image's id that needs to be used. So that the browser can be told what to do with that image as referenced by it's id.
    There are different sections as some browsers operate in a different way.

    Reverse engineering implies you do not know what is inside, but this is the code - the inside, so you can research it . javascript is not my strength, but it is fairly readable and with a few references You can work it out step by step.

    the function looks like multiple entries of
    if (condition(test) is met. make x equal to the extracted identity from the image being referenced. pass x back to whatever has asked for MM_findObj(n,d))

    This script section is not commands but defining the function MM_findObj obtaining attributes or an id for an object. If you are interested, why not search in more detail for javascript tutorials and see what each element is doing. Reverse engineering implies you do not know what is inside, but this is the code - the inside, so you can research it . javascript is not my main strength, but it is fairly readable.

    +
    0 Votes
    Tink!

    Trust me, I usually do google before I come to TR

    I was just trying to go a little quicker by perhaps bypassing some reading.

    +
    0 Votes
    robo_dev

    Most people cannot even forward-engineer it properly :)

    Not sure if you're reverse engineering the function or an app that uses the function?

    I could be 100% making all this up but.....

    At a high level, of course, this a a Macromedia function.

    Not sure if this helps, but, first of all here is the code:
    lab DOT artlung DOT com/mm_validateform/

    justskins DOT com/forums/what-is-function-mm_findobj-69683.html

    Not sure if this is the question you're asking, but I believe the purpose of this function is to
    create an array with image values so the other functions swap the button images in the toolbar when you rollover them.

    adobe DOT com/support/dreamweaver/programs/navbar_overview/navbar_overview04.html

    +
    0 Votes
    Tink!

    Yea, I realized that this was a code created by Adobe, but of course, they do not explain each line. At least not on the pages I visited.

    What I am trying to figure out is: Why this snippet of code is even necessary for the image swap function.

    I was using some reverse engineered functions based on the Image swap code to change text rather than images, and at first could not get it to do more than one line on a page. I thought it might have to do with the FindObj function which the Image Swap functions call, (and my Text functions do not call). But then I figured out that adding unique IDs to my lines allowed them to do the style swapping just fine.

    Sooo, I want to know why does the Image Swap function call for this FindObj function and what is FindObj looking for?

    +
    0 Votes
    jfdawes

    It's not really image related. Short story is It's trying to find a DOM object that is called whatever is given as the first argument. This is quite similar to the function of getElementById but it provides support for IE4 and will look through a framed document's parent (under the right conditions) and also recurses through layers.

    You haven't really said why you need it, but you can perhaps get by with just using getElementById

    +
    0 Votes
    Tink!

    Exactly! I do not know why the FindObj is needed.

    It seemed like awfully complicated code just to find the object to swap.

  • +
    0 Votes
    robo_dev

    This is a Macromedia DreamWeaver JavaScript script that specifies the Swap Image behavior for rollovers (and hides the Swap Image function from browsers that don't support JavaScript).

    adobe DOT com/support/dreamweaver/programs/navbar_overview/navbar_overview04.html

    +
    0 Votes
    Tink!

    Well then, here I thought the original creators of this webpage were brilliant programmers - only to find out that they were probably using a software that assisted them in creating the scripts. lol.

    What I need to know, since I am reverse engineering this code, is what part does the above code play in the Swap Image process? I already have the other parts that actually do the swapping, I want to know what "object" is this findObj function actually looking for?

    Or - in simpler terms - how does the Rollover script tell which image it needs to swap?

    +
    0 Votes
    Tink!

    I figured out how to get the rollover script to single out each different rollover...and it has nothing to do with the above script.

    Can you explain the commands that are used in this script?

    +
    0 Votes
    richardhx

    Searching using google for "Explain MM_findObj" brings up some fairly good possibles.
    If you look at the code you can see that it is all about locating an image's id that needs to be used. So that the browser can be told what to do with that image as referenced by it's id.
    There are different sections as some browsers operate in a different way.

    Reverse engineering implies you do not know what is inside, but this is the code - the inside, so you can research it . javascript is not my strength, but it is fairly readable and with a few references You can work it out step by step.

    the function looks like multiple entries of
    if (condition(test) is met. make x equal to the extracted identity from the image being referenced. pass x back to whatever has asked for MM_findObj(n,d))

    This script section is not commands but defining the function MM_findObj obtaining attributes or an id for an object. If you are interested, why not search in more detail for javascript tutorials and see what each element is doing. Reverse engineering implies you do not know what is inside, but this is the code - the inside, so you can research it . javascript is not my main strength, but it is fairly readable.

    +
    0 Votes
    Tink!

    Trust me, I usually do google before I come to TR

    I was just trying to go a little quicker by perhaps bypassing some reading.

    +
    0 Votes
    robo_dev

    Most people cannot even forward-engineer it properly :)

    Not sure if you're reverse engineering the function or an app that uses the function?

    I could be 100% making all this up but.....

    At a high level, of course, this a a Macromedia function.

    Not sure if this helps, but, first of all here is the code:
    lab DOT artlung DOT com/mm_validateform/

    justskins DOT com/forums/what-is-function-mm_findobj-69683.html

    Not sure if this is the question you're asking, but I believe the purpose of this function is to
    create an array with image values so the other functions swap the button images in the toolbar when you rollover them.

    adobe DOT com/support/dreamweaver/programs/navbar_overview/navbar_overview04.html

    +
    0 Votes
    Tink!

    Yea, I realized that this was a code created by Adobe, but of course, they do not explain each line. At least not on the pages I visited.

    What I am trying to figure out is: Why this snippet of code is even necessary for the image swap function.

    I was using some reverse engineered functions based on the Image swap code to change text rather than images, and at first could not get it to do more than one line on a page. I thought it might have to do with the FindObj function which the Image Swap functions call, (and my Text functions do not call). But then I figured out that adding unique IDs to my lines allowed them to do the style swapping just fine.

    Sooo, I want to know why does the Image Swap function call for this FindObj function and what is FindObj looking for?

    +
    0 Votes
    jfdawes

    It's not really image related. Short story is It's trying to find a DOM object that is called whatever is given as the first argument. This is quite similar to the function of getElementById but it provides support for IE4 and will look through a framed document's parent (under the right conditions) and also recurses through layers.

    You haven't really said why you need it, but you can perhaps get by with just using getElementById

    +
    0 Votes
    Tink!

    Exactly! I do not know why the FindObj is needed.

    It seemed like awfully complicated code just to find the object to swap.