Skip to content

Commit

Permalink
Removing contains internal implementaion | Fixes metal#367
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonvs committed Mar 27, 2018
1 parent 30b1bae commit b6027df
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 35 deletions.
17 changes: 1 addition & 16 deletions packages/metal-dom/src/domNamed.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,6 @@ export function buildFragment(htmlString) {
return fragment;
}

/**
* Checks if the first element contains the second one.
* @param {!Element} element1
* @param {!Element} element2
* @return {boolean}
*/
export function contains(element1, element2) {
if (isDocument(element1)) {
// document.contains is not defined on IE9, so call it on documentElement instead.
return element1.documentElement.contains(element2);
} else {
return element1.contains(element2);
}
}

/**
* Listens to the specified event on the given DOM element, but only calls the
* given callback listener when it's triggered by elements that match the
Expand Down Expand Up @@ -854,7 +839,7 @@ function toggleClassesWithoutNative_(element, classes) {
*/
function triggerElementListeners_(element, event, defaultFns) {
const lastContainer = event[LAST_CONTAINER];
if (!isDef(lastContainer) || !contains(lastContainer, element)) {
if (!isDef(lastContainer) || !lastContainer.contains(element)) {
const listeners = domData.get(element, 'listeners', {})[event.type];
return triggerListeners_(listeners, event, element, defaultFns);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/metal-dom/src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function registerEvents() {
// eslint-disable-next-line
if (
!related ||
(related !== target && !contains(target, related))
(related !== target && !target.contains(related))
) {
event.customType = eventName;
return callback(event);
Expand Down
18 changes: 0 additions & 18 deletions packages/metal-dom/test/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,6 @@ describe('dom', function() {
});
});

describe('contains', function() {
it('should check if element contains another', function() {
let element1 = document.createElement('div');
let element2 = document.createElement('div');
let element3 = document.createElement('div');
dom.append(element1, element2);
dom.enterDocument(element3);

assert.ok(dom.contains(element1, element2));
assert.ok(dom.contains(document, element3));

assert.ok(!dom.contains(element1, element3));
assert.ok(!dom.contains(element2, element1));
assert.ok(!dom.contains(document, element1));
assert.ok(!dom.contains(document, element2));
});
});

describe('manipulation', function() {
it('should append html string to parent element', function() {
let parent = document.createElement('div');
Expand Down

0 comments on commit b6027df

Please sign in to comment.