function textarea_replace(that){
var charnum = $(that).attr('data-char'),
op = $(that).attr('data-op'),
target = $(that).find('h2'),
textarea = $(target).next('textarea'),
testo = $(target).text();
$(target).next('textarea').val(testo).show().focus();
$(target).css({ 'display': 'none' });
$(textarea).on({
blur: function(e){
e.stopPropagation();
testo_fin = $(this).val()
if (testo_fin.length > charnum) {
var text_cut = testo_fin.substr( 0, charnum )
$(this).prev().css({ 'display': 'block' }).text(text_cut)
} else {
$(this).prev().css({ 'display': 'block' }).text(testo_fin)
}
$(this).hide();
$(textarea).off('blur');
send_textarea(op, testo_fin, url_global);
}
});
}
I call it whith a event handler
$('.edit_box').on({
click: function(e){
$('.edit_box').off('click');
that = $(this)
textarea_replace(that);
}
});
i don't understand how can i temporary stop and re active the click event, because if i click on the textarea it calls another event and send the text 2 (or more times).
Barmar
789k57 gold badges555 silver badges669 bronze badges
-
Check out this answer: stackoverflow.com/a/2970987/845632 See if that helps.imtheman– imtheman2014年09月11日 22:41:35 +00:00Commented Sep 11, 2014 at 22:41
-
It's almost always wrong to bind one event handler inside another event handler, because you create multiple event handlers.Barmar– Barmar2014年09月11日 22:43:00 +00:00Commented Sep 11, 2014 at 22:43
-
Bind all your handlers at top level. If you want to temporarily disable them, set a variable that they check before doing anything.Barmar– Barmar2014年09月11日 22:44:44 +00:00Commented Sep 11, 2014 at 22:44
1 Answer 1
I'm not sure I really undestand what is supposed to happen here, but you can always use the .stop() method of jquery to clear the animation queue (or use clearQueue() if you added custom stuff)
$(".edit_box").click(function(){
doSomething($(this));
}
function doSomething(what){
what.stop() //Clears the queue, avoiding weird behaviour
//Eventually change some properties, restore your textarea, etc.
blur(what)
}
function blur(what){
//Your stufff here
}
answered Sep 11, 2014 at 22:49
Cyril Duchon-Doris
14.2k12 gold badges92 silver badges181 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js