views:

142

answers:

3

I just implemented a multi-language mod onto my website.

Problem is that there seems to be a conflict between the javascript files from the language mod and the javascript files that already were on the page.

<!-- language files here -->
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/translationEngine.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script> 
<script type="text/javascript" src="js/jquery.translate-1.3.9.min.js"></script>
<script>var browserlang = 'en';</script> 


<!-- Javascript -->

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.pngFix.pack.js"></script>
<script type="text/javascript" src="js/jquery.flow.1.2.min.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="js/concept.js"></script>

js/jquery-1.3.2.min.js is what makes the 3 image slider on the homepage work, but... it seems to also be interfering with the functions of the translator.

If u remove js/jquery-1.3.2.min.js from the page, the translator works fine, but the slider no longer works.

removing js/jquery-1.4.2.min.js from the page doesnt make the translator work either, in fact it seems to cause more errors in the back.

Can someone guide me in the right direction that would allow me to make the language translator and image slider both work?

http://filefx.com

Thanks :)

+4  A: 

Check out the jQuery noConflict function. This function tells jQuery to relinquish it's control over the $ variable. This way, other libraries can use it.

The online docs give a pretty good guide as to how to use this function. It saved me a few times.

Example from the online docs:

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>

Basically, once you call noConflict, you can still use jQuery, just use it using the jQuery variable name instead of $.

Hope this helps!

David Hoerster
The `.noConflict()` doesn't really help the situation of having multiple **jQuery** libraries on the page, these don't play nicely at all, it's intended for use with jQuery and *another* library.
Nick Craver
I know this is getting upvoted...I'm not sure why, for anyone that finds this later: *this will not solve the issue*, the `jQuery` variable is being redefined with the second inclusion of a jQuery library. It's both an unnecessarily heavier and slower page as well as won't correctly solve the issue.
Nick Craver
I agree with @Nick. You can't define a variable with a value, *overwrite* that variable with a new value, then expect `noConflict()` (or any other method for that matter) to let you reference the old, overwritten value. The `noConflict()` method resolves conflicts with `window.$`, not with `window.jQuery`.
patrick dw
+3  A: 

The short version is to remove this:

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

And update your plugins, there are likely 1.4.x versions out there for each of them. By including jQuery a second time, like you are currently, it'll wipe out plugins and cause all sorts of issues...the first step is removing the second (hopefully the older) instance.

Edit: Here's an updated version of jFlow called jFlow plus that works with 1.4.2.

Nick Craver
Shouldn't be many breaking changes from 1.3.2 to 1.4.2?
Mark
@Mark - There shouldn't, but it seems the jFlow plugin has some break...but the plugin's site is offline at this exact moment, so I can't provide a link to the current version: http://plugins.jquery.com/project/jFlow
Nick Craver
*Shouldn't be* -> famous developer's last words :P
alex
A: 

I ended up just changing the order in which the libraries loaded.

I let all the jquery libraries load first, from newest to oldest. Then i called for the javascript files that rely on jquery.

It works fine now.

jiexi
This isn't a great approach...it's a much heavier page for your client. Why *not* just upgrade the flow plugin (I provided an updated link my answer), leave out jQuery 1.3.2 and make your page lighter and faster for your users?
Nick Craver
ya, that'd be a great idea. lol ok using your method now.
jiexi