打开 /jquery.editinplace.js 源文件。(在线版 > http://code.google.com/p/jquery-in-place-editor/source/browse/trunk/lib/jquery.editinplace.js)
在第一个函数声明$.fn.editInPlace
Line#26 中,更改以下行:
new InlineEditor(settings, dom).init();
进入 >
dom.theEditor = new InlineEditor(settings, dom);
dom.theEditor.init();
dom.data("theEditor", dom.theEditor);
现在在上下文菜单功能的单击事件中,调用它 >
$("#myContextMenuElement").live("click", function (e) {
//your other code
rename(e); //you need to pass the event argument to it now
});
确保将“e”传递给它。
并在重命名功能中 >
function rename(e) {
$("#myElementToEditInPlace").data("theEditor").openEditor(e);
}
奇迹般有效 !
编辑:
为确保您不允许用户通过单击 para 本身来激活编辑器 > 使用此代码:
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;
}
};
并在您的初始化中添加代表>
$('.context').editInPlace({
callback: function(idOfEditor) {
var renameUrl = "http://www.google.com/"+tablerowId+"/"+enteredText+"";
return enteredText;
},
delegate: del
});