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

Commit 9936185

Browse files
crisbetokara
authored andcommitted
fix(util): getClosest not working on elements with lowercase nodeName (#9510)
Fixes the `$mdUtil.getClosest` method not working properly when looking for elements with a lowercase `nodeName` (e.g. SVG). Fixes #9509.
1 parent 1f14cc4 commit 9936185

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/core/util/util.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
510510
if ( angular.isString(validateWith) ) {
511511
var tagName = validateWith.toUpperCase();
512512
validateWith = function(el) {
513-
return el.nodeName === tagName;
513+
return el.nodeName.toUpperCase() === tagName;
514514
};
515515
}
516516

@@ -776,18 +776,18 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
776776

777777
function scrollChunk() {
778778
var newPosition = calculateNewPosition();
779-
779+
780780
element.scrollTop = newPosition;
781-
781+
782782
if (scrollingDown ? newPosition < scrollEnd : newPosition > scrollEnd) {
783783
$$rAF(scrollChunk);
784784
}
785785
}
786-
786+
787787
function calculateNewPosition() {
788788
var duration = 1000;
789789
var currentTime = $mdUtil.now() - startTime;
790-
790+
791791
return ease(currentTime, scrollStart, scrollChange, duration);
792792
}
793793

@@ -797,7 +797,7 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
797797
if (currentTime > duration) {
798798
return start + change;
799799
}
800-
800+
801801
var ts = (currentTime /= duration) * currentTime;
802802
var tc = ts * currentTime;
803803

src/core/util/util.spec.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ describe('util', function() {
503503
})
504504
);
505505
});
506-
506+
507507
describe('isParentFormSubmitted', function() {
508508
var formTemplate =
509509
'<form>' +
@@ -514,26 +514,26 @@ describe('util', function() {
514514
it('returns false if you pass no element', inject(function($mdUtil) {
515515
expect($mdUtil.isParentFormSubmitted()).toBe(false);
516516
}));
517-
517+
518518
it('returns false if there is no form', inject(function($mdUtil) {
519519
var element = angular.element('<input />');
520-
520+
521521
expect($mdUtil.isParentFormSubmitted(element)).toBe(false);
522522
}));
523-
524-
it('returns false if the parent form is NOT submitted', inject(function($compile, $rootScope, $mdUtil) {
523+
524+
it('returns false if the parent form is NOT submitted', inject(function($compile, $rootScope, $mdUtil) {
525525
var scope = $rootScope.$new();
526526
var form = $compile(formTemplate)(scope);
527-
527+
528528
expect($mdUtil.isParentFormSubmitted(form.find('input'))).toBe(false);
529529
}));
530-
530+
531531
it('returns true if the parent form is submitted', inject(function($compile, $rootScope, $mdUtil) {
532532
var scope = $rootScope.$new();
533533
var form = $compile(formTemplate)(scope);
534534

535535
var formController = form.controller('form');
536-
536+
537537
formController.$setSubmitted();
538538

539539
expect(formController.$submitted).toBe(true);
@@ -616,5 +616,14 @@ describe('util', function() {
616616

617617
grandparent.remove();
618618
});
619+
620+
it('should be able to handle nodes whose nodeName is lowercase', function() {
621+
var parent = angular.element('<svg version="1.1"></svg>');
622+
var element = angular.element('<circle/>');
623+
624+
parent.append(element);
625+
expect($mdUtil.getClosest(element, 'svg')).toBeTruthy();
626+
parent.remove();
627+
});
619628
});
620629
});

0 commit comments

Comments
 (0)