Permalink
Browse files

keep in sync when original checkbox's value changes. Fixes #48

  • Loading branch information...
1 parent 753b119 commit 523468810a4fb7bd1618b62bf64fc0893eaa72b3 @dnagir committed Nov 16, 2011
View
8 coffee/iphone-style-checkboxes.coffee
@@ -119,7 +119,7 @@ class iOSCheckbox
iOSCheckbox.dragging = null
@didChange()
- refresh: -> @didChange()
+ refresh: -> @didChange() #TODO: Verify - this might fire event unnecessarily
didChange: ->
@onChange?(@elem, @elem.prop('checked'))
@@ -148,6 +148,10 @@ class iOSCheckbox
$(document).unbind 'mousemove touchmove', localMouseMove
$(document).unbind 'mouseup touchend', localMouseUp
+ # The original checkbox value might be changed by clickig on the associated label or other means
+ # To make sure we are in sync:
+ @elem.change -> self.refresh()
+
# A mousedown anywhere in the control will start tracking for dragging
@container.bind 'mousedown touchstart', (event) ->
self.onMouseDown.apply(self, arguments)
@@ -262,4 +266,4 @@ $.fn.iOSCheckbox = (options={}) ->
dataName: 'iOSCheckbox'
})
- this.iphoneStyle(opts)
+ this.iphoneStyle(opts)
View
4 compile
@@ -0,0 +1,4 @@
+coffee -o jquery -c coffee/iphone-style-checkboxes.coffee
+pushd rails
+rake update
+popd
View
3 jquery/iphone-style-checkboxes.js
@@ -157,6 +157,9 @@
$(document).unbind('mousemove touchmove', localMouseMove);
return $(document).unbind('mouseup touchend', localMouseUp);
};
+ this.elem.change(function() {
+ return self.refresh();
+ });
return this.container.bind('mousedown touchstart', function(event) {
self.onMouseDown.apply(self, arguments);
$(document).bind('mousemove touchmove', localMouseMove);
View
3 rails/vendor/assets/javascripts/ios-checkboxes.js
@@ -159,6 +159,9 @@
$(document).unbind('mousemove touchmove', localMouseMove);
return $(document).unbind('mouseup touchend', localMouseUp);
};
+ this.elem.change(function() {
+ return self.refresh();
+ });
return this.container.bind('mousedown touchstart', function(event) {
self.onMouseDown.apply(self, arguments);
$(document).bind('mousemove touchmove', localMouseMove);

0 comments on commit 5234688

Please sign in to comment.