stephenscaff / read-smore

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

Can't change button text? #5

Closed Loosie94 closed 2 years ago

Loosie94 commented 3 years ago

Hi, love your read-more solution but I can't seem to change the text values within the trigger. I did the following:

    ReadMore.settings({
        moreLink: "Lees verder",
        lessLink: "Lees minder",
    });

    ReadMore.init();

What am I doing wrong?

shankardevy commented 3 years ago

This one works but I don't think this is ideal.

    ReadMore.settings = function(){
      return {
        content: document.querySelectorAll('.js-read-more'),
        originalContentArr: [],
        truncatedContentArr: [],
        moreLink: "Read More",
        lessLink: "Show less",
      }
    }
    ReadMore.init()
stephenscaff commented 2 years ago

Took me a sec to get around to improving the api for this lib, but finally did.

Now, with v2 you can now pass in options, which include editing the read more / read less text.

import ReadSmore from 'read-smore'

const readMores = document.querySelectorAll('.js-read-smore')

const options = {
  blockClassName: 'read-more',
  moreText: '"Some custom read more',
  lessText: 'Some custom read less'
}

ReadSmore(readMores, options).init()

I documented this in the Readme and added a Docs/Demo page