mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Merge pull request #10931 from Piccirello/webui-mobile-longpress
Add WebUI support for triggering context menus on mobile
This commit is contained in:
commit
937c5be4a9
2 changed files with 50 additions and 37 deletions
|
@ -39,7 +39,6 @@ var ContextMenu = new Class({
|
||||||
menu: 'menu_id',
|
menu: 'menu_id',
|
||||||
stopEvent: true,
|
stopEvent: true,
|
||||||
targets: 'body',
|
targets: 'body',
|
||||||
trigger: 'contextmenu',
|
|
||||||
offsets: {
|
offsets: {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
|
@ -47,7 +46,8 @@ var ContextMenu = new Class({
|
||||||
onShow: $empty,
|
onShow: $empty,
|
||||||
onHide: $empty,
|
onHide: $empty,
|
||||||
onClick: $empty,
|
onClick: $empty,
|
||||||
fadeSpeed: 200
|
fadeSpeed: 200,
|
||||||
|
touchTimer: 600
|
||||||
},
|
},
|
||||||
|
|
||||||
//initialization
|
//initialization
|
||||||
|
@ -142,35 +142,39 @@ var ContextMenu = new Class({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addTarget: function(t) {
|
setupEventListeners: function(elem) {
|
||||||
this.targets[this.targets.length] = t;
|
elem.addEvent('contextmenu', function(e) {
|
||||||
t.addEvent(this.options.trigger, function(e) {
|
this.triggerMenu(e, elem);
|
||||||
//enabled?
|
|
||||||
if (!this.options.disabled) {
|
|
||||||
//prevent default, if told to
|
|
||||||
if (this.options.stopEvent) {
|
|
||||||
e.stop();
|
|
||||||
}
|
|
||||||
//record this as the trigger
|
|
||||||
this.options.element = $(t);
|
|
||||||
this.adjustMenuPosition(e);
|
|
||||||
//show the menu
|
|
||||||
this.show();
|
|
||||||
}
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
t.addEvent('click', function(e) {
|
elem.addEvent('click', function(e) {
|
||||||
this.hide();
|
this.hide();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
elem.addEvent('touchstart', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
clearTimeout(this.touchstartTimer);
|
||||||
|
this.hide();
|
||||||
|
|
||||||
|
const touchstartEvent = e;
|
||||||
|
this.touchstartTimer = setTimeout(function() {
|
||||||
|
this.triggerMenu(touchstartEvent, elem);
|
||||||
|
}.bind(this), this.options.touchTimer);
|
||||||
|
}.bind(this));
|
||||||
|
elem.addEvent('touchend', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
clearTimeout(this.touchstartTimer);
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
//get things started
|
addTarget: function(t) {
|
||||||
startListener: function() {
|
this.targets[this.targets.length] = t;
|
||||||
/* all elements */
|
this.setupEventListeners(t);
|
||||||
this.targets.each(function(el) {
|
},
|
||||||
/* show the menu */
|
|
||||||
el.addEvent(this.options.trigger, function(e) {
|
triggerMenu: function(e, el) {
|
||||||
//enabled?
|
if (this.options.disabled)
|
||||||
if (!this.options.disabled) {
|
return;
|
||||||
|
|
||||||
//prevent default, if told to
|
//prevent default, if told to
|
||||||
if (this.options.stopEvent) {
|
if (this.options.stopEvent) {
|
||||||
e.stop();
|
e.stop();
|
||||||
|
@ -180,12 +184,14 @@ var ContextMenu = new Class({
|
||||||
this.adjustMenuPosition(e);
|
this.adjustMenuPosition(e);
|
||||||
//show the menu
|
//show the menu
|
||||||
this.show();
|
this.show();
|
||||||
}
|
},
|
||||||
}.bind(this));
|
|
||||||
el.addEvent('click', function(e) {
|
//get things started
|
||||||
this.hide();
|
startListener: function() {
|
||||||
}.bind(this));
|
/* all elements */
|
||||||
}, this);
|
this.targets.each(function(el) {
|
||||||
|
this.setupEventListeners(el);
|
||||||
|
}.bind(this), this);
|
||||||
|
|
||||||
/* menu items */
|
/* menu items */
|
||||||
this.menu.getElements('a').each(function(item) {
|
this.menu.getElements('a').each(function(item) {
|
||||||
|
|
|
@ -706,6 +706,13 @@ var DynamicTable = new Class({
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
tr.addEvent('touchstart', function(e) {
|
||||||
|
if (!this._this.isRowSelected(this.rowId)) {
|
||||||
|
this._this.deselectAll();
|
||||||
|
this._this.selectRow(this.rowId);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
this.setupTr(tr);
|
this.setupTr(tr);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue