Skip to content

Commit

Permalink
Merge pull request #402 from diegonvs/401
Browse files Browse the repository at this point in the history
Fixes #401 | Revert deprecation of contains function
  • Loading branch information
jbalsas authored Nov 28, 2018
2 parents fe43748 + 2cfb601 commit b7c606a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 6 additions & 1 deletion packages/metal-dom/src/domNamed.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ export function buildFragment(htmlString) {
* @return {boolean}
*/
export function contains(element1, element2) {
return element1.contains(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);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/metal-dom/src/events.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import {isServerSide} from 'metal';
import {registerCustomEvent} from './dom';
import {registerCustomEvent, contains} from './dom';
import features from './features';

/**
Expand All @@ -23,7 +23,7 @@ function registerEvents() {
// eslint-disable-next-line
if (
!related ||
(related !== target && !target.contains(related))
(related !== target && !contains(target, related))
) {
event.customType = eventName;
return callback(event);
Expand Down
12 changes: 6 additions & 6 deletions packages/metal-dom/test/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ describe('dom', function() {
dom.append(element1, element2);
dom.enterDocument(element3);

assert.ok(dom.contains(element1, element2));
assert.ok(dom.contains(document, element3));
assert.isTrue(dom.contains(element1, element2));
assert.isTrue(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));
assert.isFalse(dom.contains(element1, element3));
assert.isFalse(dom.contains(element2, element1));
assert.isFalse(dom.contains(document, element1));
assert.isFalse(dom.contains(document, element2));
});
});

Expand Down

0 comments on commit b7c606a

Please sign in to comment.