문제

I am using jQuery editinPlace plugin, the default way of doing edit in place is using a click event on a selector, but the way I am trying to do is through context menu which calls a function "rename();". So how do I block the inline edit on click event. Please share some idea on how to do this...

$('.context').editInPlace({ 
        callback: function(idOfEditor) {
        var renameUrl = "http://www.google.com/"+tablerowId+"/"+enteredText+"";
        return enteredText;
        }
    });
도움이 되었습니까?

해결책

Open the /jquery.editinplace.js source file. (Online version > http://code.google.com/p/jquery-in-place-editor/source/browse/trunk/lib/jquery.editinplace.js)

In the first function declaration $.fn.editInPlace Line#26, change the following line :

new InlineEditor(settings, dom).init();

into >

dom.theEditor = new InlineEditor(settings, dom);
dom.theEditor.init();
dom.data("theEditor", dom.theEditor);

Now inside the click event of your context menu function, call this >

$("#myContextMenuElement").live("click", function (e) {
                    //your other code
                    rename(e); //you need to pass the event argument to it now 
});

make sure the pass the 'e' into it.

and in the rename function >

function rename(e) { 
   $("#myElementToEditInPlace").data("theEditor").openEditor(e);
}

works like a charm !

EDIT:

To ensure that you don't allow user to active editor by clicking on the para itself > use this code :

var myDelegate = { 
      shouldOpenEditInPlace: function (a, b, c) { 
         if (c.target.id != "idOfYourContextElement") { //if the edit was not invoked through the context menu option
              return false; //cancel the editor open event
         }
         return true;
    } 
};

and add the delegates in your initialization>

$('.context').editInPlace({ 
        callback: function(idOfEditor) {
           var renameUrl = "http://www.google.com/"+tablerowId+"/"+enteredText+"";
            return enteredText;
        },
        delegate: del
    });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top