News for hackers. Stuff that matters.
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by alexyoung on Monday August 20, 2012 @03:27PM (#4409336)
When handling options, I quite like this pattern:

    var settings = $.extend({
      dragable: true,
      clickable: true,
      ontext: 'ON',
      offtext: 'OFF',
      on: true,
      animtime: 300
    }, opts);
The $.extend method still returns a suitable object even if `opts` is undefined.

You also might want to `return this.each` so calls can be chained.

All of this is covered here: http://docs.jquery.com/Plugins/Authoring

Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by simontabor on Monday August 20, 2012 @06:11PM (#4410050)
Thank you Alex, I'll change it tomorrow!
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by taitems on Monday August 20, 2012 @09:58PM (#4410779)
Hey guys, I did something similar but based off the styles of the jQuery UI slider plugin. I found while these types of standalone plugins looked okay, they were frustrating to customise or even to make them look PERFECT.

Check it out here: http://taitems.github.com/UX-Lab/ToggleSwitch/index.html

I also investigated achieving something similar using only CSS base on a :checkbox, but the browser support, even in "modern" browsers was poor: http://taitems.github.com/UX-Lab/CSSInputs/index.html

Thoughts and hacks on the above, here: http://taitems.tumblr.com/post/23099016111/css3-input-stylin...

Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by axiak on Monday August 20, 2012 @04:57PM (#4409759)
This looks great! One minor suggestion: make the toggle button non selectable for dragging. http://jsfiddle.net/SWqw3/ show's a basic way of doing this.
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by simontabor on Monday August 20, 2012 @06:14PM (#4410060)
Done!
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by creativename on Monday August 20, 2012 @04:02PM (#4409511)
These look great! Thanks for sharing.

One thing - I know the intent is that they can be easily customized, but it might be nice to have smaller options out of the box. I think I've been spoiled by Twitter Bootstrap, though, where they have a few preset sizes. My first thought was that they looked a little large.

Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by simontabor on Monday August 20, 2012 @06:00PM (#4410003)
The default is actually 50x20px which is pretty small, I could possibly add it so you can specify a size for the toggle in the options.
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by tehwebguy on Monday August 20, 2012 @02:37PM (#4409085)
It's nice to see something like this as a jQuery plugin. It would be amazing if they could be adjusted by swiping on mobile!
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by rane on Monday August 20, 2012 @02:45PM (#4409123)
I don't know about Android but you don't swipe toggle buttons on iOS.
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by garand on Monday August 20, 2012 @03:05PM (#4409227)
Most users don't, but they have the ability to be swiped, and I've seen some iOS users swiping them around.
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by S_A_P on Monday August 20, 2012 @05:43PM (#4409942)
I like these, but how do you get the "value"? Im not a javascript guru, but is there an attribute or value I need to check?
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by wbobeirne on Monday August 20, 2012 @05:48PM (#4409963)
It looks like the primary function of the button is to alter something on the page via the toggles function, but I guess you could check if it had the active class or not.
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by simontabor on Monday August 20, 2012 @06:14PM (#4410059)
You can either check the class of the .slide div or have it linked to a checkbox which will be checked or unchecked.
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by S_A_P on Tuesday August 21, 2012 @12:16PM (#4413355)
Ahh, that did it. I ended up checking for $('.slide').hasClass('active');

Thanks for this simon!

Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by antihero on Monday August 20, 2012 @06:28PM (#4410117)
Suggestion - theme for Jelly Bean, then have option to automatically select theme for detected device (Android/iPhone)
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by munkydung on Monday August 20, 2012 @06:04PM (#4410020)
nice work! what license is this released under?
Re:Show HN: Easily Customizable Toggle Buttons - jQuery Plugin by simontabor on Monday August 20, 2012 @06:26PM (#4410108)
I'm feeling nice so MIT - will update the README tomorrow