Sha256: 8cb6889426373f64154893841b8c3658de89b7a751cb497fd08312dce82415ff

Contents?: true

Size: 1.2 KB

Versions: 66

Compression:

Stored size: 1.2 KB

Contents

(($) ->
  $.fn.extend 
    limit: ->
      $(this).each (i, e) ->
        input = $(this)
        limit = $(this).data("limit")
        label = $(this).closest("*:has(label)").find("label")
        horizontal = ($(this).closest(".form-horizontal").length > 0)
        counter = undefined
        counter = $("<span class=\"badge badge-info badge-mini\" data-tip=\"Caratteri disponibili\">" + limit + "</span>")
        if horizontal
          label.append "<br/>"
        else
          label.append " "
        label.append counter
        
        element = counter
        interval = undefined
        f = undefined
        self = $(this)
        $(this).focus ->
          interval = window.setInterval(substring, 100)

        $(this).blur ->
          clearInterval interval
          substring()

        substringFunction = "function substring(){ var val = $(self).val();var length = val.length;if(length > limit){$(self).val($(self).val().substring(0,limit));}"
        substringFunction += "if($(element).html() != limit-length){$(element).html((limit-length<=0)?'0':limit-length);}"  unless typeof element is "undefined"
        substringFunction += "}"
        eval substringFunction
        substring()
) jQuery

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
fullstack-admin-0.1.34 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.33 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.32 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.30 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.29 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.28 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.27 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.26 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.25 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.24 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.23 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.20 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.19 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.18 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.17 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.16 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.15 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.14 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.12 vendor/assets/javascripts/limit.js.coffee
fullstack-admin-0.1.11 vendor/assets/javascripts/limit.js.coffee