Skip to content

Instantly share code, notes, and snippets.

@Phathdt
Created January 28, 2018 16:20
Show Gist options
  • Save Phathdt/ec0b89ac6caf832cf83347d67c72e0ce to your computer and use it in GitHub Desktop.
Save Phathdt/ec0b89ac6caf832cf83347d67c72e0ce to your computer and use it in GitHub Desktop.
readmore function coffee and rails
- 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()
@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()
= render 'readmore', content: content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment