Sha256: 94960f5a3d0e38deefc7c5313d46d0d3cb511295331b43a69deab7fc8a1f778f

Contents?: true

Size: 884 Bytes

Versions: 10

Compression:

Stored size: 884 Bytes

Contents

# Autogrowing textarea.
class window.modularity.AutogrowTextArea extends modularity.Module

  constructor: (container) ->
    super
    @textarea = @container[0]
    @textarea.style.height = "auto"
    @textarea.style.overflow = "hidden"
    @container.keyup @grow
    @container.focus @grow
    @container.blur @grow

    # How many characters per line.
    @characters_per_line = this.textarea.cols

    # The initial (minimal) number of rows.
    @min_rows = this.textarea.rows

    @grow()


  # Sets the height of the textarea according to the content.
  grow: =>
    @textarea.rows = Math.max modularity.AutogrowTextArea.lines(@characters_per_line, @textarea.value), @min_rows

  # Returns the number of lines 
  @lines: (width, text) ->
    lines_count = 0
    lines = text.split(/\n/)
    lines_count += Math.floor((line.length / width) + 1) for line in lines
    lines_count

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
modularity-rails-0.15.0 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.14.0 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.12.3 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.12.2 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.12.1 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.12.0 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.11.1 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.11.0 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.10.0 vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
modularity-rails-0.9.3 vendor/assets/javascripts/modules/autogrow_textarea.coffee