Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same Varible Name Errors 1

Status
Not open for further replies.

jammer1221

Programmer
Jul 30, 2003
352
US
Hi All,

I am having some trouble implementing a script! On our site I have a script that creates a dynamic menu, which is on every page in the site. I am creating a photo gallery which is based on the prototype framework (The photo gallery script is LightBox 2). Whats happening is a lot of the menus script has the same function and variable names as the prototype script. So, as you can guess, JS errors are being thrown everywhere.

Does anyone have any suggestions as to what I should do? Also, is it possible to go through the entire script and "find & replace" all the varible and function names with unique names? I would do this on the menu script as it only has 600 lines of code.

Thanks for the help!
Matt
 
You could open the menu script and replace all occurrences of "function " with "function menu", which would change, for example:

Code:
function doSomething(args) {}

to

Code:
function menudoSomething(args) {}

Then you'd just need to update the references in the menu script.

I don't know of any automated tools to do this for Javascvript... perhaps Eclipse with the Aptana plugin might, or IntelliJ?

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan,
I think that's what I'm going to do. As far as how I'm going to do it, I have a bookmarklet that runs through the script a gathers all of the vars and functions. I'm going to run that on both scripts find out which ones are identical and then change the name.

But, as far as you know theres no way to live with both scripts untouched?
I guess I could put something in an iframe (sorry, I just had that thought)...

Thanks for you're help,
Matt
 
Yes - you could use the iframe, although you'd need to update an reference to xxx (where xxx is a variable or function name) to be "iframeObject.xxx" or possibly some method to get the iframe content window for some browsers.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Well I would just put the script inside of the iframe, instead of the parent window/document...Either way that looks like the best idea!

Thanks for the help Dan

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top