|
@@ -70,14 +70,13 @@
|
|
|
|
|
|
value = not not value
|
|
value = not not value
|
|
|
|
|
|
- @$element.prop("checked", value).trigger "change", skip
|
|
|
|
|
|
+ @$element.prop("checked", value).trigger "change.bootstrapSwitch", skip
|
|
@$element
|
|
@$element
|
|
|
|
|
|
toggleState: (skip) ->
|
|
toggleState: (skip) ->
|
|
return @$element if @options.disabled or @options.readonly
|
|
return @$element if @options.disabled or @options.readonly
|
|
|
|
|
|
- @$element.prop("checked", not @options.state).trigger "change", skip
|
|
|
|
-
|
|
|
|
|
|
+ @$element.prop("checked", not @options.state).trigger "change.bootstrapSwitch", skip
|
|
|
|
|
|
###
|
|
###
|
|
TODO: refactor
|
|
TODO: refactor
|
|
@@ -85,9 +84,9 @@
|
|
$element = @$element.not ":checked"
|
|
$element = @$element.not ":checked"
|
|
|
|
|
|
if uncheck
|
|
if uncheck
|
|
- $element.trigger "change", skip
|
|
|
|
|
|
+ $element.trigger "change.bootstrapSwitch", skip
|
|
else
|
|
else
|
|
- $element.prop("checked", not @$element.is ":checked").trigger "change", skip
|
|
|
|
|
|
+ $element.prop("checked", not @$element.is ":checked").trigger "change.bootstrapSwitch", skip
|
|
@$element
|
|
@$element
|
|
###
|
|
###
|
|
|
|
|
|
@@ -205,23 +204,24 @@
|
|
.removeClass(if checked then "switch-off" else "switch-on")
|
|
.removeClass(if checked then "switch-off" else "switch-on")
|
|
.addClass if checked then "switch-on" else "switch-off"
|
|
.addClass if checked then "switch-on" else "switch-off"
|
|
|
|
|
|
- $radios = @_radioSiblings()
|
|
|
|
- console.log $radios
|
|
|
|
- $radios.prop("checked", not value).trigger "change", skip if $radios
|
|
|
|
|
|
+ unless skip
|
|
|
|
+ $("[name='#{@$element.attr('name')}']").not(@$element).prop("checked", false).trigger "change.bootstrapSwitch", true if @$element.is ":radio"
|
|
|
|
+ @$element.trigger "switchChange", el: @$element, value: checked
|
|
|
|
|
|
- @$element.trigger "switchChange", el: @$element, value: checked if not skip
|
|
|
|
"focus.bootstrapSwitch": (e) =>
|
|
"focus.bootstrapSwitch": (e) =>
|
|
e.preventDefault()
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
e.stopPropagation()
|
|
e.stopImmediatePropagation()
|
|
e.stopImmediatePropagation()
|
|
|
|
|
|
@$wrapper.addClass "switch-focused"
|
|
@$wrapper.addClass "switch-focused"
|
|
|
|
+
|
|
"blur.bootstrapSwitch": (e) =>
|
|
"blur.bootstrapSwitch": (e) =>
|
|
e.preventDefault()
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
e.stopPropagation()
|
|
e.stopImmediatePropagation()
|
|
e.stopImmediatePropagation()
|
|
|
|
|
|
@$wrapper.removeClass "switch-focused"
|
|
@$wrapper.removeClass "switch-focused"
|
|
|
|
+
|
|
"keydown.bootstrapSwitch": (e) =>
|
|
"keydown.bootstrapSwitch": (e) =>
|
|
return if not e.which or @options.disabled or @options.readonly
|
|
return if not e.which or @options.disabled or @options.readonly
|
|
|
|
|
|
@@ -248,10 +248,11 @@
|
|
_handleHandlers: ->
|
|
_handleHandlers: ->
|
|
@$on.on "click.bootstrapSwitch", (e) =>
|
|
@$on.on "click.bootstrapSwitch", (e) =>
|
|
@state false
|
|
@state false
|
|
- @$element.trigger "focus"
|
|
|
|
|
|
+ @$element.trigger "focus.bootstrapSwitch"
|
|
|
|
+
|
|
@$off.on "click.bootstrapSwitch", (e) =>
|
|
@$off.on "click.bootstrapSwitch", (e) =>
|
|
@state true
|
|
@state true
|
|
- @$element.trigger "focus"
|
|
|
|
|
|
+ @$element.trigger "focus.bootstrapSwitch"
|
|
|
|
|
|
_labelHandlers: ->
|
|
_labelHandlers: ->
|
|
@$label.on
|
|
@$label.on
|
|
@@ -268,26 +269,29 @@
|
|
percent = right
|
|
percent = right
|
|
|
|
|
|
@$div.css "margin-left", "#{percent - right}%"
|
|
@$div.css "margin-left", "#{percent - right}%"
|
|
- @$element.trigger "focus"
|
|
|
|
|
|
+ @$element.trigger "focus.bootstrapSwitch"
|
|
|
|
+
|
|
"mousedown.bootstrapSwitch": (e) =>
|
|
"mousedown.bootstrapSwitch": (e) =>
|
|
return if @drag or @options.disabled or @options.readonly
|
|
return if @drag or @options.disabled or @options.readonly
|
|
|
|
|
|
@drag = true
|
|
@drag = true
|
|
@$wrapper.removeClass "switch-animate" if @options.animate
|
|
@$wrapper.removeClass "switch-animate" if @options.animate
|
|
- @$element.trigger "focus"
|
|
|
|
|
|
+ @$element.trigger "focus.bootstrapSwitch"
|
|
|
|
+
|
|
"mouseup.bootstrapSwitch": (e) =>
|
|
"mouseup.bootstrapSwitch": (e) =>
|
|
return unless @drag
|
|
return unless @drag
|
|
|
|
|
|
@drag = false
|
|
@drag = false
|
|
- @$element.prop("checked", (parseInt(@$div.css("margin-left"), 10) > -25)).trigger "change"
|
|
|
|
|
|
+ @$element.prop("checked", (parseInt(@$div.css("margin-left"), 10) > -25)).trigger "change.bootstrapSwitch"
|
|
@$div.css "margin-left", ""
|
|
@$div.css "margin-left", ""
|
|
@$wrapper.addClass "switch-animate" if @options.animate
|
|
@$wrapper.addClass "switch-animate" if @options.animate
|
|
|
|
+
|
|
"click.bootstrapSwitch": (e) =>
|
|
"click.bootstrapSwitch": (e) =>
|
|
e.preventDefault()
|
|
e.preventDefault()
|
|
e.stopImmediatePropagation()
|
|
e.stopImmediatePropagation()
|
|
|
|
|
|
@toggleState()
|
|
@toggleState()
|
|
- @$element.trigger "focus"
|
|
|
|
|
|
+ @$element.trigger "focus.bootstrapSwitch"
|
|
|
|
|
|
_formHandler: ->
|
|
_formHandler: ->
|
|
$form = @$element.closest "form"
|
|
$form = @$element.closest "form"
|
|
@@ -304,14 +308,6 @@
|
|
, 1
|
|
, 1
|
|
.data "bootstrap-switch", true
|
|
.data "bootstrap-switch", true
|
|
|
|
|
|
- _radioSiblings: ->
|
|
|
|
- return false unless @$element.is ":radio"
|
|
|
|
-
|
|
|
|
- $elements = $("[name='#{@$element.attr('name')}']").not @$element
|
|
|
|
-
|
|
|
|
- return false unless $elements.length
|
|
|
|
- $elements
|
|
|
|
-
|
|
|
|
$.fn.extend bootstrapSwitch: (option, args...) ->
|
|
$.fn.extend bootstrapSwitch: (option, args...) ->
|
|
ret = @
|
|
ret = @
|
|
@each ->
|
|
@each ->
|