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

Commit 168de03

Browse files
committed
Only generate parts of touch-action style that are useful
Fixes #133
1 parent f2964bc commit 168de03

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/touch-action.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
(function() {
77
function shadowSelector(v) {
8-
return 'body ^^ ' + selector(v);
8+
return 'body /shadow-deep/ ' + selector(v);
99
}
1010
function selector(v) {
1111
return '[touch-action="' + v + '"]';
@@ -27,16 +27,29 @@
2727
}
2828
];
2929
var styles = '';
30-
attrib2css.forEach(function(r) {
31-
if (String(r) === r) {
32-
styles += selector(r) + rule(r) + '\n';
33-
styles += shadowSelector(r) + rule(r) + '\n';
34-
} else {
35-
styles += r.selectors.map(selector) + rule(r.rule) + '\n';
36-
styles += r.selectors.map(shadowSelector) + rule(r.rule) + '\n';
37-
}
38-
});
39-
var el = document.createElement('style');
40-
el.textContent = styles;
41-
document.head.appendChild(el);
30+
// only install stylesheet if the browser has touch action support
31+
var head = document.head;
32+
var hasNativePE = window.PointerEvent || window.MSPointerEvent;
33+
// only add shadow selectors if shadowdom is supported
34+
var hasShadowRoot = !window.ShadowDOMPolyfill && document.head.createShadowRoot;
35+
36+
if (hasNativePE) {
37+
attrib2css.forEach(function(r) {
38+
if (String(r) === r) {
39+
styles += selector(r) + rule(r) + '\n';
40+
if (hasShadowRoot) {
41+
styles += shadowSelector(r) + rule(r) + '\n';
42+
}
43+
} else {
44+
styles += r.selectors.map(selector) + rule(r.rule) + '\n';
45+
if (hasShadowRoot) {
46+
styles += r.selectors.map(shadowSelector) + rule(r.rule) + '\n';
47+
}
48+
}
49+
});
50+
51+
var el = document.createElement('style');
52+
el.textContent = styles;
53+
document.head.appendChild(el);
54+
}
4255
})();

0 commit comments

Comments
 (0)