2

Link to website

I am sure that the conflict is between my pageslide and image slider..

Here is the code for the page slide:

<ul>
    <li>
        <a href="javascript:$.pageslide({ direction: 'right', href: '_secondary.html' })" class="first">Slide to the right, and load content from a secondary page.</a>
    </li>

    <li>
        <a href="javascript:$.pageslide({ direction: 'left', href: '/template/_secondary.html' })" class="second">Open the page programatically.</a>
    </li>
</ul>
<script>
var jq171 = jQuery.noConflict();
</script>
<script src="/template/js/jquery-1.7.1.min.js"></script>
<script src="/template/js/jquery.pageslide.js"></script>
<script>
    /* Default pageslide, moves to the right */
    $(".first").pageslide({ direction: "right"});

    /* Slide to the left, and make it model (you'll have to call $.pageslide.close() to close) */
    $(".second").pageslide({ direction: "left"});
</script>`

Here is the image slider: This code references two jQuery libraries - v1.5.1 & orbit-1.2.3

<div class="container" style="margin-top:20px; margin-left:10px;">
    <div id="featured"> 
        <a href=""><img src="*****" /></a>
        <a href=""><img src="*****" /></a>
        <a href=""><img src="*****" /></a>
        <a href=""><img src="*****" /></a>
        <a href=""><img src="*****" /></a>
    </div>

For a minute a I had them both working together, but i'm not sure what is causing the conflict. I have tried the no conflict script in different variations.. Let me know if you need any more information to help. Thanks!

Rob W
  • 341,306
  • 83
  • 791
  • 678
dilloncarter
  • 35
  • 1
  • 8
  • You need to call `noConflict` *after* including the 2nd jQuery script. – gen_Eric Jul 06 '12 at 18:03
  • moving the v1.7.1 library breaks the page slide and the image slider doesn't work. are you talking about a noconflict for the pageslide.js? – dilloncarter Jul 06 '12 at 18:07
  • 1
    Seriously... throw out your old plugins and get replacements, or stick to one version of jQuery. For that one little page, you don't need to bring in over 35,000 lines of library javascript just to make some things fade in and out. – Chris Baker Jul 06 '12 at 18:21
  • Chris, you have a point, so are you suggesting I simply take out the elements I need for this? – dilloncarter Jul 06 '12 at 18:28
  • 1
    I suggest you stop, remove all effects. Design your page. Pick a version of jQuery -- I suggest the newest (1.7x). Then you use a CDN-hosted copy of it (http://code.jquery.com/jquery.min.js, for example). THEN, get together a small, tasteful collection of effects that will enhance your page. Only chose things that work in the latest jQuery version. The way you are doing it makes everything harder for you, which is the opposite of what a library should do. Also, because you're using old versions, you still have to worry about browser compatibility -- also a main purpose for using a library. – Chris Baker Jul 06 '12 at 18:33
  • Yeah that makes total sense but what I should do about the library that bigcommerce adds for their functionality? They supply the v1.6.4 for their pages – dilloncarter Jul 06 '12 at 18:46
  • Then that part of the choice is made for you. I would still stop with piecemeal effects: stop and think about the total effect you're going for. See if there's one plugin that works with 1.6.4 that takes care of it. If so, there you go. If not, what can you do with stock jQuery functionality? Only after you've explored that, then start shopping for plugins, but if they **require** older jQuery, they're off the table. That said, *most* jQuery plugins try to be agnostic to version -- they don't care what version of jQuery you're using them with. That's also worth exploring. – Chris Baker Jul 06 '12 at 19:04
  • I really appreciate the help. I got it all to work well now, how can I go about the syntax errors in the common.js? – dilloncarter Jul 06 '12 at 21:36

4 Answers4

3

The code will work sometimes and not others because of variances in the speed that the library script loads. Sometimes, it loads fast enough to be in place when you start using it, sometimes not. That's why you should put your initial code in a ready block:

<script src="/template/js/jquery-1.7.1.min.js"></script>
<script src="/template/js/jquery.pageslide.js"></script>
<script type="text/javascript">
    var jq171 = jQuery.noConflict();
    jq171.ready(function ($) {
        /* Default pageslide, moves to the right */
        $(".first").pageslide({ direction: "right"});

        /* Slide to the left, and make it model (you'll have to call $.pageslide.close() to close) */
        $(".second").pageslide({ direction: "left"});
    });
</script>

Also, I urge you to reconsider using two libraries on the same page, or even the same site. One is enough!

Documentation

Chris Baker
  • 49,926
  • 12
  • 96
  • 115
  • Downvoter, please explain -- this answer is factually correct. – Chris Baker Jul 06 '12 at 18:09
  • Knew who did it as soon as I saw your answer. Edit the answer to add such a minute correction. – Chris Baker Jul 06 '12 at 18:10
  • Removed DV, but why define another variable, `jq171` is just not needed. :) – iambriansreed Jul 06 '12 at 18:11
  • When one is conducting the bad practice of using two versions of jQuery on the same page, it is the standard procedure to alias each version to a descriptive variable so that one may, in later scripts, correctly refer to the desired version. See http://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page – Chris Baker Jul 06 '12 at 18:14
  • I see that. UPvoted. I just never see a need for two jQuery versions. So odd. – iambriansreed Jul 06 '12 at 18:17
  • There is a never a need. I question the need for ONE jQuery version, but let's not get into lengthy digressions ;) – Chris Baker Jul 06 '12 at 18:19
  • pageslide works without the noconflict..I got that fully working but the image gallery isn't loading – dilloncarter Jul 06 '12 at 18:20
  • You have syntax errors here: http://avs.mybigcommerce.com/javascript/common.js, you have other code executing before the DOM is ready, you have code trying to use `$` in the global scope (can't, when you're using no conflicts)... lots of stuff going on there. Get Firebug! Drop the second version of jQuery! You're making a mess :) – Chris Baker Jul 06 '12 at 18:24
  • I appreciate the help..I obviously need it when it comes to the javascripts. Which library do I get rid of? – dilloncarter Jul 06 '12 at 18:32
  • See my comment above on the question. I say take them all off. Design your page first, make sparing choices on which effects to include on your page. Find out what base jQuery cannot do on its own. Then choose effects that meet your requirements. What you have now is a gathering vortex of...stuff. It is making it confusing for you without adding much value to your site's usability or design. – Chris Baker Jul 06 '12 at 18:36
2

use noConflict after loading jQuery and use it instead of $():

var jq171 = jQuery.noConflict();
jq171(document).ready(function () {
   jq171(".first").pageslide({ direction: "right"});
   // ....
})
Ram
  • 143,282
  • 16
  • 168
  • 197
1

Run your jQuery in a ready state passing the $ variable.

Use only one jQuery library, preferably the latest and from a CDN.

jQuery.noConflict();
jQuery.ready(function ($) {
    /* Default pageslide, moves to the right */
    $(".first").pageslide({ direction: "right"});

    /* Slide to the left, and make it model (you'll have to call $.pageslide.close() to close) */
    $(".second").pageslide({ direction: "left"});
});

// Outside the ready state $ calls the other library.
iambriansreed
  • 21,935
  • 6
  • 63
  • 79
1

You have three different versions of jQuery loading. Forget juggling them with noConflict, there's just no reason to load three versions.

Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
  • Whoever downvoted... even if the noConflict thing isn't true, a comment would suffice. The advice to not have THREE different versions of jQuery is absolutely good advice. THey don't need 1.6.4, 1.5.1, and 1.7.1 on the same page. – Greg Pettit Jul 06 '12 at 18:26
  • I just DVed. "the noConflict thing isn't true" remove it and I will remove my DV. 3 versions is ridiculous and a point I am surprised nobody else made. :) – iambriansreed Jul 06 '12 at 18:27
  • 2
    So you comment, I update... it's much friendlier than an (ironically) anonymous downvote. – Greg Pettit Jul 06 '12 at 18:28
  • Wasn't me..but I am clearly not a js expert..so If I only load one library it will be enough to support those elements? – dilloncarter Jul 06 '12 at 18:30
  • +1 for being the only to mention the 3 versions of jQuery madness. – iambriansreed Jul 06 '12 at 18:30
  • 1
    dillon, you're not loading 3 libraries, you're loading 3 different versions of the same library. You only need 1 version of that one library. I don't see any others (prototype, etc) even being used. I understand that when we follow tutorials and use sample code, it's not always 100% clear, though. We can be led to believe that this particular version is required for this specific plugin. – Greg Pettit Jul 06 '12 at 18:33
  • @GregPettit Truth, but OP says he is loaded "orbit-1.2.3" whatever that is. – iambriansreed Jul 06 '12 at 18:34