Skip to content

Commit

Permalink
taphold should trigger contextmenu now - ref vakata#908
Browse files Browse the repository at this point in the history
  • Loading branch information
vakata committed Nov 12, 2014
1 parent 5771387 commit 40f4962
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 12 deletions.
45 changes: 40 additions & 5 deletions dist/jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5071,6 +5071,8 @@
* Shows a context menu when a node is right-clicked.
*/

var cto = null, ex, ey;

/**
* stores all defaults for the contextmenu plugin
* @name $.jstree.defaults.contextmenu
Expand Down Expand Up @@ -5218,18 +5220,35 @@

var last_ts = 0;
this.element
.on("contextmenu.jstree", ".jstree-anchor", $.proxy(function (e) {
.on("contextmenu.jstree", ".jstree-anchor", $.proxy(function (e, data) {
e.preventDefault();
last_ts = e.ctrlKey ? e.timeStamp : 0;
last_ts = e.ctrlKey ? +new Date() : 0;
if(data || cto) {
last_ts = (+new Date()) + 10000;
}
if(cto) {
clearTimeout(cto);
}
if(!this.is_loading(e.currentTarget)) {
this.show_contextmenu(e.currentTarget, e.pageX, e.pageY, e);
}
}, this))
.on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
if(this._data.contextmenu.visible && (!last_ts || e.timeStamp - last_ts > 250)) { // work around safari & macOS ctrl+click
if(this._data.contextmenu.visible && (!last_ts || (+new Date()) - last_ts > 250)) { // work around safari & macOS ctrl+click
$.vakata.context.hide();
}
}, this));
last_ts = 0;
}, this))
.on("touchstart.jstree", ".jstree-anchor", function (e) {
if(!e.originalEvent || !e.originalEvent.changedTouches || !e.originalEvent.changedTouches[0]) {
return;
}
ex = e.pageX;
ey = e.pageY;
cto = setTimeout(function () {
$(e.currentTarget).trigger('contextmenu', true);
}, 750);
});
/*
if(!('oncontextmenu' in document.body) && ('ontouchstart' in document.body)) {
var el = null, tm = null;
Expand Down Expand Up @@ -5330,6 +5349,20 @@
};
};

$(function () {
$(document)
.on('touchmove.vakata.jstree', function (e) {
if(cto && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0] && (Math.abs(ex - e.pageX) > 50 || Math.abs(ey - e.pageY) > 50)) {
clearTimeout(cto);
}
})
.on('touchend.vakata.jstree', function (e) {
if(cto) {
clearTimeout(cto);
}
});
});

// contextmenu helper
(function ($) {
var right_to_left = false,
Expand Down Expand Up @@ -5636,7 +5669,9 @@

$(document)
.on("mousedown.vakata.jstree", function (e) {
if(vakata_context.is_visible && !$.contains(vakata_context.element[0], e.target)) { $.vakata.context.hide(); }
if(vakata_context.is_visible && !$.contains(vakata_context.element[0], e.target)) {
$.vakata.context.hide();
}
})
.on("context_show.vakata.jstree", function (e, data) {
vakata_context.element.find("li:has(ul)").children("a").addClass("vakata-context-parent");
Expand Down
Loading

0 comments on commit 40f4962

Please sign in to comment.