|
|
@ -1,5 +1,4 @@
|
|
|
|
import { has_prop } from "./utils";
|
|
|
|
import { has_prop } from "./utils";
|
|
|
|
import { is_cors } from "./environment";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function append(target: Node, node: Node) {
|
|
|
|
export function append(target: Node, node: Node) {
|
|
|
|
target.appendChild(node);
|
|
|
|
target.appendChild(node);
|
|
|
@ -235,6 +234,26 @@ export function select_multiple_value(select) {
|
|
|
|
return [].map.call(select.querySelectorAll(':checked'), option => option.__value);
|
|
|
|
return [].map.call(select.querySelectorAll(':checked'), option => option.__value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// unfortunately this can't be a constant as that wouldn't be tree-shakeable
|
|
|
|
|
|
|
|
// so we cache the result instead
|
|
|
|
|
|
|
|
let crossorigin: boolean;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function is_crossorigin() {
|
|
|
|
|
|
|
|
if (crossorigin === undefined) {
|
|
|
|
|
|
|
|
crossorigin = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (typeof window !== 'undefined' && window.parent) {
|
|
|
|
|
|
|
|
void window.parent.document;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
crossorigin = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return crossorigin;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function add_resize_listener(node: HTMLElement, fn: () => void) {
|
|
|
|
export function add_resize_listener(node: HTMLElement, fn: () => void) {
|
|
|
|
const computed_style = getComputedStyle(node);
|
|
|
|
const computed_style = getComputedStyle(node);
|
|
|
|
const z_index = (parseInt(computed_style.zIndex) || 0) - 1;
|
|
|
|
const z_index = (parseInt(computed_style.zIndex) || 0) - 1;
|
|
|
@ -251,9 +270,11 @@ export function add_resize_listener(node: HTMLElement, fn: () => void) {
|
|
|
|
iframe.setAttribute('aria-hidden', 'true');
|
|
|
|
iframe.setAttribute('aria-hidden', 'true');
|
|
|
|
iframe.tabIndex = -1;
|
|
|
|
iframe.tabIndex = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const crossorigin = is_crossorigin();
|
|
|
|
|
|
|
|
|
|
|
|
let unsubscribe: () => void;
|
|
|
|
let unsubscribe: () => void;
|
|
|
|
|
|
|
|
|
|
|
|
if (is_cors) {
|
|
|
|
if (crossorigin) {
|
|
|
|
iframe.src = `data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}</script>`;
|
|
|
|
iframe.src = `data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}</script>`;
|
|
|
|
unsubscribe = listen(window, 'message', (event: MessageEvent) => {
|
|
|
|
unsubscribe = listen(window, 'message', (event: MessageEvent) => {
|
|
|
|
if (event.source === iframe.contentWindow) fn();
|
|
|
|
if (event.source === iframe.contentWindow) fn();
|
|
|
@ -268,7 +289,7 @@ export function add_resize_listener(node: HTMLElement, fn: () => void) {
|
|
|
|
append(node, iframe);
|
|
|
|
append(node, iframe);
|
|
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
return () => {
|
|
|
|
if (is_cors) {
|
|
|
|
if (crossorigin) {
|
|
|
|
unsubscribe();
|
|
|
|
unsubscribe();
|
|
|
|
} else if (unsubscribe && iframe.contentWindow) {
|
|
|
|
} else if (unsubscribe && iframe.contentWindow) {
|
|
|
|
unsubscribe();
|
|
|
|
unsubscribe();
|
|
|
@ -333,4 +354,4 @@ export class HtmlTag {
|
|
|
|
d() {
|
|
|
|
d() {
|
|
|
|
this.n.forEach(detach);
|
|
|
|
this.n.forEach(detach);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|