Sha256: e1f5a42a817ceb48b75077a4117bfa6d569d4c3147ebd754610d3e05b254b1eb

Contents?: true

Size: 1.55 KB

Versions: 28

Compression:

Stored size: 1.55 KB

Contents

class IuguUI.Checkbox
  defaults:
    none: false

  el: undefined

  @load: ( context ) ->
    selector = "[data-type='iux.form.checkbox']"
    if context
      elements = context.find(selector)
    else
      elements = $(selector)

    return if elements.length == 0
    
    elements.each ->
      return if $(@).data("iux.initialized") == true

      new IuguUI.Checkbox
        el: @

      $(@).data "iux.initialized", true

  constructor: ( options ) ->
    @initialize( options )
  
  initialize: ( options ) ->
    _.bindAll @
    @options = _.extend {}, @defaults, options

    return null unless @options.el

    @el = $(@options.el) if @options.el

    checkbox_classes = "checkbox"

    label_on = if @el.data("on") then @el.data("on") else undefined
    label_off = if @el.data("off") then @el.data("off") else undefined

    if @el.data("mode") == "switch"
      checkbox_classes = " switch"

    optional_labels = ""

    optional_labels += '<div class="label_decorator_on"> ' + label_on + '</div>' if label_on
    optional_labels += '<div class="label_decorator_off"> ' + label_off + '</div>' if label_off

    @decorator = $('<a>',
      class: checkbox_classes + ( if @el.is(":checked") then ' selected' else '')
      html: '<div class="outer_decorator"><div class="inner_decorator"><span>✓</span></div>' + optional_labels + '</div>'
      "data-mode": "toggle"
      "data-input": @el.attr("id")
    )

    @decorator.insertAfter( @el )

    new IuguUI.Button
      el: @decorator
      context: @el

@IuguUI.Checkbox = IuguUI.Checkbox

$ ->
  IuguUI.Checkbox.load()

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
iugu-ux-1.0.25 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.24 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.23 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.22 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.21 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.20 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.19 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.18 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.17 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.16 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.15 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.14 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.13 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.12 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.11 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.10 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.9 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.8 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.7 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee
iugu-ux-1.0.6 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-checkbox.js.coffee