dropcap.js
dropcap.js copied to clipboard
Use -initial-letter if it is available
First!!
Let's assume you can do this: window.CSS && window.CSS.supports("-webkit-initial-letter", "1");
I suggest you need two flags:
A. onlyExecuteIfNativeIsMissing (or something like that) where the JS will early return if the test above returned false. This would allow an author to write CSS rules that use initial-letter as well as include dropcap.js and not have them conflict.
B. preferNativeImplementation where dropcap.js would use initial-letter rather than setting the styles on the objects. This is actually quite annoying to do thanks to the 💩 that is the CSS OM, where you can't create a pseudo-style directly, but you have to create a whole new style rule, etc.
Good idea. Added to the list!
Update!
I have added support for A through the Dropcap.options.runEvenIfInitialLetterExists property (defaults to true)
Regarding B:
- As you point out, generating additional CSSOM rules is painful. Not so much creating additional rules but generating selectors is a bit awkward. One relatively easy way to support this would be to allow the caller to pass in a querySelector string instead of an HTMLElement or NodeList; when they do that we'd support preferNativeImplementation. It's not great but it's a start.
- But once I do the above I'll run into a wrinkle with WebKit Nightlies: the spec has swapped the order of the parameters so I'd sometimes get the wrong result in WK using a valid value. I think I'll try to submit a patch for this, then maybe hack this into dropcap.js...