Sha256: a164f989183276cfc4b2b4f4cee11f283dec77cbb030c8ac1b9cc5ba50aea0d3

Contents?: true

Size: 1.08 KB

Versions: 22

Compression:

Stored size: 1.08 KB

Contents

# jQuery plugin checkbox
$.fn.spinaSwitch = ->
  return this.each ->
    unless $(this).attr('data-plugin-switch')
      input = $(this)
      input.attr('data-plugin-switch', true)
      input.hide()

      # Check if it is checked
      if input.is(':checked')
        klass = "switch active"
      else
        klass = "switch"

      # Insert new HTML into the DOM
      input.after('<a href="#' + input.attr("id") + '" class="' + klass + '">
                    <span class="knob"></span>
                  </a>')

# Click handlers for checkbox
$(document).on 'click', 'a.switch', (e) ->
  toggleSwitch(e)

$(document).on 'touchend', 'a.switch', (e) ->
  toggleSwitch(e)

toggleSwitch = (e) ->
  checkbox = $(e.currentTarget)
  input = $(checkbox.attr("href"))

  if checkbox.hasClass('activated') || checkbox.hasClass('active') 
    checkbox.removeClass('active')
    checkbox.removeClass('activated')
    checkbox.addClass('deactivated')
    input.prop("checked", false)
  else
    checkbox.addClass('activated')
    checkbox.removeClass('deactivated')
    input.prop("checked", true)

  return false

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
spina-template-0.4.2 app/assets/javascripts/spina/switch.coffee
spina-template-0.4.1 app/assets/javascripts/spina/switch.coffee
spina-template-0.4.0 app/assets/javascripts/spina/switch.coffee
spina-template-0.3.3 app/assets/javascripts/spina/switch.coffee
spina-template-0.3.2 app/assets/javascripts/spina/switch.coffee
spina-template-0.3.1 app/assets/javascripts/spina/switch.coffee
spina-template-0.3.0 app/assets/javascripts/spina/switch.coffee
spina-template-0.2.18 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.17 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.16 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.15 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.14 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.13 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.12 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.11 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.10 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.9 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.8 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.7 app/assets/javascripts/spina/switch.js.coffee
spina-template-0.2.6 app/assets/javascripts/spina/switch.js.coffee