在函数上调用Editinplace jquery插件而不是单击

Sul*_*lan 5 jquery edit-in-place jquery-plugins

我正在使用jQuery editinPlace插件,默认的编辑方式是在选择器上使用click事件,但我尝试的方法是通过调用函数"rename();"的上下文菜单.那么如何阻止点击事件的内联编辑.请分享一些关于如何做到这一点的想法......

$('.context').editInPlace({ 
        callback: function(idOfEditor) {
        var renameUrl = "http://www.google.com/"+tablerowId+"/"+enteredText+"";
        return enteredText;
        }
    });
Run Code Online (Sandbox Code Playgroud)

nee*_*ebz 1

打开 /jquery.editinplace.js 源文件。(在线版本 > http://code.google.com/p/jquery-in-place-editor/source/browse/trunk/lib/jquery.editinplace.js

在第一个函数声明$.fn.editInPlaceLine#26 中,更改以下行:

new InlineEditor(settings, dom).init();
Run Code Online (Sandbox Code Playgroud)

进入 >

dom.theEditor = new InlineEditor(settings, dom);
dom.theEditor.init();
dom.data("theEditor", dom.theEditor);
Run Code Online (Sandbox Code Playgroud)

现在,在上下文菜单函数的单击事件中,调用此 >

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

确保将“e”传递到其中。

并在重命名函数中>

function rename(e) { 
   $("#myElementToEditInPlace").data("theEditor").openEditor(e);
}
Run Code Online (Sandbox Code Playgroud)

奇迹般有效 !

编辑:

为了确保您不允许用户通过单击段落本身来激活编辑器>使用以下代码:

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;
    } 
};
Run Code Online (Sandbox Code Playgroud)

并在初始化中添加委托>

$('.context').editInPlace({ 
        callback: function(idOfEditor) {
           var renameUrl = "http://www.google.com/"+tablerowId+"/"+enteredText+"";
            return enteredText;
        },
        delegate: del
    });
Run Code Online (Sandbox Code Playgroud)