Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fix inserting touch action stylesheet for Shadow DOM Polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Apr 26, 2013
1 parent 8f5dae0 commit d4ca275
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/touch-action.js
Expand Up @@ -34,5 +34,10 @@
});
var el = document.createElement('style');
el.textContent = styles;
document.head.appendChild(el);
// Use querySelector instead of document.head to ensure that in
// ShadowDOM Polyfill that we have a wrapped head to append to.
var h = document.querySelector('head');
// document.write + document.head.appendChild = crazytown
// use insertBefore instead for correctness in ShadowDOM Polyfill
h.insertBefore(el, h.firstChild);
})();

3 comments on commit d4ca275

@sjmiles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just

document.write('<style>' + styles + '</style>');

instead of lines 37-42?

It worked when I tried it on Canary.

@dfreedm
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to leave the door open for placing a built PointerEvents in document body.

@sjmiles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good reason. Do you know why 'insertBefore' is necessary?

What if you used the old code (aka document.head.appendChild(el);), but did it asynchronously (on a timeout)?

Please sign in to comment.