テーブルのTD
要素をダブルクリックで編集可能にしています:
$(document).on("dblclick", "#table>tbody>tr>td.cell", function(e) {
if (e.which != 1 || e.shiftKey || e.altKey || e.ctrlKey)
// need left button without keyboard modifiers
return;
reset_selection();
var editor = document.createElement("div");
editor.setAttribute("contenteditable", "true");
editor.innerHTML = this.innerHTML;
this.innerHTML = '';
// this.style.padding = 0;
this.appendChild(editor);
$(document).on("*", stub);
editor.onblur = function() {
// this.parentNode.setAttribute("style", "");
this.parentNode.innerHTML = this.innerHTML;
sys.editor = null;
$(document).off("*", stub);;
};
editor.focus();
});
function stub(e) {
e.stopImmediatePropagation();
return false;
}
しかし、編集可能なdiv内のテキストをダブルクリックすると、ダブルクリックイベントが親tdに伝播し、望ましくない結果を引き起こします。他にも防止したいイベント(select
、、mousedown
など)があるので、それぞれにスタブを書くのは見栄えがよくありません。
現在アクティブなすべてのjQueryイベントハンドラーを無効にして、後で有効にする方法はありますか?または、どういうわけか、編集可能なdivからその親へのすべてのイベントの伝播を停止しますか?