From 5551699cfeb2daf154d6655ec31a127c6af877f4 Mon Sep 17 00:00:00 2001 From: Thomas Burleson Date: Fri, 11 Sep 2015 12:30:43 -0500 Subject: [PATCH] feat(dialog): allow specifying parent by string selector. --- src/components/dialog/dialog.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/dialog/dialog.js b/src/components/dialog/dialog.js index c5582f4e82b..14af4759e94 100644 --- a/src/components/dialog/dialog.js +++ b/src/components/dialog/dialog.js @@ -463,7 +463,6 @@ function MdDialogProvider($$interimElementProvider) { * Show method for dialogs */ function onShow(scope, element, options, controller) { - element = $mdUtil.extractElementByName(element, 'md-dialog'); angular.element($document[0].body).addClass('md-dialog-is-showing'); wrapSimpleContent(); @@ -549,8 +548,11 @@ function MdDialogProvider($$interimElementProvider) { * unless overridden in the options.parent */ function captureSourceAndParent(element, options) { - var origin = {element: null, bounds: null, focus: angular.noop}; - options.origin = angular.extend({}, origin, options.origin || {}); + options.origin = angular.extend({ + element: null, + bounds: null, + focus: angular.noop + }, options.origin || {}); var source = angular.element((options.targetEvent || {}).target); if (source && source.length) { @@ -564,7 +566,14 @@ function MdDialogProvider($$interimElementProvider) { } } - // In case the user provides a raw dom element, always wrap it in jqLite + // If the parent specifier is a simple string selector, then query for + // the DOM element. + if ( angular.isString(options.parent) ) { + var simpleSelector = options.parent; + container = $document[0].querySelectorAll(selector); + options.parent = container.length ? container[0] : null; + } + // If we have a reference to a raw dom element, always wrap it in jqLite options.parent = angular.element(options.parent || $rootElement); }