Acordian nav slider on click closes my sliding div holdding the acordian nav

This is strange to explain, but can be seen better if you have a table to view the following site on.

http://devchecksafetyfirst.csf.dcmanaged.com/responsive/index.php

The top button in orange on theleft should say ‘Countries’ and when clicked it makes a div appear from the left with an acordian style nav inside.

All works perfectly, appart from the most annoying thing, that when a user clicks one of the top level country regions, it starts the acordian nav, but at the same time closes the slider so you then have to click countries again to get at the second level nav in the acordian.

There are only 2 .js files the one below is for the div slider


// Slidebars 0.8.2 - http://plugins.adchsm.me/slidebars/ Written by Adam Smith - http://www.adchsm.me/ Released under MIT License - http://plugins.adchsm.me/slidebars/license.txt
;(function(a){a.slidebars=function(b){var v=a.extend({siteClose:true,disableOver:false,hideControlClasses:false},b);var s=document.createElement("div").style,q=false,i=false;if(s.MozTransition===""||s.WebkitTransition===""||s.OTransition===""||s.transition===""){q=true}if(s.MozTransform===""||s.WebkitTransform===""||s.OTransform===""||s.transform===""){i=true}var p=navigator.userAgent,x=false;if(p.match(/Android/)){x=parseFloat(p.slice(p.indexOf("Android")+8));if(x<3){a("html").addClass("sb-android")}}if(!a("#sb-site").length){a("body").children().wrapAll('<div id="sb-site" />')}var o=a("#sb-site");if(!o.parent().is("body")){o.appendTo("body")}o.addClass("sb-slide");if(a(".sb-left").length){var d=a(".sb-left"),e=false;if(!d.parent().is("body")){d.appendTo("body")}if(x&&x<3){d.addClass("sb-static")}if(d.hasClass("sb-width-custom")){d.css("width",d.attr("data-sb-width"))}}if(a(".sb-right").length){var f=a(".sb-right"),h=false;if(!f.parent().is("body")){f.appendTo("body")}if(x&&x<3){f.addClass("sb-static")}if(f.hasClass("sb-width-custom")){f.css("width",f.attr("data-sb-width"))}}function r(){o.css("minHeight","");if(d){d.css("minHeight","")}if(f){f.css("minHeight","")}var y=a("html").css("height");o.css("minHeight",y);if(d&&d.hasClass("sb-static")){d.css("minHeight",y)}if(f&&f.hasClass("sb-static")){f.css("minHeight",y)}}r();var u=a(".sb-toggle-left, .sb-toggle-right, .sb-open-left, .sb-open-right, .sb-close");function m(){var y=a(window).width();if(!v.disableOver||(typeof v.disableOver==="number"&&v.disableOver>=y)){this.init=true;a("html").addClass("sb-init");if(v.hideControlClasses){u.show()}}else{if(typeof v.disableOver==="number"&&v.disableOver<y){this.init=false;a("html").removeClass("sb-init");if(v.hideControlClasses){u.hide()}if(e||h){j()}}}}m();var t,k=a(".sb-slide");if(q&&i){t="translate";if(x&&x<4.4){t="side"}}else{t="jQuery"}a("html").addClass("sb-anim-type-"+t);function c(y,B,A){if(t==="translate"){y.css({transform:"translate("+B+")"})}else{if(t==="side"){y.css(A,B)}else{if(t==="jQuery"){var z={};z[A]=B;y.stop().animate(z,400)}}}}function g(y){if(y==="left"&&d&&h||y==="right"&&f&&e){j();setTimeout(z,400)}else{z()}function z(){if(this.init&&y==="left"&&d){var A=d.css("width");a("html").addClass("sb-active sb-active-left");c(k,A,"left");setTimeout(function(){e=true},400)}else{if(this.init&&y==="right"&&f){var B=f.css("width");a("html").addClass("sb-active sb-active-right");c(k,"-"+B,"left");setTimeout(function(){h=true},400)}}}}function j(y){if(e||h){e=false;h=false;c(k,"0px","left");setTimeout(function(){a("html").removeClass("sb-active sb-active-left sb-active-right");if(y){window.location=y}},400)}}function l(y){if(y==="left"&&d){if(e){j()}else{if(!e){g("left")}}}else{if(y==="right"&&f){if(h){j()}else{if(!h){g("right")}}}}}this.open=g;this.close=j;this.toggle=l;function w(){r();m();if(e){g("left")}else{if(h){g("right")}}}a(window).resize(w);function n(z,y){z.stopPropagation();z.preventDefault();if(z.type==="touchend"){y.off("click")}}a(".sb-toggle-left").on("touchend click",function(y){n(y,a(this));if(d&&e!==true){g("left")}else{j()}});a(".sb-toggle-right").on("touchend click",function(y){n(y,a(this));if(f&&h!==true){g("right")}else{j()}});a(".sb-open-left").on("touchend click",function(y){n(y,a(this));if(d&&e!==true){g("left")}});a(".sb-open-right").on("touchend click",function(y){n(y,a(this));if(f&&h!==true){g("right")}});a(".sb-close").on("touchend click",function(y){n(y,a(this));if(e||h){j()}});a(".sb-slidebar a").not(".sb-disable-close").on("click",function(y){n(y,a(this));if(e||h){j(a(this).attr("href"))}});o.on("touchend click",function(y){if(v.siteClose&&(e||h)){n(y,a(this));j()}})}})(jQuery);

This one for the acordian style


$(document).ready(function(){
  $("#country_Nav_Slide > li > a").on("click", function(e){
    if($(this).parent().has("ul")) {
      e.preventDefault();
    }
    
    if(!$(this).hasClass("open")) {
      // hide any open menus and remove all other classes
      $("#country_Nav_Slide li ul").slideUp(350);
      $("#country_Nav_Slide li a").removeClass("open");
      
      // open our new menu and add the open class
      $(this).next("ul").slideDown(350);
      $(this).addClass("open");
    }
    
    else if($(this).hasClass("open")) {
      $(this).removeClass("open");
      $(this).next("ul").slideUp(350);
    }
  });
});

There a slight conflict somewhere, and I cant find it.

Hi,

I can’t see a button marked countries.

Hi pullo,

ive been on this for three days and still can’t work it out, and then I checked the forum again and saw you had replied and was very happy.

Possibly the reason why you can’t see it is because there responsive CSS working, and you should be able to see the change in design if you drag the browser in from the right to emulate tablet size and the nav in the orange bar should change.

Sorry about that Pullo.

Hi there,

I don’t mean to be harsh, but a slight conflict is putting it mildly.
You have tons of unclosed tags, lots of redundant (commented out) code, as well as inline CSS and JS all over the place.
You also have multiple document.ready() callbacks and are including jQuery three times, which can only lead to pain.

That said, once I fixed the above, it seems that you can apply class of sb-disable-close to a link within a Slidebar to prevent it from closing on click.
I read this on the very last line of this page: http://plugins.adchsm.me/slidebars/usage.php

Here’s a thinned down version of your code which works as required at a width of 900px (tested in Chrome).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="http://devchecksafetyfirst.csf.dcmanaged.com/responsive/" />
    <title>CheckSafetyFirst | Safe Hotels, Apartments, Villas &amp; Restaurants</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="css/style.css" rel="stylesheet" type= "text/css" />
    <link href="css/styles-Acordian.css" rel="stylesheet" type= "text/css" />
    <link rel="stylesheet" href="slidebars/slidebars.min.css" />
    <link rel="stylesheet" href="css/example-styles.css">
  </head>

  <body>
    <div class="sb-slidebar sb-left">
      <ul id="country_Nav_Slide">
        <li>
          <a href="#" class="sb-disable-close" title="European hotels - browse by countries below">Europe</a>
          <ul>
            <li><a href="result.php?Country=64" title="Hotels in Austria" style="text-transform:uppercase; font-weight:bold;">Austria</a></li>
            <li><a href="result.php?Country=62" title="Hotels in Belgium" style="text-transform:uppercase; font-weight:bold;">Belgium</a></li>
            <li><a href="result.php?Country=33" title="Hotels in Cyprus" style="text-transform:uppercase; font-weight:bold;">Cyprus</a></li>
            <li><a href="result.php?Country=34" title="Hotels in Czech Republic" style="text-transform:uppercase; font-weight:bold;">Czech Republic</a></li>
            <li><a href="result.php?Country=56" title="Hotels in France" style="text-transform:uppercase; font-weight:bold;">France</a></li>
          </ul>
        </li>
        <li>
          <a href="#" class="sb-disable-close" title="Americas hotels - browse by countries below">Americas</a>
          <ul>
            <li><a href="result.php?Country=65" title="Hotels in Argentina" style="text-transform:uppercase; font-weight:bold;">Argentina</a></li>
            <li><a href="result.php?Country=68" title="Hotels in Costa Rica" style="text-transform:uppercase; font-weight:bold;">Costa Rica</a></li>
            <li><a href="result.php?Country=71" title="Hotels in Ecuador" style="text-transform:uppercase; font-weight:bold;">Ecuador</a></li>
          </ul>
        </li>
        <li>
          <a href="#" class="sb-disable-close" title="Asian hotels - browse by countries below">Asia</a>
          <ul>
            <li><a href="result.php?Country=76" title="Hotels in India" style="text-transform:uppercase; font-weight:bold;">India</a></li>
            <li><a href="result.php?Country=41" title="Hotels in Thailand" style="text-transform:uppercase; font-weight:bold;">Thailand</a></li>
          </ul>
        </li>
      </ul>
    </div>

    <div id="sb-site">
      <div id="logo_Area_2">
        <div id="top_Bar">
          <div id="top_Bar_Wrapper">
            <a href="index.php" title="CheckSafetyFirst Home Page">
              <div id="top_Bar_Wrapper_Logo"></div>
            </a>
          </div>
        </div>
        <ul id="country_Nav">
          <li class="sb-toggle-left"><a href="#" title="Countries Menu">Countries</a></li>
          <li class="sb-toggle-left"><a href="#" title="Categories Menu">Categories</a></li>
          <li style="position:relative; float:right"><a href="#" title="Search">Search</a></li>
          <li style="position:relative; float:right"><a href="#" title="Contact Us">Contact</a></li>
        </ul>
      </div>
    </div>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="slidebars/slidebars.min.js"></script>
    <script type="text/javascript" language="javascript" charset="utf-8" src="js/nav.js"></script>

    <script>
      $.slidebars();
    </script>
  </body>
</html>

And here’s a demo of it working. Don’t forget to resize your browser to ca. 900px width.

HTH - I’m off to bed :slight_smile:

Right I see, can i ask a question.

You know where you found all the problems, are you finding those out using w3c validator…

I will go through it all then and sort it out.

Thanks again though

Hi,

I found all the problems by taking your page and making a Short, Self Contained, Correct (Compilable), Example.