Sha256: 951d7d914101b363b0db9b3ec4cd9048089c2c99d6835ccbbe90f5d633a009a4

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

#= require partystreusel/base

class Readmore extends Partystreusel.Base
  @className = 'Readmore'

  constructor: (el) ->
    super
    return if $.trim(@$el.text()) == ''

    unless @$el.hasClass('readmore--opened') || @$el.hasClass('readmore--closed')
      @$el.addClass('readmore--closed')

    @button = @$el.next()
    unless @button.hasClass('readmore__button')
      @button = @renderButton()
      @button.insertAfter(@$el)

    $(@button).bind 'click', @toggle

  toggle: (event) =>
    @$el.slideToggle =>
      @$el.toggleClass('readmore--opened readmore--closed')
      @button.text(@buttonText())
      @$el.css('display', "")
      @$el.removeAttr('style') if @$el.attr('style') == ''
      if @$el.hasClass('readmore--opened')
        @trigger('open', @$el)
      else
        @trigger('close', @$el)
    return false

  buttonState: ->
    return 'close' if @$el.hasClass('readmore--opened')
    'open'

  buttonText: (state = @buttonState()) ->
    I18n.t("readmore.button_text.#{state}")

  renderButton: =>
    text = @buttonText()

    $('<a></a>')
      .addClass('readmore__button')
      .attr('href', '#')
      .html(text)

Partystreusel.Readmore = Readmore

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
partystreusel-2.0.0 app/assets/javascripts/partystreusel/readmore.js.coffee
partystreusel-1.2.0 app/assets/javascripts/partystreusel/readmore.js.coffee
partystreusel-1.1.1 app/assets/javascripts/partystreusel/readmore.js.coffee
partystreusel-1.1.0 app/assets/javascripts/partystreusel/readmore.js.coffee