Created
June 15, 2020 13:22
-
-
Save burgalon/597de98c66600560e3b9267f62d9ea30 to your computer and use it in GitHub Desktop.
Rails Ellipsis helper with toggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ellipsis_text(s, limit=90) | |
if s&.length>limit | |
(s.slice(0..limit) + | |
'... ' + | |
content_tag(:a, 'More', | |
class: 'more semibold small', | |
href: '#', | |
onClick: "$(this.nextElementSibling).removeClass('hide'); $(this).addClass('hide'); return false;") + | |
content_tag(:span, s.slice(90..-1), class: 'hide')).html_safe | |
else | |
s | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment