3 * https://github.com/ExactTarget/fuelux
5 * Copyright (c) 2012 ExactTarget
6 * Licensed under the MIT license.
9 define(['require','jquery'],function (require) {
11 var $ = require('jquery');
14 // RADIO CONSTRUCTOR AND PROTOTYPE
16 var Radio = function (element, options) {
17 this.$element = $(element);
18 this.options = $.extend({}, $.fn.radio.defaults, options);
21 this.$label = this.$element.parent();
22 this.$icon = this.$label.find('i');
23 this.$radio = this.$label.find('input[type=radio]');
24 this.groupName = this.$radio.attr('name');
27 this.setState(this.$radio);
30 this.$radio.on('change', $.proxy(this.itemchecked, this));
37 setState: function ($radio, resetGroupState) {
38 var checked = $radio.is(':checked');
39 var disabled = $radio.is(':disabled');
42 if (checked === true) {
43 this.$icon.addClass('checked');
45 if (disabled === true) {
46 this.$icon.addClass('disabled');
50 resetGroup: function () {
51 // reset all radio buttons in group
52 $('input[name=' + this.groupName + ']').next().removeClass('checked');
56 this.$radio.attr('disabled', false);
57 this.$icon.removeClass('disabled');
60 disable: function () {
61 this.$radio.attr('disabled', true);
62 this.$icon.addClass('disabled');
65 itemchecked: function (e) {
66 var radio = $(e.target);
74 // RADIO PLUGIN DEFINITION
76 $.fn.radio = function (option, value) {
79 var $set = this.each(function () {
81 var data = $this.data('radio');
82 var options = typeof option === 'object' && option;
84 if (!data) $this.data('radio', (data = new Radio(this, options)));
85 if (typeof option === 'string') methodReturn = data[option](value);
88 return (methodReturn === undefined) ? $set : methodReturn;
91 $.fn.radio.defaults = {};
93 $.fn.radio.Constructor = Radio;
99 $(window).on('load', function () {
100 //$('i.radio').each(function () {
101 $('.radio-custom > input[type=radio]').each(function () {
103 if ($this.data('radio')) return;
104 $this.radio($this.data());