Created
January 28, 2018 16:20
-
-
Save Phathdt/ec0b89ac6caf832cf83347d67c72e0ce to your computer and use it in GitHub Desktop.
readmore function coffee and rails
This file contains 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
- NUMBER_CHAR_HIDDEN = 300 | |
- if content.length < NUMBER_CHAR_HIDDEN | |
p = content | |
- else | |
p | |
= content[0..NUMBER_CHAR_HIDDEN] | |
a.read-more-show.hide href="#" = "Read More" | |
span.read-more-content | |
= content[NUMBER_CHAR_HIDDEN + 1..-1] | |
a.read-more-hide.hide href="#" = "Read Less" | |
javascript: | |
readMore() |
This file contains 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
@readMore = -> | |
$('.read-more-content').addClass 'hide' | |
$('.read-more-show, .read-more-hide').removeClass 'hide' | |
$('.read-more-show').on 'click', (e) -> | |
$(this).next('.read-more-content').removeClass 'hide' | |
$(this).addClass 'hide' | |
e.preventDefault() | |
$('.read-more-hide').on 'click', (e) -> | |
p = $(this).parent('.read-more-content') | |
p.addClass 'hide' | |
p.prev('.read-more-show').removeClass 'hide' | |
e.preventDefault() |
This file contains 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
= render 'readmore', content: content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment