|
559 | 559 | } |
560 | 560 |
|
561 | 561 | return function ($scope, element, attrs) { |
562 | | - var openMenuEvent = 'contextmenu'; |
| 562 | + var openMenuEvents = ['contextmenu']; |
563 | 563 | _emptyText = $scope.$eval(attrs.contextMenuEmptyText) || 'empty'; |
564 | 564 |
|
565 | 565 | if(attrs.contextMenuOn && typeof(attrs.contextMenuOn) === 'string'){ |
566 | | - openMenuEvent = attrs.contextMenuOn; |
| 566 | + openMenuEvents = attrs.contextMenuOn.split(','); |
567 | 567 | } |
568 | | - element.on(openMenuEvent, function (event) { |
569 | | - if(!attrs.allowEventPropagation) { |
570 | | - event.stopPropagation(); |
571 | | - event.preventDefault(); |
572 | | - } |
573 | 568 |
|
574 | | - // Don't show context menu if on touch device and element is draggable |
575 | | - if(isTouchDevice() && element.attr('draggable') === 'true') { |
576 | | - return false; |
577 | | - } |
| 569 | + angular.forEach(openMenuEvents, function (openMenuEvent) { |
| 570 | + element.on(openMenuEvent.trim(), function (event) { |
| 571 | + if(!attrs.allowEventPropagation) { |
| 572 | + event.stopPropagation(); |
| 573 | + event.preventDefault(); |
| 574 | + } |
578 | 575 |
|
579 | | - // Remove if the user clicks outside |
580 | | - $document.find('body').on('mousedown', removeOnOutsideClickEvent); |
581 | | - // Remove the menu when the scroll moves |
582 | | - $document.on('scroll', removeOnScrollEvent); |
| 576 | + // Don't show context menu if on touch device and element is draggable |
| 577 | + if(isTouchDevice() && element.attr('draggable') === 'true') { |
| 578 | + return false; |
| 579 | + } |
583 | 580 |
|
584 | | - _clickedElement = event.currentTarget; |
585 | | - $(_clickedElement).addClass('context'); |
| 581 | + // Remove if the user clicks outside |
| 582 | + $document.find('body').on('mousedown', removeOnOutsideClickEvent); |
| 583 | + // Remove the menu when the scroll moves |
| 584 | + $document.on('scroll', removeOnScrollEvent); |
586 | 585 |
|
587 | | - $scope.$apply(function () { |
588 | | - var options = $scope.$eval(attrs.contextMenu); |
589 | | - var customClass = attrs.contextMenuClass; |
590 | | - var modelValue = $scope.$eval(attrs.model); |
591 | | - var orientation = attrs.contextMenuOrientation; |
| 586 | + _clickedElement = event.currentTarget; |
| 587 | + $(_clickedElement).addClass('context'); |
592 | 588 |
|
593 | | - $q.when(options).then(function(promisedMenu) { |
594 | | - if (angular.isFunction(promisedMenu)) { |
595 | | - // support for dynamic items |
596 | | - promisedMenu = promisedMenu.call($scope, $scope, event, modelValue); |
597 | | - } |
598 | | - var params = { |
599 | | - '$scope' : $scope, |
600 | | - 'event' : event, |
601 | | - 'options' : promisedMenu, |
602 | | - 'modelValue' : modelValue, |
603 | | - 'level' : 0, |
604 | | - 'customClass' : customClass, |
605 | | - 'orientation': orientation |
606 | | - }; |
607 | | - $rootScope.$broadcast(ContextMenuEvents.ContextMenuOpening, { context: _clickedElement }); |
608 | | - renderContextMenu(params); |
| 589 | + $scope.$apply(function () { |
| 590 | + var options = $scope.$eval(attrs.contextMenu); |
| 591 | + var customClass = attrs.contextMenuClass; |
| 592 | + var modelValue = $scope.$eval(attrs.model); |
| 593 | + var orientation = attrs.contextMenuOrientation; |
| 594 | + |
| 595 | + $q.when(options).then(function(promisedMenu) { |
| 596 | + if (angular.isFunction(promisedMenu)) { |
| 597 | + // support for dynamic items |
| 598 | + promisedMenu = promisedMenu.call($scope, $scope, event, modelValue); |
| 599 | + } |
| 600 | + var params = { |
| 601 | + '$scope' : $scope, |
| 602 | + 'event' : event, |
| 603 | + 'options' : promisedMenu, |
| 604 | + 'modelValue' : modelValue, |
| 605 | + 'level' : 0, |
| 606 | + 'customClass' : customClass, |
| 607 | + 'orientation': orientation |
| 608 | + }; |
| 609 | + $rootScope.$broadcast(ContextMenuEvents.ContextMenuOpening, { context: _clickedElement }); |
| 610 | + renderContextMenu(params); |
| 611 | + }); |
609 | 612 | }); |
610 | | - }); |
611 | 613 |
|
612 | | - // Remove all context menus if the scope is destroyed |
613 | | - $scope.$on('$destroy', function () { |
614 | | - removeAllContextMenus(); |
| 614 | + // Remove all context menus if the scope is destroyed |
| 615 | + $scope.$on('$destroy', function () { |
| 616 | + removeAllContextMenus(); |
| 617 | + }); |
615 | 618 | }); |
616 | 619 | }); |
617 | 620 | }; |
|
0 commit comments