UNPKG

equation-admin-template

Version:

Booststrap 4 admin template made by equation

97 lines (86 loc) 3.32 kB
/*A jQuery plugin which add loading indicators into buttons * By Minoli Perera * MIT Licensed. */ (function ($) { $('.has-spinner').attr("disabled", false); $.fn.buttonLoader = function (action) { var self = $(this); if (action == 'start') { if ($(self).attr("disabled") == "disabled") { return false; } $('.has-spinner').attr("disabled", true); $(self).attr('data-btn-text', $(self).text()); var text = 'Loading'; console.log($(self).attr('data-load-text')); if($(self).attr('data-load-text') != undefined && $(self).attr('data-load-text') != ""){ var text = $(self).attr('data-load-text'); } $(self).html('<span class="spinner"><i class="fa fa-spinner fa-spin" title="button-loader"></i></span> '+text); $(self).addClass('active'); } if (action == 'stop') { $(self).html($(self).attr('data-btn-text')); $(self).removeClass('active'); $('.has-spinner').attr("disabled", false); } } })(jQuery); /*Check box js*/ $(function () { $('.button-checkbox').each(function () { // Settings var $widget = $(this), $button = $widget.find('button'), $checkbox = $widget.find('input:checkbox'), color = $button.data('color'), settings = { on: { icon: 'glyphicon glyphicon-check' }, off: { icon: 'glyphicon glyphicon-unchecked' } }; // Event Handlers $button.on('click', function () { $checkbox.prop('checked', !$checkbox.is(':checked')); $checkbox.triggerHandler('change'); updateDisplay(); }); $checkbox.on('change', function () { updateDisplay(); }); // Actions function updateDisplay() { var isChecked = $checkbox.is(':checked'); // Set the button's state $button.data('state', (isChecked) ? "on" : "off"); // Set the button's icon $button.find('.state-icon') .removeClass() .addClass('state-icon ' + settings[$button.data('state')].icon); // Update the button's color if (isChecked) { $button .removeClass('btn-default') .addClass('btn-' + color + ' active'); } else { $button .removeClass('btn-' + color + ' active') .addClass('btn-default'); } } // Initialization function init() { updateDisplay(); // Inject the icon if applicable if ($button.find('.state-icon').length == 0) { $button.prepend('<i class="state-icon ' + settings[$button.data('state')].icon + '"></i>'); } } init(); }); });