views:

197

answers:

1

I am able to set up the inplace editor no problem, everything works great, but I haven't found a way to remove it once it is attached to a field, anyone know how?

I am talking about this plugin here: http://www.davehauenstein.com/code/jquery-edit-in-place/

+2  A: 

I suppose you mean you want to disable the inplace editor.

I never used this plugin but I see no code sample on the site that leads to believe the behavior you're asking for is implemented.

If it's not, maybe you could use the good old div cache trick:

$.fn.disableWithADiv() {
    var element = $(this);
    var pos = element.offset();
    $("body").append($("<div />").css({
        "position": "absolute",
        "z-index": 1000,
        "left": pos.left+"px",
        "top": pos.top+"px",
        "width": element.width(),
        "height": element.height(),
        "display": "block"
    }).attr("id",element.attr("id")+"-div-disabler"));
}

$.fn.removeDivDisabler() {
    var element = $(this);
    $("#"+element.attr("id")+"-div-disabler").remove();
}

then use

$("#yourElement").disableWithADiv();   // To disable
$("#yourElement").removeDivDisabler(); // To re-enable

If everything goes as planned, the div will catch click events in place of your element and the inplace editor will never get opened.

That's from the top of my head, not sure there are no typo or a major logic flaw in there ;)

EDIT:

Well, there is a problem... the bodies of the two functions should be encapsulated into this construct:

return this.each(function() {
    // Body here
});

Silly me.

Julian Aubourg