1

I've added 3 jqueryscripts for an html page (a colorbox plugin for gallery, a popup plugin for a reservation form and a sliding jquery for footer. While adding these three plugins, either pop up close button not working or else the colorbox not working. Ive tried all the ways, but no use... im herewith adding the scripts..

<link href="02/css/login Popup/popup.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="02/js/Login pop_up/jquery.min.js"></script>


   <script type="text/javascript">

   $(document).ready(function() {
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size

//Pull Query & Variables from href URL
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value

//Fade in the Popup and add close button
  $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#"   class="close"><img src="02/images/close1.png" class="btn_close1" title="Close Window"    alt="Close" /></a>');

//Define margin for center alignment (vertical   horizontal) - we add 80px to the  height/width to accomodate for the padding  and border width defined in the css
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;

//Apply Margin to Popup
$('#' + popID).css({
    'margin-top' : -popMargTop,
    'margin-left' : -popMargLeft
});

//Fade in Background
 $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
 $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

return false;
   });

   //Close Popups and Fade Layer
 $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
   $('#fade , .popup_block').fadeOut(function() {
    $('#fade, a.close').remove();  //fade them both out
});
return false;
 });
 });

 </script>

  <!---Popup plugin ending---> 



   <!---Slider plugin starting---> 

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

 <script type="text/javascript" src="slide/jquery.scrollTo.js"></script>



   <script>



    $(document).ready(function() {



$('a.panel').click(function () {



    $('a.panel').removeClass('selected');

    $(this).addClass('selected');



    current = $(this);



    $('#wrapper').scrollTo($(this).attr('href'), 800);      



    return false;

});



$(window).resize(function () {

    resizePanel();

});



     });



     function resizePanel() {



width = $(window).width();

height = $(window).height();



mask_width = width * $('.item').length;



$('#debug').html(width  + ' ' + height + ' ' + mask_width);



$('#wrapper, .item').css({width: width, height: height});

$('#mask').css({width: mask_width, height: height});

$('#wrapper').scrollTo($('a.selected').attr('href'), 0);



        }



        </script>

               <!---Slider plugin ending---> 

       <!---Colorbox plugin starting--->


        <link rel="stylesheet" href="css/colorbox.css" />
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
           <script src="plugins/jquery.colorbox.js"></script>
         <script src="plugins/colorbox-main.js" type="text/javascript"></script>
         <script src="plugins/jquery.colorbox-min.js" type="text/javascript"></script>

         <!---Colorbox plugin ending--->
Barney
  • 16,181
  • 5
  • 62
  • 76
Warlock
  • 13
  • 7
  • 1
    Including three different versions of jquery.js is going to give you problems. Does it work if you just include the 1.9.1 version, and include it at the top? – nnnnnn Sep 02 '13 at 09:21
  • @nnnnnn Ya...i tried, now both the popup and slider plugin working, but colorbox is not working.... – Warlock Sep 02 '13 at 09:25
  • @Warlock check this out http://interface88.blogspot.in/2012/07/using-multiple-version-of-jquery-on.html – rajesh kakawat Sep 02 '13 at 09:32
  • you have two jquery versions??? maybe use jquery migrate with 1.9.1 instead of also using 1.3 – kangoroo Sep 02 '13 at 09:32
  • @rajeshkakawat Ive tried, but not working.:-( – Warlock Sep 02 '13 at 09:45
  • @kangoroo i ve replaced the 1.3 and 1.9.1 with jquery migrate 1.9.1. Now the colorbox is working, but the popup close button and slider is not working.... – Warlock Sep 02 '13 at 09:49
  • oh boy ;) I think you have to figure out what versions they work with and make a choice buddy. – kangoroo Sep 02 '13 at 09:50
  • or slowly iterate up from 1.3 gradually and try to find a version that works for all – kangoroo Sep 02 '13 at 09:51
  • @kangaroo Ive removed 1.3 and popup plugin working fine with 1.9.1,:-)....but colorbox still not working – Warlock Sep 02 '13 at 10:00

1 Answers1

1

The real problem is that the plugins you want require different versions of jQuery: You say the popup and slider work with 1.9.1, but colorbox requires 1.3, meaning that so far you can't get a situation whereby all 3 work. The real question, then, is "how can I use different versions of jQuery on the same page?".

This has been answered before: Use jQuery's noConflict function to get both versions of jQuery represented by different variables, then invoke the plugins as necessary.

Seeing as colorbox is the odd one out (and using an ancient version of jQuery for most of your code will be increasingly difficult), it's probably best to use jQuery 1.9.1 (or higher) by default, then set jQuery 1.3 to a different variable. I've paraphrased filenames, paths, etc, but the code below should give you an idea:

<script src="jquery-1.9.1.min.js"></script>
<script src="popup.js"></script>
<script src="slider.js"></script>

<script src="jquery-1.3.2.min.js"></script>
<script src="colorbox.js"></script>

<script>
    $old = $.noConflict( true );
</script>

Now a runthrough of what's happening above:

  1. Load jQuery 1.9.1, which assigns itself to the $ and jQuery variables.
  2. Load the popup and slider scripts. These assume that jQuery 1.9.1 is bound to the variable names above (which it is), and attach their behaviour.
  3. Load jQuery 1.3.2, which replaces the jQuery variables with itself - jQuery 1.9.1 can no longer be referenced in the global scope — but that's not a problem for the popup and slider plugins, because they've already executed and attached their behaviour.
  4. Load the colorbox script, which finds jQuery 1.3.2 and binds to it.
  5. Call jQuery 1.3.2's noConflict - this assigns current $ and jQuery variables back to whatever they were before this version of jQuery executed (jQuery 1.9.1), and assigns the current jQuery (1.3.2) to whatever variable you provide. From this point onwards, you'll need to use that varialbe instead of $ if you want to use jQuery 1.3.2 or the colorbox plugin.

I created a proof of concept here: these plugins are extremely simple (all they do is use jQuery to make clicking paragraphs alert messages), but they will only function if they have the correct version of jQuery.

Community
  • 1
  • 1
Barney
  • 16,181
  • 5
  • 62
  • 76
  • :-)...Thank you soo much....The thing worked...!!!...but an error occured....the popup close button is not working....everything else is going fine.....:-)...think error with the click function in colorbox and popup... – Warlock Sep 02 '13 at 12:34
  • :-)...Thank you soo much....The thing worked...!!!...but an error occured....the popup close button is not working....everything else is going fine.....:-)...think error with the click function in colorbox and popup... – Warlock Sep 02 '13 at 12:40
  • Can you link a page with the problem? If not, do you get a Javascript error (if you're using Chrome, hit F12 and try to close the popup again — it will show in the console)? – Barney Sep 02 '13 at 12:50
  • //Close Popups and Fade Layer $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer... an error showing ()live is not a function – Warlock Sep 03 '13 at 04:35
  • @Warlock that's a a separate problem. `.live()` was removed from jQuery in version 1.9 — [it says so in the docs](http://api.jquery.com/live/). Most of your code uses jQuery 1.9, so you should be using that version for all your code apart from colorbox. I recommend using a modern jQuery method: `$( document ).on( 'click', 'a.close, #fade', function(){ … } );`. If you insist on using old jQuery methods, use your old jQuery: `$old( 'a.close, #fade').live( function(){ … } );`. If you have any more questions, you should ask them as separate questions! PS: An upvote would be nice. Or an acceptance! – Barney Sep 03 '13 at 09:14
  • It worked!!!!........Thank you sooooo much.......:-)...u r great....sorry that i cant give an upvote because minimum 15 reputation...i dont have one..!!!! – Warlock Sep 03 '13 at 09:37
  • Haha, glad it worked — at last! Can you mark my answer as accepted (tickbox under the votes)? – Barney Sep 03 '13 at 10:31