Skip to content

Commit 329ab68

Browse files
authored
Merge pull request #146 from Awingu/master
Fix contextmenu not repositioning at bottom of screen on IE and contextmenus not closing on touch
2 parents 566ec59 + a077335 commit 329ab68

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

contextMenu.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@
386386
$q.all($promises).then(function () {
387387
var topCoordinate = event.pageY;
388388
var menuHeight = angular.element($ul[0]).prop('offsetHeight');
389-
var winHeight = $window.scrollY + event.view.innerHeight;
389+
var winHeight = $window.pageYOffset + event.view.innerHeight;
390+
390391
/// the 20 pixels in second condition are considering the browser status bar that sometimes overrides the element
391392
if (topCoordinate > menuHeight && winHeight - topCoordinate < menuHeight + 20) {
392393
topCoordinate = event.pageY - menuHeight;
@@ -515,7 +516,7 @@
515516
}
516517

517518
function removeAllContextMenus(e) {
518-
$document.find('body').off('mousedown', removeOnOutsideClickEvent);
519+
$document.find('body').off('mousedown touchstart', removeOnOutsideClickEvent);
519520
$document.off('scroll', removeOnScrollEvent);
520521
$(_clickedElement).removeClass('context');
521522
removeContextMenus();
@@ -573,6 +574,10 @@
573574

574575
angular.forEach(openMenuEvents, function (openMenuEvent) {
575576
element.on(openMenuEvent.trim(), function (event) {
577+
// Cleanup any leftover contextmenus(there are cases with longpress on touch where we
578+
// still see multiple contextmenus)
579+
removeAllContextMenus();
580+
576581
if(!attrs.allowEventPropagation) {
577582
event.stopPropagation();
578583
event.preventDefault();
@@ -584,7 +589,7 @@
584589
}
585590

586591
// Remove if the user clicks outside
587-
$document.find('body').on('mousedown', removeOnOutsideClickEvent);
592+
$document.find('body').on('mousedown touchstart', removeOnOutsideClickEvent);
588593
// Remove the menu when the scroll moves
589594
$document.on('scroll', removeOnScrollEvent);
590595

0 commit comments

Comments
 (0)