I've been playing around with jQuery In Place Editor and I can't figure out how to properly disable it. Below is the code I have so far.
I'm using jQuery toggle
method to initialize and terminate the plugin functionality on a list of links. There are some extra bits in the code below which are probably not related to my issue but I left them there just in case.
The problem is that the code below works as I expect on first 2 clicks (ie 1st click - enable editInPlace plugin, 2nd click - disable it) but it doesn't re-enable edit in place functionality on 3rd click .
Any ideas why?
(shoppingList.editButton).toggle(function() {
(shoppingList.editButton).attr('value', 'Finish editing');
(shoppingList.$ingrLinks).unbind('click', shoppingList.ingredients) // disable some functionality on links
.addClass('inplace-editor') // add class to links I want to be editable
.removeAttr('href') // make links unclickable
.editInPlace({ // editInPlace plugin initialized
url: 'http://localhost:8000/edit-ingredient/',
show_buttons: true
});
}, function() {
(shoppingList.editButton).attr('value', 'Edit items');
(shoppingList.$ingrLinks).bind('click', shoppingList.ingredients) // bring back the functionality previously removed
.removeClass('inplace-editor') // remove the class from links that were editable
.attr('href', '#') // make the links clickable again
.unbind('.editInPlace') // remove editInPlace plugin functionality
;
});
每次用户单击时,都会执行传递给切换的第一个功能。
replace the links with clones of the links. When using $.clone()
with argument false, all event-handlers will be removed from the clone.
the 2nd function(leave the 1st function as it is):
function() {
(shoppingList.editButton).attr('value', 'Edit items');
//close the editor(s) when still active
$('.inplace_cancel',shoppingList.$ingrLinks).trigger('click');
//create clones of the items
var clones=(shoppingList.$ingrLinks).clone(false)
.each(function(i,o) {
//restore the original behaviour
$(o)//o is a clone
.bind('click', shoppingList.ingredients)
.removeClass('inplace-editor')
.attr('href', '#')
//replace the link inside the document with it's clone
.replaceAll($(shoppingList.$ingrLinks[i]));
});
//assign the clones to shoppingList.$ingrLinks
shoppingList.$ingrLinks=clones;
}
Found a solution that works:
$('input[name="edit-items"]').toggle(function() {
$(this).attr('value', 'Finish editing');
(shoppingList.$ingrLinks).unbind('click', shoppingList.ingredients) // disable highlighting items
.removeAttr('href');
$('.editme').editable("enable");
$('.editme').editable('http://localhost:8000/edit-ingredient/');
}, function() {
$(this).attr('value', 'Edit item');
(shoppingList.$ingrLinks).attr('href', '#');
$('.editme').editable("disable");
(shoppingList.$ingrLinks).bind('click', shoppingList.ingredients) // re-enable highlighting items
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.