0

For one of my projects we have a proprietary CMS that works by looking for a file in the clients instance directory first and if not found, it defaults to the common directory. So in the common directory, i have shell.js which includes a function for setting the initial state of a collapse div in bootstrap 2.3.2. I need to be able to disable this function at the client level while still having the function available in the common level. Im pretty green at js/jquery, can someone help me?

The code in the shell.js is this...

/*******************************/
/*  TOGGLE BUTTON
/*******************************/
var toggleBlock = function() {
    var windowsize = $(window).width(),
        isDesktop = windowsize > 765;

    $("#quicksearch").toggleClass("collapse in", isDesktop);
    $("#quicksearch").toggleClass("collapse out", !isDesktop);
    $("#sidebar").toggleClass("collapse in", isDesktop);
    $("#sidebar").toggleClass("collapse out", !isDesktop);
}
$(document).ready(toggleBlock);
$(window).on("resize.showContent", toggleBlock);
toggleBlock();

would .unbind() be the right direction?

1 Answer 1

1

A pretty crude solution:

  var disabledFlag = false;

  var toggleBlock = function() {
    if(!disabledFlag){
      var windowsize = $(window).width(),
      isDesktop = windowsize > 765;

      $("#quicksearch").toggleClass("collapse in", isDesktop);
      $("#quicksearch").toggleClass("collapse out", !isDesktop);
      $("#sidebar").toggleClass("collapse in", isDesktop);
      $("#sidebar").toggleClass("collapse out", !isDesktop);
   }
}

Then elsewhere in the code you flip the flag to true, which will stop the function from executing the meaningful code:

 disabledFlag = true;
Sign up to request clarification or add additional context in comments.

3 Comments

i changed the code in my shell.js and then added <script>var disabledFlag = true;</script> in the head section of index.html and its not working...something i'm doing wrong? By setting the var disableFlag to true, i need the default state to be collapsed?
Did you add that block after shell.js? It would need to come before.
now have it before the shell.js and still loading page with the collapse expanded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.