Sha256: 68ff3055dd9275a881c1f8406e8392cc7497d5af54cf9ad3e115e8a5bf11a4e0

Contents?: true

Size: 864 Bytes

Versions: 8

Compression:

Stored size: 864 Bytes

Contents

class Storytime.Dashboard.CharacterCounter
  init: ()->
    self = @
    $(".character-limit").each () ->
      display = $(this).find(".character-limit-display")
      limit = display.data("limit")
      input = $(this).find(".character-limit-input")
      contenteditable = $(this).find(".character-limit-contenteditable")
      self.setText(display, limit, input)

      if contenteditable.length > 0
        self.bind(contenteditable, input, display, limit)
      else
        self.bind(input, input, display, limit)

  setText: (display, limit, input) ->
    display.html limit - input.val().length

  bind: (field, input, display, limit) ->
    field.keypress((e) ->
      e.preventDefault() if (e.which is 32 or e.which > 0x20) and (input.val().length > limit - 1)
      return
    ).keyup(->
      display.html limit - input.val().length
      return
    )

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
storytime-2.1.6 app/assets/javascripts/storytime/character_counter.js.coffee
storytime-2.1.5 app/assets/javascripts/storytime/character_counter.js.coffee
storytime-2.1.4 app/assets/javascripts/storytime/character_counter.js.coffee
storytime-2.1.3 app/assets/javascripts/storytime/character_counter.js.coffee
storytime-2.1.2 app/assets/javascripts/storytime/character_counter.js.coffee
storytime-2.1.1 app/assets/javascripts/storytime/character_counter.js.coffee
storytime-2.1.0 app/assets/javascripts/storytime/character_counter.js.coffee
storytime-2.0.0 app/assets/javascripts/storytime/character_counter.js.coffee