|
116 | 116 | // flag denoting if a second trigger should simply move (true) or rebuild (false) an open menu
|
117 | 117 | // as long as the trigger happened on one of the trigger-element's child nodes
|
118 | 118 | reposition: true,
|
| 119 | + // Flag denoting if a second trigger should close the menu, as long as |
| 120 | + // the trigger happened on one of the trigger-element's child nodes. |
| 121 | + // This overrides the reposition option. |
| 122 | + hideOnSecondTrigger: false, |
119 | 123 |
|
120 | 124 | //ability to select submenu
|
121 | 125 | selectableSubMenu: false,
|
|
217 | 221 | collision: 'flipfit fit'
|
218 | 222 | }).css('display', '');
|
219 | 223 | } else {
|
| 224 | + var parentOffset = this.offset(); |
220 | 225 | // determine contextMenu position
|
221 | 226 | var offset = {
|
222 |
| - top: -9, |
223 |
| - left: this.outerWidth() - 5 |
| 227 | + top: parentOffset.top, |
| 228 | + left: parentOffset.left + this.outerWidth() |
224 | 229 | };
|
225 | 230 | $menu.css(offset);
|
| 231 | + op.activated($menu); |
226 | 232 | }
|
227 | 233 | },
|
228 | 234 | // offset to add to zIndex
|
|
472 | 478 | $(target).trigger(e);
|
473 | 479 | root.$layer.show();
|
474 | 480 | }
|
475 |
| - |
| 481 | + |
| 482 | + if (root.hideOnSecondTrigger && triggerAction && root.$menu !== null && typeof root.$menu !== 'undefined') { |
| 483 | + root.$menu.trigger('contextmenu:hide'); |
| 484 | + return; |
| 485 | + } |
| 486 | + |
476 | 487 | if (root.reposition && triggerAction) {
|
477 | 488 | if (document.elementFromPoint) {
|
478 | 489 | if (root.$trigger.is(target)) {
|
|
999 | 1010 | opt.$menu.css(css)[opt.animation.show](opt.animation.duration, function () {
|
1000 | 1011 | $trigger.trigger('contextmenu:visible');
|
1001 | 1012 |
|
1002 |
| - op.activated(opt); |
| 1013 | + op.activated(opt.$menu); |
1003 | 1014 | opt.events.activated();
|
1004 | 1015 | });
|
1005 | 1016 | // make options available and set state
|
|
1533 | 1544 | promise.then(completedPromise.bind(this, opt, root), errorPromise.bind(this, opt, root));
|
1534 | 1545 | },
|
1535 | 1546 | // operation that will run after contextMenu showed on screen
|
1536 |
| - activated: function(opt){ |
1537 |
| - var $menu = opt.$menu; |
| 1547 | + activated: function(menu){ |
| 1548 | + var $menu = menu; |
1538 | 1549 | var $menuOffset = $menu.offset();
|
1539 | 1550 | var winHeight = $(window).height();
|
1540 | 1551 | var winScrollTop = $(window).scrollTop();
|
|
1546 | 1557 | 'overflow-y': 'auto',
|
1547 | 1558 | 'top': winScrollTop + 'px'
|
1548 | 1559 | });
|
1549 |
| - } else if( |
1550 |
| - ($menuOffset.top < winScrollTop) || |
1551 |
| - ($menuOffset.top + menuHeight > winScrollTop + winHeight) |
1552 |
| - ){ |
| 1560 | + } else if($menuOffset.top < winScrollTop){ |
1553 | 1561 | $menu.css({
|
1554 | 1562 | 'top': '0px'
|
1555 | 1563 | });
|
1556 |
| - } |
| 1564 | + } else if($menuOffset.top + menuHeight > winScrollTop + winHeight){ |
| 1565 | + $menu.css({ |
| 1566 | + 'top':$menuOffset.top- Math.abs((winScrollTop+winHeight) - ($menuOffset.top+menuHeight)) |
| 1567 | + }); |
| 1568 | + } |
1557 | 1569 | }
|
1558 | 1570 | };
|
1559 | 1571 |
|
|
1643 | 1655 | }
|
1644 | 1656 |
|
1645 | 1657 | switch (operation) {
|
| 1658 | + |
| 1659 | + case 'update': |
| 1660 | + // Updates visibility and such |
| 1661 | + if(_hasContext){ |
| 1662 | + op.update($context); |
| 1663 | + } else { |
| 1664 | + for(var menu in menus){ |
| 1665 | + if(menus.hasOwnProperty(menu)){ |
| 1666 | + op.update(menus[menu]); |
| 1667 | + } |
| 1668 | + } |
| 1669 | + } |
| 1670 | + break; |
| 1671 | + |
1646 | 1672 | case 'create':
|
1647 | 1673 | // no selector no joy
|
1648 | 1674 | if (!o.selector) {
|
|
1932 | 1958 | disabled: !!$node.attr('disabled'),
|
1933 | 1959 | callback: (function () {
|
1934 | 1960 | return function () {
|
1935 |
| - $node.get(0).click() |
| 1961 | + $node.get(0).click(); |
1936 | 1962 | };
|
1937 | 1963 | })()
|
1938 | 1964 | };
|
|
1951 | 1977 | icon: $node.attr('icon'),
|
1952 | 1978 | callback: (function () {
|
1953 | 1979 | return function () {
|
1954 |
| - $node.get(0).click() |
| 1980 | + $node.get(0).click(); |
1955 | 1981 | };
|
1956 | 1982 | })()
|
1957 | 1983 | };
|
|
0 commit comments