﻿/*!
* jQuery Form Controls v1.0.1
* By Anders Pettersson
* 
* Version history:
* ----------------
* 1.0.1 - Changed functionality to allow for more generic classes
*/
(function ($) { $.fn.dropdown = function (b) { var c = $(this); var d = { items: [], controlName: c.attr('id'), initialValue: 'DropDown' }; return this.each(function () { if (b) { $.extend(d, b) } html = '<div class="jfc_container">'; html += '<input type="hidden" id="' + d.controlName + '_value" name="' + d.controlName + '_value" value="' + d.initialValue + '" />'; html += '\t<div id="' + d.controlName + '_visible_value" class="jfc_value">' + d.initialValue + '</div><span id="' + d.controlName + '_btn" class="jfc_btn" />\n'; html += '</div>'; html += '\t<div id="' + d.controlName + '_drop" class="jfc_drop">\n'; html += '\t\t<ul>\n'; c.data('value', d.initialValue); jQuery.each(d.items, function (i, a) { if (a.value == d.initialValue) html += '\t\t\t<li class="item selected">' + a.value + '</li>\n'; else html += '\t\t\t<li class="item">' + a.value + '</li>\n' }); html += '\t\t</ul>\n'; html += '\t</div>\n'; html += '</div>'; $('#' + c.attr('id')).html(html); $('#' + d.controlName + ' .item').click(function () { $('#' + d.controlName + '_visible_value').html($(this).html()); $('#' + d.controlName + '_drop').css('display', 'none'); c.data('value', $(this).html()); $('#' + d.controlName + '_value').val(c.data('value')) }); $('#' + d.controlName + '_btn').click(function () { if ($('#' + d.controlName + '_drop').css('display') == 'none') { $('#' + d.controlName + '_drop').css('display', 'block'); $('li').each(function (i, a) { if ($(this).text() == c.data('value')) $(this).addClass('selected'); else $(this).removeClass('selected') }) } else $('#' + d.controlName + '_drop').css('display', 'none') }) }) }; $.fn.radiobutton = function (c) { var d = $(this); var e = { radiobuttons: [], controlName: d.attr('id'), initialValue: 'RadioButton', checkedClass: 'radio_label_checked', uncheckedClass: 'radio_label_unchecked' }; return this.each(function () { if (c) { $.extend(e, c) } html = '<div class="radio_wrap">'; jQuery.each(e.items, function (i, a) { if (a.value == e.initialValue) html += '\t<label id="' + e.controlName + '_label' + i + '" class="' + e.uncheckedClass + ' ' + e.checkedClass + '"><input id="' + e.controlName + '_rb_' + i + '" class="' + e.controlName + '_rb" value="' + a.value + '" type="radio" name="' + e.controlName + '" checked="true" /></label><p class="' + e.controlName + '_label_class">' + a.label + '</p>\n'; else html += '\t<label id="' + e.controlName + '_label' + i + '" class="' + e.uncheckedClass + '"><input id="' + e.controlName + '_rb_' + i + '" class="' + e.controlName + '_rb" value="' + a.value + '" type="radio" name="' + e.controlName + '" /></label><p class="' + e.controlName + '_label_class">' + a.label + '</p>\n' }); html += '</div>'; $('#' + d.attr('id')).html(html); $('input[name*="' + e.controlName + '"]').parent().click(function (i, b) { $('input[name*="' + e.controlName + '"]').parent().each(function (i, a) { $("#" + $(this).attr('id')).removeClass(e.checkedClass); $("#" + $(this).attr('id')).addClass(e.uncheckedClass); $("#" + $(this).attr('id')).children(0).removeAttr('checked') }); $("#" + $(this).attr('id')).addClass(e.checkedClass); $("#" + $(this).attr('id')).removeClass(e.uncheckedClass); $("#" + $(this).attr('id')).children(0).attr('checked', 'true') }); $('input[name*="' + e.controlName + '"]').parent().next().click(function (i, b) { $('input[name*="' + e.controlName + '"]').parent().each(function (i, a) { $("#" + $(this).attr('id')).removeClass(e.checkedClass); $("#" + $(this).attr('id')).addClass(e.uncheckedClass); $("#" + $(this).attr('id')).children(0).removeAttr('checked') }); $(this).prev().addClass(e.checkedClass); $(this).prev().removeClass(e.uncheckedClass); $(this).prev().children(0).attr('checked', 'true') }) }) } })(jQuery);
