Skip to content

Commit

Permalink
combo
Browse files Browse the repository at this point in the history
use forked dialog-polyfill
window.CSS bug
contains && isConnected polyfills
toggleAttribvute correction
  • Loading branch information
nuxodin committed May 4, 2021
1 parent 215248b commit 3fb044f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 7 deletions.
5 changes: 3 additions & 2 deletions htmlfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ document.addEventListener('DOMContentLoaded', function () {
var polyfills = {
dialog: {
supports: 'HTMLDialogElement' in window,
js: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/dialog-polyfill.min.js',
js: 'https://cdn.jsdelivr.net/gh/nuxodin/[email protected]/dist/dialog-polyfill.min.js',
//js: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/dialog-polyfill.min.js',
//css: 'https://cdn.jsdelivr.net/npm/[email protected]/dialog-polyfill.css',
onfound: function(el){
dialogPolyfill.registerDialog(el);
Expand Down Expand Up @@ -114,4 +115,4 @@ function loadScript(path, cb, eb) {



}(window, document);
}(window, document);
38 changes: 35 additions & 3 deletions mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ addCombo('cdn.jsdelivr.net/gh/nuxodin/[email protected]/polyfills/Element/combo.js'
remove:1,
blur:1, // to use in SVGElement:
focus:1,
contains:1,
// contains:1, // moved to Node.prototype
classList:1,
getElementsByClassName:1,
children:1,
}, Element.prototype);

/* blank object "CSS" needed */
if (!window.CSS) CSS = {};
if (!window.CSS) window.CSS = {};
var lazyfills = {
Array:{
from:1,
Expand Down Expand Up @@ -90,8 +90,16 @@ var lazyfills = {
currentScript:1,
caretRangeFromPoint:1,
},
Node:{
prototype:{
contains:1,
isConnected:1,
},
},
Element:{
toggleAttribute:1
prototype:{
toggleAttribute:1
}
},
HTMLFormElement:{
prototype:{
Expand Down Expand Up @@ -237,6 +245,30 @@ function loadScriptSync(path) {
}
}


/*
if (!('contains' in Node.prototype)) {
Node.prototype.contains = function(el){
if (el instanceof CharacterData) {
if (!el.parentNode) return false;
el = el.parentNode;
}
if (this === el) return true;
if (this instanceof Document) {
return this.documentElement.contains(el)
}
return HTMLElement.prototype.contains.call(this, el);
}
}
if (!('isConnected' in Node.prototype)) {
Object.defineProperty(Node.prototype, 'isConnected',{
get:function(){
return this.ownerDocument.contains(this);
}
})
}
*/

/* very small polyfills, they are not worth adding to the service */
if (!NodeList.prototype.forEach) NodeList.prototype.forEach = Array.prototype.forEach; // ie11
if (!document.scrollingElement) document.scrollingElement = document.documentElement; // ie11
Expand Down
2 changes: 1 addition & 1 deletion polyfills/Element/combo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function mutationMacro(nodes) {
var props = [
'blur', // ie11
'focus',
'contains',
// 'contains', // needed at Node.prototype
'classList',
'getElementsByClassName',
// 'className',
Expand Down
13 changes: 13 additions & 0 deletions polyfills/Node/prototype/contains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if (!('contains' in Node.prototype)) {
Node.prototype.contains = function(el){
if (el instanceof CharacterData) {
if (!el.parentNode) return false;
el = el.parentNode;
}
if (this === el) return true;
if (this instanceof Document) {
return this.documentElement.contains(el)
}
return HTMLElement.prototype.contains.call(this, el);
}
}
7 changes: 7 additions & 0 deletions polyfills/Node/prototype/isConnected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if (!('isConnected' in Node.prototype)) {
Object.defineProperty(Node.prototype, 'isConnected',{
get:function(){
return this.ownerDocument.contains(this);
}
})
}
34 changes: 33 additions & 1 deletion test.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,39 @@
console.log(korean.hourCycle, japanese.hourCycle);
// expected output: "h24" "h12"

}, 1000)
}, 1000);


/* Node contains tests */

console.log(
'document.contains(document)',
document.contains(document)
)
console.log(
'document.documentElement.contains(document)',
document.documentElement.contains(document)
)
console.log(
'document.contains(document.documentElement)',
document.contains(document.documentElement)
)
console.log(
'document.documentElement.contains(document.documentElement)',
document.documentElement.contains(document.documentElement)
)
var textel = document.body.firstChild;
console.log(
'document.contains(textel)',
document.contains(textel)
)

/* is connected tests */

div = document.createElement('div');
console.log(div.isConnected);
document.body.append(div)
console.log(div.isConnected);

</script>

Expand Down

0 comments on commit 3fb044f

Please sign in to comment.