Bootstrap Toggle Buttons
github.com
github.com
Just keep polishing them and getting them cross browser. I'll be forking the project and using them.
I was personally impressed that drag actions were supported, because that's a frequently overlooked aspect when people roll their own slider toggles. Without looking at the source, I would guess that implementing mobile touch events would go a long way towards making this library cross-browser.
I was surprised that Bootstrap didn't have these from the get-go, so I'm going to say, again: hell yes. This is practical, useful development that will make a lot of apps better.
Matt Gemmell wrote a good post about toggle switches some time ago: http://mattgemmell.com/2011/11/01/on-off-switches/
The buttons linked follow the example from iOS and avoid the mistakes he talks about.
Hoever, on iOS5, especially when zoomed in - page just scrolls.
On the demo page, when not zoomed in, it hard to tell if it actually slides or not because the button is completely covered by my finger tip.
Regardless, like everyone else suggests.. please don't use these.
The behavior I ended up implementing is... when the box is clicked, it is immediately hidden and replaced with a loading animation while the ajax request is hitting the server saving state. When that finishes, it shows a icon-thumbs-up for a second and then the checkbox again (either checked or unchecked).
I know this isn't your intent, but when the behavior of something like this fails to match my expectations, it is extra irritating, because I feel the author thought having something pretty and iOS-looking was more important than it being usable for me. Either that, or else s/he decided that I'm too stupid to know what I like, and decided to shove an iOS form-control down my throat.
That being said, I must admit that these are visually gorgeous, and their behavior seems pretty excellent at first blush. (But again, I am unsure how I will feel once I start seeing them pop up and inevitably being even slightly misused in the wild. I also haven't tried them on my phone yet.)
https://github.com/component/component https://github.com/component/component/wiki/F.A.Q
Twitter bootstrap isn't modular or supported by a package manager.
The assumption that the "toggle" is 50% of the width is hard coded into the library. I went to change it and, holy cow, the code is a mess.
I got it to work, but had to disable the click-and-slide behavior.
Be warned if you decide to change any of its behavior!
Two things,
#1: If you modify the attribute checked of the input, the state doesn't change.
#2: I don't see a programmatic way of changing the state from your source without re-initializing all the elements?
#2 You're right
That said, if any iOS style switches were done very well, we can explore adding them down the line. I'm not against them 100%, but custom form elements can get tricky. I'm not going to discourage their development—tons of folks have created their own implementation of this. I look forward to them improving over time.
Looking at this again, I'll try to shoot him some feedback so he can improve them and we can get closer to a solution that's fit for the Bootstrap core.
I've forked and pull requested.
The background states were light at the top and darker at the bottom giving a button feel, rather than an inset feel. :)