123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', '../../lib/@waca/dashboard-common/dist/ui/toolbar_components/Menu'], function ($, Menu) {
- var ContextMenuItem = null;
- /**
- * Represents a context down menu
- */
- ContextMenuItem = Menu.extend({
- init: function init(options) {
- this.oInvokedContext = null;
- this.nPreviousFocus = null;
- ContextMenuItem.inherited('init', this, arguments);
- if (options.selectedIndex) {
- this.selectedIndex = options.selectedIndex;
- }
- },
- _performAction: function _performAction(id) {
- var action = this.itemActions[id];
- var oInvokedContext = this.oInvokedContext;
- if (action) {
- // Delay the action slightly to allow bootstrap to close the menu before
- // the action is fired
- setTimeout(function () {
- action(oInvokedContext);
- }, 10);
- }
- this.hide();
- },
- render: function render() {
- this.$el.addClass('contextmenu').hide();
- var promise = ContextMenuItem.inherited('render', this, arguments);
- this.$toggle.addClass('sr-only');
- this.$menu.show();
- return promise;
- },
- show: function show(event) {
- this.oInvokedContext = event;
- this.nPreviousFocus = document.activeElement;
- var oMenuNode = this.$el.find('.dropdown-menu').first();
- var oWindow = $(window);
- //Bind our initial position to the bounds of the target node
- var iInitialX = event.pageX ? event.pageX : 0;
- var iInitialY = event.pageY ? event.pageY : 0;
- if (event.target) {
- var oTarget = $(event.target);
- var oTargetCoords = oTarget.offset();
- oTargetCoords.width = oTarget.width();
- oTargetCoords.height = oTarget.height();
- if (iInitialX < oTargetCoords.left || iInitialX > oTargetCoords.left + oTargetCoords.width) {
- iInitialX = oTargetCoords.left;
- }
- if (iInitialY < oTargetCoords.top || iInitialY > oTargetCoords.top + oTargetCoords.height) {
- iInitialY = oTargetCoords.top;
- }
- }
- this.$el.show().addClass('open').css({
- left: this._getPosition(iInitialX, oWindow.width(), oMenuNode.outerWidth()),
- top: this._getPosition(iInitialY, oWindow.height(), oMenuNode.outerHeight())
- });
- var selectedItem;
- if (this.selectedIndex) {
- selectedItem = this.$el.find('.dropdown-menu a').eq(this.selectedIndex);
- } else {
- selectedItem = this.$el.find('.dropdown-menu a').first();
- }
- selectedItem.focus();
- $(document).on('click.privateViewEvents' + this.viewId + 'visible', this.hide.bind(this));
- },
- hide: function hide() {
- this.oInvokedContext = null;
- if (this.nPreviousFocus) {
- this.nPreviousFocus.focus();
- }
- this.nPreviousFocus = null;
- this.$el.hide().removeClass('open');
- $(document).off('click.privateViewEvents' + this.viewId + 'visible');
- },
- _getPosition: function _getPosition(iInitialLocation, iLimit, iObjectSize) {
- var iFinalLocation = iInitialLocation;
- if (iInitialLocation + iObjectSize > iLimit) {
- if (iObjectSize <= iInitialLocation) {
- iFinalLocation = iInitialLocation - iObjectSize;
- } else {
- iFinalLocation = 0;
- }
- }
- return iFinalLocation;
- }
- });
- return ContextMenuItem;
- });
- //# sourceMappingURL=ContextMenu.js.map
|