From 4f841379bdf2171a3a8fc7ade1347925be5d229b Mon Sep 17 00:00:00 2001 From: Thomas Burleson Date: Tue, 22 Sep 2015 11:30:13 -0500 Subject: [PATCH] fix(menu): remove exception when async loading Fixes #4687. --- src/components/menu/js/menuServiceProvider.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/menu/js/menuServiceProvider.js b/src/components/menu/js/menuServiceProvider.js index 1ab56ca21ed..c55202b8153 100644 --- a/src/components/menu/js/menuServiceProvider.js +++ b/src/components/menu/js/menuServiceProvider.js @@ -410,24 +410,22 @@ function MenuProvider($$interimElementProvider) { right: boundryNodeRect.right - MENU_EDGE_MARGIN }; - var alignTarget, alignTargetRect, existingOffsets; + var alignTarget, alignTargetRect = { top:0, left : 0, right:0, bottom:0 }, existingOffsets = { top:0, left : 0, right:0, bottom:0 }; var positionMode = opts.mdMenuCtrl.positionMode(); if (positionMode.top == 'target' || positionMode.left == 'target' || positionMode.left == 'target-right') { - // TODO: Allow centering on an arbitrary node, for now center on first menu-item's child alignTarget = firstVisibleChild(); - if (!alignTarget) { - throw Error('Error positioning menu. No visible children.'); + if ( alignTarget ) { + // TODO: Allow centering on an arbitrary node, for now center on first menu-item's child + alignTarget = alignTarget.firstElementChild || alignTarget; + alignTarget = alignTarget.querySelector('[md-menu-align-target]') || alignTarget; + alignTargetRect = alignTarget.getBoundingClientRect(); + + existingOffsets = { + top: parseFloat(containerNode.style.top || 0), + left: parseFloat(containerNode.style.left || 0) + }; } - - alignTarget = alignTarget.firstElementChild || alignTarget; - alignTarget = alignTarget.querySelector('[md-menu-align-target]') || alignTarget; - alignTargetRect = alignTarget.getBoundingClientRect(); - - existingOffsets = { - top: parseFloat(containerNode.style.top || 0), - left: parseFloat(containerNode.style.left || 0) - }; } var position = {};