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

Commit

Permalink
Only generate parts of touch-action style that are useful
Browse files Browse the repository at this point in the history
Fixes #133
  • Loading branch information
dfreedm committed Mar 10, 2014
1 parent f2964bc commit 168de03
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/touch-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
(function() {
function shadowSelector(v) {
return 'body ^^ ' + selector(v);
return 'body /shadow-deep/ ' + selector(v);

This comment has been minimized.

Copy link
@sapjax

sapjax Apr 18, 2014

is it should be '/deep/' ?

}
function selector(v) {
return '[touch-action="' + v + '"]';
Expand All @@ -27,16 +27,29 @@
}
];
var styles = '';
attrib2css.forEach(function(r) {
if (String(r) === r) {
styles += selector(r) + rule(r) + '\n';
styles += shadowSelector(r) + rule(r) + '\n';
} else {
styles += r.selectors.map(selector) + rule(r.rule) + '\n';
styles += r.selectors.map(shadowSelector) + rule(r.rule) + '\n';
}
});
var el = document.createElement('style');
el.textContent = styles;
document.head.appendChild(el);
// only install stylesheet if the browser has touch action support
var head = document.head;
var hasNativePE = window.PointerEvent || window.MSPointerEvent;
// only add shadow selectors if shadowdom is supported
var hasShadowRoot = !window.ShadowDOMPolyfill && document.head.createShadowRoot;

if (hasNativePE) {
attrib2css.forEach(function(r) {
if (String(r) === r) {
styles += selector(r) + rule(r) + '\n';
if (hasShadowRoot) {
styles += shadowSelector(r) + rule(r) + '\n';
}
} else {
styles += r.selectors.map(selector) + rule(r.rule) + '\n';
if (hasShadowRoot) {
styles += r.selectors.map(shadowSelector) + rule(r.rule) + '\n';
}
}
});

var el = document.createElement('style');
el.textContent = styles;
document.head.appendChild(el);
}
})();

0 comments on commit 168de03

Please sign in to comment.