前の回答で説明したように、イベントを使用してcontextmenu
右クリックを検出できます。マウスの右ボタンのクリックを検出する別の方法は、jquery のevent.whichです。
clickTree: function(e) {
if (event.which === 3) {
// handle right clicks
this.showtreemenu(e);
return;
}
// handle left clicks
this.toggletree(e);
}
長いクリック、つまりクリックの持続時間の測定には、 と を使用mouseup
しmousedown
ます。
events: {
'mousedown .measure-click-duration': 'clickStarted',
'mouseup .measure-click-duration': 'clickEnded'
},
clickStarted: function(e) {
this.clickStartTime = e.timeStamp;
},
clickEnded: function(e) {
var clickDuration = e.timeStamp - this.clickStarted;
if (clickDuration > 1000) {
this.longClick(e);
}
}
上記の右クリックとクリック時間のデモンストレーションを行うフィドルを作成しました。contextmenu