Reputation: 4403
In the view I have the following class
.class{"data-id" => time.id}
At the end of the view I enable the live click event
$('.class').live("click", function() {
window.orc.time.stopCount();
window.orc.time.whenClicked(#{class.id}, #{class.time}, #
{class.start});});
In coffeescript i have the following function
time.whenClicked = (class.id, time_dur, time_start) ->
ct = time_entries.to_time(time_dur, time_start)
$("div[data-id=#{time_id}]").addClass "ajax"
$("div[data-id=#{time_id}]").html("<input id=\"editbox\" size=\"8\" type=\"text\" value=\"#{ct}\">")
$("#editbox").bind "keyup", (event) ->
...
In the whenClicked function I need the live("click") to be disabled. If I try
$(".class").die("click")
it works, but then the click event will be re-enabled only after I refresh the page, and that's not what I need.
Is there a solution to disable the click event untill the function is executed?
Upvotes: 0
Views: 93
Reputation: 245449
Don't disable the handler. Just implement a boolean flag so you know if the method is already running or not. You can then immediately return from the handler in that case:
var isBusy = false;
$('.class').live('click', function(){
if(isBusy) return;
isBusy = true;
window.orc.time.stopCount();
window.orc.time.whenClicked(/* some params */);
isBusy = false;
});
Upvotes: 2