1

I have a button to switch on edit mode: show some #edit_bar and turns on .selectable():

$('#edit_mode').click(function() {
  $('#edit_bar').slideToggle("slow", function() {
    $('#foo').selectable("enable");
  });
});

I wish to disable .selectable() when the button is clicked second time (turn off edit mode).

I'm wondering about best way to do that. There was .toggle() method to do so but it's replaced now by something very different.

pawel7318
  • 3,383
  • 2
  • 28
  • 44

1 Answers1

1

How about setting a flag for this? It would set a toggle effect such that the flag will be checked each time the click function is called and will perform the appropriate function:

var flag = true;
$('#edit_mode').click(function() {
  $('#edit_bar').slideToggle("slow", function() {
  if(flag == true) {
       $('#foo').selectable("enable");
       flag = false;
    }
    else {
       $('#foo').selectable("disable");
       flag = true;
    }
  });
});
Aditya
  • 1,241
  • 5
  • 19
  • 29
  • Yep, I know it can be done that way but I was expecting some ready to use old fassion `.toggle` replacement or some explanation why it's not longer available. I like Randy's answer for [that question](http://stackoverflow.com/questions/14301935/where-has-fn-toggle-handlereventobject-handlereventobject-gone) the most I think. – pawel7318 Jan 13 '15 at 11:19