Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2013, 08:27 PM   PM User | #1
samuelito.mcf
New Coder

 
Join Date: Jan 2013
Location: Oregon
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
samuelito.mcf is an unknown quantity at this point
Exclamation Using more than one Jquery plugin at a time?

I have one jquery plugin that stretches the background image (Backstretch) and another that is a picture slideshow/accordion (Slidorion). My problem is that one will never work while the other exists, but on their own they work fine. Backstretch is used in my master page so it makes up the background on all my pages while slidorion is only on one page. How do I seperate them some how so they aren't affecting each other?

Last edited by samuelito.mcf; 01-31-2013 at 08:15 PM.. Reason: make resolved
samuelito.mcf is offline   Reply With Quote
Old 01-30-2013, 08:59 PM   PM User | #2
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 364
Thanks: 3
Thanked 43 Times in 43 Posts
Airblader can only hope to improve
The simplest thing to try – and thus the first thing to try – is rearranging the order you load the plugins. It sounds silly, but sometimes it helps.

However, I only give that a fairly small chance. After that, it's time to figure out what is going wrong. If both plugins truly conflict in the sense that they are writing over each others' variables, you have a problem.

I never encountered this before, but my first idea would be trying to trap each plugin in a closure. That way, whatever (formerly) global objects they shared (that caused the interference) are now within a plugin-specific closure. You'd have to think about how you can make the plugin available from outside that closure then, though.
Airblader is offline   Reply With Quote
Old 01-31-2013, 04:45 PM   PM User | #3
samuelito.mcf
New Coder

 
Join Date: Jan 2013
Location: Oregon
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
samuelito.mcf is an unknown quantity at this point
Quote:
Originally Posted by Airblader View Post
The simplest thing to try – and thus the first thing to try – is rearranging the order you load the plugins. It sounds silly, but sometimes it helps.

However, I only give that a fairly small chance. After that, it's time to figure out what is going wrong. If both plugins truly conflict in the sense that they are writing over each others' variables, you have a problem.

I never encountered this before, but my first idea would be trying to trap each plugin in a closure. That way, whatever (formerly) global objects they shared (that caused the interference) are now within a plugin-specific closure. You'd have to think about how you can make the plugin available from outside that closure then, though.

How do I trap each plugin in a closure?
samuelito.mcf is offline   Reply With Quote
Old 01-31-2013, 05:33 PM   PM User | #4
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 364
Thanks: 3
Thanked 43 Times in 43 Posts
Airblader can only hope to improve
If and how this works heavily depends on how the plugins are written, so before going into this trouble you might wanna check what's actually causing the interference. In any case, this is potencially a lot of work and it might not work at all. But there is no easy answer on "how do I do it?", so if you're not too experienced, this is not really an option for you, sorry.

Did you try changing the order you load the scripts in?
Airblader is offline   Reply With Quote
Old 01-31-2013, 05:56 PM   PM User | #5
samuelito.mcf
New Coder

 
Join Date: Jan 2013
Location: Oregon
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
samuelito.mcf is an unknown quantity at this point
I did try switching the order in which they load and what I found is that whichever one I try to load first ends up not working but the second one works perfect.
samuelito.mcf is offline   Reply With Quote
Old 01-31-2013, 07:21 PM   PM User | #6
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 364
Thanks: 3
Thanked 43 Times in 43 Posts
Airblader can only hope to improve
In that case, if you have the knowledge and feel like it's worth it, start debugging to find out what kind of interference the plugins have. You might also try to use Google and see if there are general recommendations or even a known interference of those plugins.

However, the more I think about it, the less I think the closure trap will work. I don't think either plugin just registers global variables that interfere, but instead they define objects attached to jQuery which interfere. Now you could change at least one of the plugins to adapt it to a different object, but that would most likely break the plugin as it cannot use jQuery functions anymore.

In that case, and if you can't find anything on Google, the way to go would be deactivating one plugin. Either the one you only need on one page (hurts less) or the one you might be able to find a different plugin for or even write yourself.
Airblader is offline   Reply With Quote
Users who have thanked Airblader for this post:
samuelito.mcf (01-31-2013)
Old 01-31-2013, 08:09 PM   PM User | #7
samuelito.mcf
New Coder

 
Join Date: Jan 2013
Location: Oregon
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
samuelito.mcf is an unknown quantity at this point
Ok I figured it out! I took your suggestion and googled any known conflicts and although I didn't find any with my specific slideshow involved I did find some helpful suggestions. All I had to do was omit the version of jquery in the second plugin and let the declaration at the beginning work for the second plugin. I'm sure this was a total no brainer and I should've known but my Javascript knowledge is 0. haha, but I got it working. Thanks for your responses and suggestions.
samuelito.mcf is offline   Reply With Quote
Old 01-31-2013, 09:11 PM   PM User | #8
Airblader
Regular Coder

 
Join Date: Jan 2013
Location: Germany
Posts: 364
Thanks: 3
Thanked 43 Times in 43 Posts
Airblader can only hope to improve
Awesome. Glad to hear it worked out for you!
Airblader is offline   Reply With Quote
Old 01-31-2013, 09:20 PM   PM User | #9
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,607
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
You could just have looked at the sticky in the JS frameworks (sub) forum where I thoroughly explained the issue you encountered.
__________________
Don’t click this link!
VIPStephan is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:27 PM.


Advertisement
Log in to turn off these ads.