문제

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 (i.e. 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
                                     ;
        });
도움이 되었습니까?

해결책 3

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 first function passed to toggle is executed every time the user clicks.

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;
        } 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top