Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage for toggling? #10

Closed
MartinMalinda opened this issue Nov 2, 2020 · 5 comments
Closed

usage for toggling? #10

MartinMalinda opened this issue Nov 2, 2020 · 5 comments

Comments

@MartinMalinda
Copy link

Thanks for the lib, it seems to do the job well in quite a few lines of JS.

But since it replaces the text in place, it makes it a bit harder to implement any kind of toggling functionality. If there was a function to return the clamped text instead of mutating the element, it would make the toggling easier to implement for me in Vue.

@tvanc
Copy link
Owner

tvanc commented Nov 3, 2020

From the order of the issues you opened, I'm guessing you attempted to implement the requested functionality by saving the clamped element's original markup/text and then listening for clamping events, saving the resulting markup and then restoring?

Are you able to achieve the desired outcome more easily now that the clamp events don't fire unless clamping actually occurs?

@MartinMalinda
Copy link
Author

@tvanc thanks, I did managed to implement it now! The only issue now is that the algorithm is too good at clamping at the end of line, while I would like to leave space for the "show more" button. But I'll see if I could apply an adhoc mutation to fix that case.

@MartinMalinda
Copy link
Author

MartinMalinda commented Nov 5, 2020

el.addEventListener("lineclamp.clamp", () => {
  isClamped.value = true;
  el.textContent = el.textContent?.slice(0, -20) + "... ";
});

Not flawless, but it seems like it does the job! I was afraid that I'd be continously losing the text on toggling but it's not the case.

@tvanc
Copy link
Owner

tvanc commented Nov 6, 2020

Excellent! I'm glad to hear it. If your use of my lib is public I wouldn't mind seeing it?

@tvanc tvanc closed this as completed Nov 6, 2020
@MartinMalinda
Copy link
Author

So far it's not public, but I might later release it as something like vue-lineclamp or something like that. Will share a link here when that happens!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants