Re-introduce onclone option (Fix #1434)

This commit is contained in:
MoyuScript
2018-02-15 21:40:34 +08:00
parent 3a2f03bf0b
commit ff7753e1d0
4 changed files with 56 additions and 5 deletions

View File

@ -611,14 +611,21 @@ export const cloneWindow = (
documentClone.documentElement.style.left = -bounds.left + 'px';
documentClone.documentElement.style.position = 'absolute';
}
const result = Promise.resolve([
cloneIframeContainer,
cloner.clonedReferenceElement,
cloner.resourceLoader
]);
const onclone = options.onclone;
return cloner.clonedReferenceElement instanceof cloneWindow.HTMLElement ||
cloner.clonedReferenceElement instanceof ownerDocument.defaultView.HTMLElement ||
cloner.clonedReferenceElement instanceof HTMLElement
? Promise.resolve([
cloneIframeContainer,
cloner.clonedReferenceElement,
cloner.resourceLoader
])
? typeof onclone === 'function'
? Promise.resolve().then(() => onclone(documentClone)).then(() => result)
: result
: Promise.reject(
__DEV__
? `Error finding the ${referenceElement.nodeName} in the cloned document`

View File

@ -17,6 +17,7 @@ export type Options = {
ignoreElements?: HTMLElement => boolean,
imageTimeout: number,
logging: boolean,
onclone?: Document => void,
proxy: ?string,
removeContainer: ?boolean,
scale: number,