kswedberg / jquery-expander

Expand and Collapse HTML content

Home Page:https://kswedberg.github.io/jquery-expander/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sliceOn should get indexOf summaryText with innerHTML

mkormendy opened this issue · comments

I believe that sliceOn should get the indexOf the summaryText without any html markup characters.

For instance, lets say we have html markup for a link within the beginning content up to the slicePoint. Depending on the length of the URL in that link, it could possibly add unnecessary characters to the indexOf count for the sliceOn trigger -- unintentionally, this would cause the sliceOn trigger to NOT fire as expected. Furthermore, if we have other html markup in the beginning content paragraph, it just adds to the problem.

I am attempting to fix this issue and will try to push my changes to the repository.

One problem that I am seeing is that if we try to get the indexOf the text without html characters, that could inadvertently remove the sliceOn code that we are attempting to find the indexOf to slice the text with.

A workaround would be to find the sliceOn code of the full text with HTML markup, and then change it to some temporary piece of arbitrary text that someone wouldn't likely write in their code, like the string "ExpandMoreHere374216623". Then, as we are indexOf'ing for the sliceOn point, strip the full text of HTML, then find the Expand More here to get a proper character count to compare against the slicePoint. If the condition passes as less than the slicePoint, then go back to the full text markup with the sliceOn text and html markup, and do the slice at the sliceOn location.

If that is confusing, let me know, but that's what I think would be bulletproof and more semantic version of calculating the slicePoint vs indexOf sliceOn.

Pull request here: #100

I tested it and it works as expected, ignores html markup when testing condition against slicePoint value.
Very useful in situations where text has html markup of varying lengths (link urls, image urls, inline markup).