forked from fanruan/fineui
Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
treecat-罗群 | 0ed3e845b1 | 1 year ago |
Treecat | 3995479d53 | 1 year ago |
Treecat | f85867bb66 | 1 year ago |
Jimmy.Chai-柴嘉明 | f4f58e24e0 | 1 year ago |
jimmychai | 6c62a7c695 | 1 year ago |
Jimmy.Chai-柴嘉明 | c057e5cd2c | 1 year ago |
jimmychai | c5dfb11f1f | 1 year ago |
Kobi-蒋科斌 | 0143741ef5 | 1 year ago |
Kobi | 2b50b02d79 | 1 year ago |
Kobi | 3b4ffbbe45 | 1 year ago |
Treecat | ba1e19280c | 2 years ago |
6 changed files with 26 additions and 101 deletions
@ -1,96 +0,0 @@
|
||||
/** |
||||
* 用于 jquery 在 worker 环境或者 V8 引擎的 polyfill |
||||
*/ |
||||
// import { _global } from "@/core/0.foundation";
|
||||
|
||||
const _global = globalThis; |
||||
|
||||
const document = {}; |
||||
const fakeElement = Object.create(document); |
||||
|
||||
Object.assign(document, { |
||||
parentNode: null, |
||||
nodeType: 9, |
||||
head: fakeElement, |
||||
body: fakeElement, |
||||
ownerDocument: document, |
||||
documentElement: document, |
||||
toString() { |
||||
return "FakeDocument"; |
||||
}, |
||||
appendChild(child) { |
||||
return child; |
||||
}, |
||||
implementation: { |
||||
createHTMLDocument() { |
||||
return { |
||||
body: { |
||||
childNodes: [], |
||||
}, |
||||
}; |
||||
}, |
||||
createDocumentFragment() { |
||||
return this; |
||||
}, |
||||
}, |
||||
getElementById() { |
||||
return fakeElement; |
||||
}, |
||||
createElement() { |
||||
return fakeElement; |
||||
}, |
||||
createDocumentFragment() { |
||||
return this; |
||||
}, |
||||
cloneNode() { |
||||
return this; |
||||
}, |
||||
getElementsByTagName() { |
||||
return [fakeElement]; |
||||
}, |
||||
getElementsByClassName() { |
||||
return [fakeElement]; |
||||
}, |
||||
setAttribute() { |
||||
return null; |
||||
}, |
||||
getAttribute() { |
||||
return null; |
||||
}, |
||||
removeChild() { |
||||
return null; |
||||
}, |
||||
addEventListener() { |
||||
return null; |
||||
}, |
||||
removeEventListener() { |
||||
return null; |
||||
}, |
||||
}); |
||||
|
||||
Object.assign(fakeElement, { |
||||
nodeType: 1, |
||||
style: {}, |
||||
ownerDocument: document, |
||||
parentNod: fakeElement, |
||||
firstChild: fakeElement, |
||||
lastChild: fakeElement, |
||||
toString() { |
||||
return "FakeElement"; |
||||
}, |
||||
}); |
||||
|
||||
function polyfillProps(key, obj) { |
||||
_global[key] = _global[key] || obj; |
||||
if (typeof obj === "object") { |
||||
try { |
||||
Object.assign(_global[key], obj); |
||||
} catch(err) { |
||||
// _global[key] 可能只有 get 方法
|
||||
} |
||||
} |
||||
} |
||||
|
||||
_global.window = _global; |
||||
polyfillProps("XMLHttpRequest", function () {}); |
||||
polyfillProps("document", document); |
Loading…
Reference in new issue