Skip to content

Commit

Permalink
Partial fix fro the issue #17
Browse files Browse the repository at this point in the history
* References to host objects need to be extracted from the global object associated with provided element
  • Loading branch information
que-etc committed Nov 16, 2017
1 parent 733984e commit 10d761d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/ResizeObserverSPI.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Map} from './shims/es6-collections.js';
import ResizeObservation from './ResizeObservation.js';
import ResizeObserverEntry from './ResizeObserverEntry.js';
import getWindowOf from './utils/getWindowOf.js';

export default class ResizeObserverSPI {
/**
Expand Down Expand Up @@ -76,7 +77,7 @@ export default class ResizeObserverSPI {
return;
}

if (!(target instanceof Element)) {
if (!(target instanceof getWindowOf(target).Element)) {
throw new TypeError('parameter 1 is not of type "Element".');
}

Expand Down Expand Up @@ -111,7 +112,7 @@ export default class ResizeObserverSPI {
return;
}

if (!(target instanceof Element)) {
if (!(target instanceof getWindowOf(target).Element)) {
throw new TypeError('parameter 1 is not of type "Element".');
}

Expand Down
13 changes: 7 additions & 6 deletions src/utils/geometry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import defineConfigurable from './defineConfigurable.js';
import getWindowOf from './getWindowOf.js';
import isBrowser from './isBrowser.js';

// Placeholder of an empty content rectangle.
Expand Down Expand Up @@ -84,7 +85,7 @@ function getHTMLElementContentRect(target) {
return emptyRect;
}

const styles = getComputedStyle(target);
const styles = getWindowOf(target).getComputedStyle(target);
const paddings = getPaddings(styles);
const horizPad = paddings.left + paddings.right;
const vertPad = paddings.top + paddings.bottom;
Expand Down Expand Up @@ -152,15 +153,15 @@ function getHTMLElementContentRect(target) {
const isSVGGraphicsElement = (() => {
// Some browsers, namely IE and Edge, don't have the SVGGraphicsElement
// interface.
if (typeof SVGGraphicsElement != 'undefined') {
return target => target instanceof SVGGraphicsElement;
if (typeof SVGGraphicsElement !== 'undefined') {
return target => target instanceof getWindowOf(target).SVGGraphicsElement;
}

// If it's so, then check that element is at least an instance of the
// SVGElement and that it has the "getBBox" method.
// eslint-disable-next-line no-extra-parens
return target => (
target instanceof SVGElement &&
target instanceof getWindowOf(target).SVGElement &&
typeof target.getBBox === 'function'
);
})();
Expand All @@ -172,7 +173,7 @@ const isSVGGraphicsElement = (() => {
* @returns {boolean}
*/
function isDocumentElement(target) {
return target === document.documentElement;
return target === getWindowOf(target).document.documentElement;
}

/**
Expand Down Expand Up @@ -202,7 +203,7 @@ export function getContentRect(target) {
*/
export function createReadOnlyRect({x, y, width, height}) {
// If DOMRectReadOnly is available use it as a prototype for the rectangle.
const Constr = typeof DOMRectReadOnly != 'undefined' ? DOMRectReadOnly : Object;
const Constr = typeof DOMRectReadOnly !== 'undefined' ? DOMRectReadOnly : Object;
const rect = Object.create(Constr.prototype);

// Rectangle's properties are not writable and non-enumerable.
Expand Down
18 changes: 18 additions & 0 deletions src/utils/getWindowOf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import global from '../shims/global.js';

/**
* Returns the global object associated with provided element.
*
* @param {Object} target
* @returns {Object}
*/
export default target => {
// Assume that the element is an instance of Node, which means that it
// has the "ownerDocument" property from which we can retrieve a
// corresponding global object.
const ownerGlobal = target && target.ownerDocument && target.ownerDocument.defaultView;

// Return the local global object if it's not possible extract one from
// provided element.
return ownerGlobal || global;
};

0 comments on commit 10d761d

Please sign in to comment.