stephenscaff / read-smore

A little Read More JS thing
https://stephenscaff.github.io/read-smore/
MIT License
28 stars 7 forks source link

Allow set moreText/lessText with data attributes #34

Closed danakil closed 10 months ago

danakil commented 10 months ago

Hello, Do you think it would make sense to allow the moreText/lessText to be configurable with data-attributes ? In a multilingual website, it would be much easier to do something like: <div class="js-read-smore" data-read-smore-more-text="..."> where one could integrate the translated content directly in the template (ex with twig/symfony: {{ 'read-more'|trans }}

stephenscaff commented 10 months ago

Sure, that makes sense (honestly, I checked to make sure the option didn't already exist.... been a while). If I recall, my thinking was that you'd always want to define that globally, so what's the point redefining it per instance? Didn't consider your use.

Would probs want to use js property, with data attribute overriding on instance if available (falling back to good ole read more/less if neither option is defined).

You wanna handle the PR? Can follow the examples from other data attributes stuff.

If not, I can try to get it cooking tomorrow.

Thanks!

stephenscaff commented 10 months ago

Okay, adding this capability. See #36

Will publish new version in a moment.