TEN Design
TEN Design

Reputation: 717

jquery disable a function

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?

Upvotes: 0

Views: 65

Answers (1)

Mister Epic
Mister Epic

Reputation: 16733

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;

Upvotes: 1

Related Questions