Live data from Hacker News

Show HN: Easily Customizable Toggle Buttons - jQuery Plugin

simontabor.com

11–18 of 18 posts

Re: Show HN: Easily Customizable Toggle Buttons - jQuery Plugin

#12

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

Thank you Alex, I'll change it tomorrow!

Re: Show HN: Easily Customizable Toggle Buttons - jQuery Plugin

#13
post #8

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?

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.

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

#17
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

#18

Earlier quoted context omitted.

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.

You can either check the class of the .slide div or have it linked to a checkbox which will be checked or unchecked.

Ahh, that did it. I ended up checking for $('.slide').hasClass('active');

Thanks for this simon!

Post reply on HN