dropcap.js icon indicating copy to clipboard operation
dropcap.js copied to clipboard

Use -initial-letter if it is available

Open grorg opened this issue 11 years ago • 2 comments

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.

grorg avatar Oct 15 '14 23:10 grorg

Good idea. Added to the list!

sylvain-galineau avatar Oct 24 '14 18:10 sylvain-galineau

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...

sylvain-galineau avatar Dec 29 '14 21:12 sylvain-galineau