|
11 | 11 | * Licensed under
|
12 | 12 | * MIT License http://www.opensource.org/licenses/mit-license
|
13 | 13 | *
|
14 |
| - * Date: 2017-08-30T12:16:04.336Z |
| 14 | + * Date: 2017-09-08T12:01:36.877Z |
15 | 15 | */
|
16 | 16 |
|
17 | 17 | // jscs:disable
|
|
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,
|
|
236 | 240 | // events
|
237 | 241 | events: {
|
238 | 242 | show: $.noop,
|
239 |
| - hide: $.noop |
| 243 | + hide: $.noop, |
| 244 | + activated: $.noop |
240 | 245 | },
|
241 | 246 | // default callback
|
242 | 247 | callback: null,
|
|
471 | 476 | $(target).trigger(e);
|
472 | 477 | root.$layer.show();
|
473 | 478 | }
|
474 |
| - |
| 479 | + |
| 480 | + if (root.hideOnSecondTrigger && triggerAction && root.$menu !== null && typeof root.$menu !== 'undefined') { |
| 481 | + root.$menu.trigger('contextmenu:hide'); |
| 482 | + return; |
| 483 | + } |
| 484 | + |
475 | 485 | if (root.reposition && triggerAction) {
|
476 | 486 | if (document.elementFromPoint) {
|
477 | 487 | if (root.$trigger.is(target)) {
|
|
997 | 1007 | // position and show context menu
|
998 | 1008 | opt.$menu.css(css)[opt.animation.show](opt.animation.duration, function () {
|
999 | 1009 | $trigger.trigger('contextmenu:visible');
|
| 1010 | + |
| 1011 | + op.activated(opt); |
| 1012 | + opt.events.activated(); |
1000 | 1013 | });
|
1001 | 1014 | // make options available and set state
|
1002 | 1015 | $trigger
|
|
1527 | 1540 | // Wait for promise completion. .then(success, error, notify) (we don't track notify). Bind the opt
|
1528 | 1541 | // and root to avoid scope problems
|
1529 | 1542 | promise.then(completedPromise.bind(this, opt, root), errorPromise.bind(this, opt, root));
|
| 1543 | + }, |
| 1544 | + // operation that will run after contextMenu showed on screen |
| 1545 | + activated: function(opt){ |
| 1546 | + var $menu = opt.$menu; |
| 1547 | + var $menuOffset = $menu.offset(); |
| 1548 | + var winHeight = $(window).height(); |
| 1549 | + var winScrollTop = $(window).scrollTop(); |
| 1550 | + var menuHeight = $menu.height(); |
| 1551 | + if(menuHeight > winHeight){ |
| 1552 | + $menu.css({ |
| 1553 | + 'height' : winHeight + 'px', |
| 1554 | + 'overflow-x': 'hidden', |
| 1555 | + 'overflow-y': 'auto', |
| 1556 | + 'top': winScrollTop + 'px' |
| 1557 | + }); |
| 1558 | + } else if(($menuOffset.top < winScrollTop) || ($menuOffset.top + menuHeight > winScrollTop + winHeight)){ |
| 1559 | + $menu.css({ |
| 1560 | + 'top': '0px' |
| 1561 | + }); |
| 1562 | + } |
1530 | 1563 | }
|
1531 | 1564 | };
|
1532 | 1565 |
|
|
1616 | 1649 | }
|
1617 | 1650 |
|
1618 | 1651 | switch (operation) {
|
| 1652 | + |
| 1653 | + case 'update': |
| 1654 | + // Updates visibility and such |
| 1655 | + if(_hasContext){ |
| 1656 | + op.update($context); |
| 1657 | + } else { |
| 1658 | + for(var menu in menus){ |
| 1659 | + if(menus.hasOwnProperty(menu)){ |
| 1660 | + op.update(menus[menu]); |
| 1661 | + } |
| 1662 | + } |
| 1663 | + } |
| 1664 | + break; |
| 1665 | + |
1619 | 1666 | case 'create':
|
1620 | 1667 | // no selector no joy
|
1621 | 1668 | if (!o.selector) {
|
|
0 commit comments