mirror of
https://github.com/nasa/openmct.git
synced 2025-04-15 15:06:47 +00:00
Merge remote-tracking branch 'github-open/open1506' into open-master
This commit is contained in:
commit
9ab06cfdd2
@ -31,7 +31,7 @@ define(
|
||||
|
||||
var MENU_TEMPLATE = "<mct-representation key=\"'context-menu'\" " +
|
||||
"mct-object=\"domainObject\" " +
|
||||
"ng-class=\"menuClass\"" +
|
||||
"ng-class=\"menuClass\" " +
|
||||
"ng-style=\"menuStyle\">" +
|
||||
"</mct-representation>",
|
||||
dismissExistingMenu;
|
||||
@ -48,7 +48,7 @@ define(
|
||||
* should be performed
|
||||
*/
|
||||
function ContextMenuAction($compile, $document, $window, $rootScope, actionContext) {
|
||||
|
||||
|
||||
function perform() {
|
||||
var winDim = [$window.innerWidth, $window.innerHeight],
|
||||
eventCoors = [actionContext.event.pageX, actionContext.event.pageY],
|
||||
@ -62,7 +62,7 @@ define(
|
||||
// Remove the context menu
|
||||
function dismiss() {
|
||||
menu.remove();
|
||||
body.off("click", dismiss);
|
||||
body.off("mousedown", dismiss);
|
||||
dismissExistingMenu = undefined;
|
||||
}
|
||||
|
||||
@ -92,20 +92,21 @@ define(
|
||||
|
||||
// Add the menu to the body
|
||||
body.append(menu);
|
||||
|
||||
|
||||
// Stop propagation so that clicks on the menu do not close the menu
|
||||
menu.on('mousedown', function (event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
|
||||
// Dismiss the menu when body is clicked elsewhere
|
||||
// ('mousedown' because 'click' breaks left-click context menus)
|
||||
body.on('mousedown', dismiss);
|
||||
menu.on('click', dismiss);
|
||||
|
||||
// Don't launch browser's context menu
|
||||
actionContext.event.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
perform: perform
|
||||
};
|
||||
@ -113,4 +114,4 @@ define(
|
||||
|
||||
return ContextMenuAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -69,7 +69,7 @@ define(
|
||||
mockCompiledTemplate.andReturn(mockMenu);
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockRootScope.$new.andReturn(mockScope);
|
||||
|
||||
|
||||
mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent};
|
||||
|
||||
action = new ContextMenuAction(
|
||||
@ -118,9 +118,9 @@ define(
|
||||
it("removes a menu when body is clicked", function () {
|
||||
// Show the menu
|
||||
action.perform();
|
||||
|
||||
|
||||
// Verify precondition
|
||||
expect(mockBody.off).not.toHaveBeenCalled();
|
||||
expect(mockBody.remove).not.toHaveBeenCalled();
|
||||
|
||||
// Find and fire body's mousedown listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
@ -133,8 +133,29 @@ define(
|
||||
expect(mockMenu.remove).toHaveBeenCalled();
|
||||
|
||||
// Listener should have been detached from body
|
||||
expect(mockBody.off).toHaveBeenCalled();
|
||||
expect(mockBody.off).toHaveBeenCalledWith(
|
||||
'mousedown',
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
it("removes a menu when it is clicked", function () {
|
||||
// Show the menu
|
||||
action.perform();
|
||||
|
||||
// Verify precondition
|
||||
expect(mockMenu.remove).not.toHaveBeenCalled();
|
||||
|
||||
// Find and fire body's mousedown listener
|
||||
mockMenu.on.calls.forEach(function (call) {
|
||||
if (call.args[0] === 'click') {
|
||||
call.args[1]();
|
||||
}
|
||||
});
|
||||
|
||||
// Menu should have been removed
|
||||
expect(mockMenu.remove).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user