|
11 | 11 | * Licensed under |
12 | 12 | * MIT License http://www.opensource.org/licenses/mit-license |
13 | 13 | * |
14 | | - * Date: 2017-02-27T20:33:08.614Z |
| 14 | + * Date: 2017-03-15T09:06:18.835Z |
15 | 15 | */ |
16 | 16 |
|
17 | 17 | // jscs:disable |
|
200 | 200 | }, |
201 | 201 | // position the sub-menu |
202 | 202 | positionSubmenu: function ($menu) { |
203 | | - if ($menu === undefined) { |
| 203 | + if (typeof $menu === 'undefined') { |
204 | 204 | // When user hovers over item (which has sub items) handle.focusItem will call this. |
205 | 205 | // but the submenu does not exist yet if opt.items is a promise. just return, will |
206 | 206 | // call positionSubmenu after promise is completed. |
|
285 | 285 | } |
286 | 286 |
|
287 | 287 | // Let the current contextmenu decide if it should show or not based on its own trigger settings |
288 | | - if (e.mouseButton !== undefined && e.data) { |
| 288 | + if (typeof e.mouseButton !== 'undefined' && e.data) { |
289 | 289 | if (!(e.data.trigger === 'left' && e.mouseButton === 0) && !(e.data.trigger === 'right' && e.mouseButton === 2)) { |
290 | 290 | // Mouse click is not valid. |
291 | 291 | return; |
|
507 | 507 | }); |
508 | 508 | } |
509 | 509 |
|
510 | | - if (root !== null && root.$menu !== null) { |
| 510 | + if (root !== null && typeof root !== 'undefined' && root.$menu !== null && typeof root.$menu !== 'undefined') { |
511 | 511 | root.$menu.trigger('contextmenu:hide'); |
512 | 512 | } |
513 | 513 | }, 50); |
|
529 | 529 | opt = $currentTrigger.data('contextMenu') || {}; |
530 | 530 | } |
531 | 531 | // If the trigger happen on a element that are above the contextmenu do this |
532 | | - if (opt.zIndex === undefined) { |
| 532 | + if (typeof opt.zIndex === 'undefined') { |
533 | 533 | opt.zIndex = 0; |
534 | 534 | } |
535 | 535 | var targetZIndex = 0; |
536 | 536 | var getZIndexOfTriggerTarget = function (target) { |
537 | 537 | if (target.style.zIndex !== '') { |
538 | 538 | targetZIndex = target.style.zIndex; |
539 | 539 | } else { |
540 | | - if (target.offsetParent !== null && target.offsetParent !== undefined) { |
| 540 | + if (target.offsetParent !== null && typeof target.offsetParent !== 'undefined') { |
541 | 541 | getZIndexOfTriggerTarget(target.offsetParent); |
542 | 542 | } |
543 | | - else if (target.parentElement !== null && target.parentElement !== undefined) { |
| 543 | + else if (target.parentElement !== null && typeof target.parentElement !== 'undefined') { |
544 | 544 | getZIndexOfTriggerTarget(target.parentElement); |
545 | 545 | } |
546 | 546 | } |
|
563 | 563 | if (opt.$selected) { |
564 | 564 | opt.$selected.find('input, textarea, select').blur(); |
565 | 565 | } |
566 | | - if (opt.$menu !== null) { |
| 566 | + if (opt.$menu !== null && typeof opt.$menu !== 'undefined') { |
567 | 567 | opt.$menu.trigger('prevcommand'); |
568 | 568 | } |
569 | 569 | return; |
|
573 | 573 | return; |
574 | 574 | } |
575 | 575 | } else if (e.keyCode !== 9 || e.shiftKey) { |
576 | | - if (opt.$menu !== null) { |
| 576 | + if (opt.$menu !== null && typeof opt.$menu !== 'undefined') { |
577 | 577 | opt.$menu.trigger('prevcommand'); |
578 | 578 | } |
579 | 579 | return; |
|
589 | 589 | if (opt.$selected) { |
590 | 590 | opt.$selected.find('input, textarea, select').blur(); |
591 | 591 | } |
592 | | - if (opt.$menu !== null) { |
| 592 | + if (opt.$menu !== null && typeof opt.$menu !== 'undefined') { |
593 | 593 | opt.$menu.trigger('nextcommand'); |
594 | 594 | } |
595 | 595 | return; |
|
599 | 599 | return; |
600 | 600 | } |
601 | 601 | } else { |
602 | | - if (opt.$menu !== null) { |
| 602 | + if (opt.$menu !== null && typeof opt.$menu !== 'undefined') { |
603 | 603 | opt.$menu.trigger('nextcommand'); |
604 | 604 | } |
605 | 605 | return; |
|
671 | 671 |
|
672 | 672 | case 27: // esc |
673 | 673 | handle.keyStop(e, opt); |
674 | | - if (opt.$menu !== null) { |
| 674 | + if (opt.$menu !== null && typeof opt.$menu !== 'undefined') { |
675 | 675 | opt.$menu.trigger('contextmenu:hide'); |
676 | 676 | } |
677 | 677 | return; |
|
1008 | 1008 | if (opt.$layer && !opt.hovering && (!(e.pageX >= pos.left && e.pageX <= pos.right) || !(e.pageY >= pos.top && e.pageY <= pos.bottom))) { |
1009 | 1009 | /* Additional hover check after short time, you might just miss the edge of the menu */ |
1010 | 1010 | setTimeout(function () { |
1011 | | - if (!opt.hovering && opt.$menu !== null) { |
| 1011 | + if (!opt.hovering && opt.$menu !== null && typeof opt.$menu !== 'undefined') { |
1012 | 1012 | opt.$menu.trigger('contextmenu:hide'); |
1013 | 1013 | } |
1014 | 1014 | }, 50); |
|
1089 | 1089 | } |
1090 | 1090 | }, |
1091 | 1091 | create: function (opt, root) { |
1092 | | - if (root === undefined) { |
| 1092 | + if (typeof root === 'undefined') { |
1093 | 1093 | root = opt; |
1094 | 1094 | } |
1095 | 1095 | // create contextMenu |
|
1185 | 1185 | k.commands[key] = item; |
1186 | 1186 | // Overwrite only if undefined or the item is appended to the root. This so it |
1187 | 1187 | // doesn't overwrite callbacks of root elements if the name is the same. |
1188 | | - if ($.isFunction(item.callback) && (k.callbacks[key] === undefined || opt.type === undefined)) { |
| 1188 | + if ($.isFunction(item.callback) && (typeof k.callbacks[key] === 'undefined' || typeof opt.type === 'undefined')) { |
1189 | 1189 | k.callbacks[key] = item.callback; |
1190 | 1190 | } |
1191 | 1191 | }); |
|
1288 | 1288 | k.commands[key] = item; |
1289 | 1289 | // Overwrite only if undefined or the item is appended to the root. This so it |
1290 | 1290 | // doesn't overwrite callbacks of root elements if the name is the same. |
1291 | | - if ($.isFunction(item.callback) && (k.callbacks[key] === undefined || opt.type === undefined)) { |
| 1291 | + if ($.isFunction(item.callback) && (typeof k.callbacks[key] === 'undefined' || typeof opt.type === 'undefined')) { |
1292 | 1292 | k.callbacks[key] = item.callback; |
1293 | 1293 | } |
1294 | 1294 | }); |
|
1382 | 1382 | }, |
1383 | 1383 | update: function (opt, root) { |
1384 | 1384 | var $trigger = this; |
1385 | | - if (root === undefined) { |
| 1385 | + if (typeof root === 'undefined') { |
1386 | 1386 | root = opt; |
1387 | 1387 | op.resize(opt.$menu); |
1388 | 1388 | } |
|
1461 | 1461 | .on('mousedown', handle.layerClick); |
1462 | 1462 |
|
1463 | 1463 | // IE6 doesn't know position:fixed; |
1464 | | - if (document.body.style.maxWidth === undefined) { // IE6 doesn't support maxWidth |
| 1464 | + if (typeof document.body.style.maxWidth === 'undefined') { // IE6 doesn't support maxWidth |
1465 | 1465 | $layer.css({ |
1466 | 1466 | 'position': 'absolute', |
1467 | 1467 | 'height': $(document).height() |
|
1477 | 1477 | function completedPromise(opt, root, items) { |
1478 | 1478 | // Completed promise (dev called promise.resolve). We now have a list of items which can |
1479 | 1479 | // be used to create the rest of the context menu. |
1480 | | - if (items === undefined) { |
| 1480 | + if (typeof items === 'undefined') { |
1481 | 1481 | // Null result, dev should have checked |
1482 | 1482 | errorPromise(undefined);//own error object |
1483 | 1483 | } |
|
1486 | 1486 |
|
1487 | 1487 | function errorPromise(opt, root, errorItem) { |
1488 | 1488 | // User called promise.reject() with an error item, if not, provide own error item. |
1489 | | - if (errorItem === undefined) { |
| 1489 | + if (typeof errorItem === 'undefined') { |
1490 | 1490 | errorItem = { |
1491 | 1491 | "error": { |
1492 | 1492 | name: "No items and no error item", |
|
1503 | 1503 | } |
1504 | 1504 |
|
1505 | 1505 | function finishPromiseProcess(opt, root, items) { |
1506 | | - if (root.$menu === undefined || !root.$menu.is(':visible')) { |
| 1506 | + if (typeof root.$menu === 'undefined' || !root.$menu.is(':visible')) { |
1507 | 1507 | return; |
1508 | 1508 | } |
1509 | 1509 | opt.$node.removeClass(root.classNames.iconLoadingClass); |
|
1538 | 1538 | $.fn.contextMenu = function (operation) { |
1539 | 1539 | var $t = this, $o = operation; |
1540 | 1540 | if (this.length > 0) { // this is not a build on demand menu |
1541 | | - if (operation === undefined) { |
| 1541 | + if (typeof operation === 'undefined') { |
1542 | 1542 | this.first().trigger('contextmenu'); |
1543 | | - } else if (operation.x !== undefined && operation.y !== undefined) { |
| 1543 | + } else if (typeof operation.x !== 'undefined' && typeof operation.y !== 'undefined') { |
1544 | 1544 | this.first().trigger($.Event('contextmenu', { |
1545 | 1545 | pageX: operation.x, |
1546 | 1546 | pageY: operation.y, |
|
1585 | 1585 |
|
1586 | 1586 | if (typeof options === 'string') { |
1587 | 1587 | options = {selector: options}; |
1588 | | - } else if (options === undefined) { |
| 1588 | + } else if (typeof options === 'undefined') { |
1589 | 1589 | options = {}; |
1590 | 1590 | } |
1591 | 1591 |
|
|
1786 | 1786 |
|
1787 | 1787 | // import values into <input> commands |
1788 | 1788 | $.contextMenu.setInputValues = function (opt, data) { |
1789 | | - if (data === undefined) { |
| 1789 | + if (typeof data === 'undefined') { |
1790 | 1790 | data = {}; |
1791 | 1791 | } |
1792 | 1792 |
|
|
1814 | 1814 |
|
1815 | 1815 | // export values from <input> commands |
1816 | 1816 | $.contextMenu.getInputValues = function (opt, data) { |
1817 | | - if (data === undefined) { |
| 1817 | + if (typeof data === 'undefined') { |
1818 | 1818 | data = {}; |
1819 | 1819 | } |
1820 | 1820 |
|
|
0 commit comments