Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(interimElement): fix default parent grabbing svg body
Browse files Browse the repository at this point in the history
closes #2527
  • Loading branch information
rschmukler committed Apr 23, 2015
1 parent 88612d6 commit 952d5f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/services/interimElement/interimElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,15 @@ function InterimElementProvider() {
// If parent querySelector/getter function fails, or it's just null,
// find a default.
if (!(options.parent || {}).length) {
options.parent = $rootElement.find('body');
if (!options.parent.length) options.parent = $rootElement;
if (options.parent[0].nodeName == '#comment') {
options.parent = $document.find('body');
var el;
if ($rootElement[0] && $rootElement[0].querySelector) {
el = $rootElement[0].querySelector(':not(svg) > body');
}
if (!el) el = $rootElement[0];
if (el.nodeName == '#comment') {
el = $document[0].body;
}
options.parent = angular.element(el);
}

if (options.themable) $mdTheming(element);
Expand Down
16 changes: 16 additions & 0 deletions src/core/services/interimElement/interimElement.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,22 @@ describe('$$interimElement service', function() {
expect(shown).toBe(true);
}));

it('does not select svg body tags', inject(function($rootScope, $rootElement, $document) {
var shown = false;
var originalRoot = $rootElement[0];
var svgEl = angular.element('<div><svg><body></body></svg></div>');
$rootElement[0] = svgEl[0];
Service.show({
onShow: function(scope, element, options) {
expect(options.parent[0]).toBe(svgEl[0]);
shown = true;
}
});
$rootScope.$digest();
$rootElement[0] = originalRoot;
expect(shown).toBe(true);
}));

it('falls back to $document.body if $rootElement was removed', inject(function($document, $rootElement, $rootScope) {
var shown = false;
var originalRoot = $rootElement[0];
Expand Down

0 comments on commit 952d5f5

Please sign in to comment.