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 // CHECKBOX CONSTRUCTOR AND PROTOTYPE
16 var Checkbox = function (element, options) {
18 this.$element = $(element);
19 this.options = $.extend({}, $.fn.checkbox.defaults, options);
22 this.$label = this.$element.parent();
23 this.$icon = this.$label.find('i');
24 this.$chk = this.$label.find('input[type=checkbox]');
27 this.setState(this.$chk);
30 this.$chk.on('change', $.proxy(this.itemchecked, this));
33 Checkbox.prototype = {
35 constructor: Checkbox,
37 setState: function ($chk) {
38 var checked = $chk.is(':checked');
39 var disabled = $chk.is(':disabled');
42 this.$icon.removeClass('checked').removeClass('disabled');
44 // set state of checkbox
45 if (checked === true) {
46 this.$icon.addClass('checked');
48 if (disabled === true) {
49 this.$icon.addClass('disabled');
54 this.$chk.attr('disabled', false);
55 this.$icon.removeClass('disabled');
58 disable: function () {
59 this.$chk.attr('disabled', true);
60 this.$icon.addClass('disabled');
67 itemchecked: function (e) {
68 var chk = $(e.target);
74 // CHECKBOX PLUGIN DEFINITION
76 $.fn.checkbox = function (option, value) {
79 var $set = this.each(function () {
81 var data = $this.data('checkbox');
82 var options = typeof option === 'object' && option;
84 if (!data) $this.data('checkbox', (data = new Checkbox(this, options)));
85 if (typeof option === 'string') methodReturn = data[option](value);
88 return (methodReturn === undefined) ? $set : methodReturn;
91 $.fn.checkbox.defaults = {};
93 $.fn.checkbox.Constructor = Checkbox;
99 $(window).on('load', function () {
100 //$('i.checkbox').each(function () {
101 $('.checkbox-custom > input[type=checkbox]').each(function () {
103 if ($this.data('checkbox')) return;
104 $this.checkbox($this.data());