Try to support CSS touch-action rather than using attributes #151
Comments
Investigate what hammer.js is doing: https://github.com/hammerjs/hammer.js/blob/master/src/touchaction.js |
If I understand correctly, hammer.js gets |
Also worth tracking the work being done by the Houdini WG to surface more CSS features to scripts |
Here's how hand.js does it: https://github.com/deltakosh/handjs/blob/master/src/hand.css.js |
Unless i'm missing something it looks like the handjs approach only runs once when the page initially loads and will not account for elements added at any point after that. |
As a follow up to conversations with the hammer.js team and in todays meeting we should attempt to collaborate on the best way to handle touch action. @jacobrossi has also offered to put the two teams in touch with someone from http://ecsstender.org/ to see what we can do about attempting to support the actual css. |
When I was working on eCSStender, Ajax was the only way to accurately get the CSS info. @jzaefferer is dead on with that. That said, we have a fully-functioning CSS parser in JS. I haven’t touched it in a while, so it could probably be optimized, but it’s there. |
@aarongustafson our main concern here I think is performance size, PEP is just a polyfill so we would not want to add too much overhead to it. There is only a single css property that we care about so ideally we would want to highly optimize around that. @jacobrossi Am i crazy or didn't you tell me there was a way to get the raw stylesheet in IE to avoid the ajax? Not that that helps else where but its something... |
In terms of bare-bones implementation, what you’re gonna need is a parser The actual CSS file parser in eCSStender isn’t all that big. Neither is the I’d recommend cacheing the result (and the raw CSS) in On Thu, Jul 16, 2015 at 2:01 PM, Alexander Schmitz <notifications@github.com
|
@aarongustafson
Not looking for firm answers or anything just wondering if you think there is anyway this is feasible or if based on your experience is this just a no go for our use case? |
I think postcss is probably the most well-known/maintained JS CSS parser today: https://github.com/postcss Also, since, again, this is a domain that the Houdini WG is supposed to be tackling, it might be worth following their https://wiki.css-houdini.org/background page (though admittedly it doesn't appear to have any relevant resources to this right now). |
Just a side-note to say that yes, that's correct, and there is also no inheritance, which may simplify matters https://w3c.github.io/pointerevents/#the-touch-action-css-property |
@patrickhlauke thank you for confirming that and yeah I forgot about no inheritance that simplifies it too. That means we only need to find containing rules, and compare the selector specificity if there is more then one that applies. @stuartpb Yeah i don't think we want or need a full css parser we only need to find rules actually containing and compare selector specificity to pick the right one. The Houdini group while applicable i don't think will be seeing any useable results in the time frame that this will really matter here but worth keeping an eye out for forsure. |
also, perhaps an edge case, but: worth also checking any |
@patrickhlauke that actually brings to mind an interesting idea here to super easily support this with strict limits. So right now we require you to use an attribute |
@patrickhlauke @arschmitz - supporting |
@msegado Agreed i have a POC for this ill be posting very shortly just working out a few things. |
@arschmitz Sweet! Yet another benefit: it'll allow default browser behavior for those that support |
So to sum up my understanding: Right now, PEP tells users that they need to specify a PEP-specific This would change it so users could specify a Sounds good to me. One thought: does PEP have some kind of callback or reporting mechanism that would allow code to only execute if PEP is being used to provide pointer events (rather than native pointer events)? If not, I think that would be a good idea, since it would allow implementations to add this inlined rule conditionally based on some kind of application-specific logic. |
a simple check for |
Worked on a POC for using the native style over the weekend. I implemented it in a small fast-click we have been working on for hammer.js that was previously using the touch-action attribute like PEP. There is one main gotcha to this which is if the style attributes properties are set directly the browser will sanitize the style attribute of any invalid properties. To work around this I used a mutation observer to restore the touch-action property when ever it was removed. PEP is already using a mutation observer to watch the code: https://github.com/hammerjs/hammer-time/blob/master/hammer-time.js @stuartpb PEP currently creates a stylesheet and sets touch action for elements within it to support native implementations of |
@arschmitz @stuartpb Huh, it's actually only creating the stylesheet if window.PointerEvent exists, which explains the issue I was having with Chrome in #211 (Chrome supports the touch-action CSS property but does not yet support native pointer events). I'll comment more over there. |
@msegado ah your right we will need to fix that. This was written before chrome supported touch-action so at the time this was a valid check. We will need to update this if we stick with the attribute. |
http://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome Despite it's downvote for mechanical reasons, |
@runspired I think in this case we should just switch from looking for It will do what we actually want which is install when native |
👍 |
@arschmitz Agreed. (I think IE10 uses |
@msegado Yup I believe you are correct. |
We talked about this in the meeting today and we have decided to move to using the style attribute as a way to support using valid css. I have a PR in progress for this. @stuartpb since we have done only one alpha release we are not going to provide backcompat for the touch-action attribute. |
Sweet! A quick question: what's the plan for |
@msegado: Depends. Do you want to support IE10 or not? IE10 is prefixed. |
@msegado i'm not sure us doing it automatically would be wise. Currently pep is a complete noop on ie10 this would mean doing a non insignificant amount of work to make it possible in any real sense to sync the attributes. More so when you consider the lack of mutation observers in ie10. |
Ack, sorry, I keep forgetting that ie10 has native pointer events... |
I could have sworn we mentioned this in this thread, maybe it was somewhere else, but the big problem with relying on unrecognized property names in an inline style is that they get removed whenever the content of the inline style string is recalculated through any update to I don't like this behavior at all, and I've started a WICG thread about changing it, but it is the reality of the current browser landscape (what polyfills, by definition, have to deal with). For this reason, I think it's important to keep recognition of the |
@stuartpb that is not an issue if you see the code and explination i posted above, and the meeting discussion http://irc.jquery.org/%23jquery-meeting/default_%23jquery-meeting_20150730.log.html#t09:10:54 this is easily handled with a mutation observer which we are already using. There is no need to keep the touch-action property. |
There it is, I was trying to find that post: #151 (comment) Good to know this can actually be polyfilled at a higher level for the WICG thread I posted. |
About using xhr to load the css: why not offering an option to enable it? on by default (for KISS), it could be turned off by web developers who are concerned about performance. As a side note, starting yesterday we discontinued hand.js in favor of PEP :) |
@arschmitz 🙈 🙉 🙊 |
@arschmitz ping |
Setting |
We sadly need to check the attribute at least initially to be able to get the value from the markup |
Browsers like Chrome that have native support for the CSS property make this easy, otherwise its necessary to load the original stylesheet via ajax and parse them manually, since unsupported CSS properties are just dropped when the browser parses them.
The text was updated successfully, but these errors were encountered: