Skip to content

Instantly share code, notes, and snippets.

@codeboxr
Created June 30, 2013 11:40
Show Gist options
  • Save codeboxr/5894857 to your computer and use it in GitHub Desktop.
Save codeboxr/5894857 to your computer and use it in GitHub Desktop.
Make Radio Switch button in joomla frontend
/**
* @package Joomla.Administrator
* @subpackage Templates.isis
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @since 3.0
*/
(function($)
{
$(document).ready(function()
{
//$('*[rel=tooltip]').tooltip()
// Turn radios into btn-group
$('.radio.btn-group label').addClass('btn');
$(".btn-group label:not(.active)").click(function()
{
var label = $(this);
var input = $('#' + label.attr('for'));
if (!input.prop('checked')) {
label.closest('.btn-group').find("label").removeClass('active btn-success btn-danger btn-primary');
if (input.val() == '') {
label.addClass('active btn-primary');
} else if (input.val() == 0) {
label.addClass('active btn-danger');
} else {
label.addClass('active btn-success');
}
input.prop('checked', true);
}
});
$(".btn-group input[checked=checked]").each(function()
{
if ($(this).val() == '') {
$("label[for=" + $(this).attr('id') + "]").addClass('active btn-primary');
} else if ($(this).val() == 0) {
$("label[for=" + $(this).attr('id') + "]").addClass('active btn-danger');
} else {
$("label[for=" + $(this).attr('id') + "]").addClass('active btn-success');
}
});
})
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment