/** * Native Checkbox/Radio Replacement for iCheck * Provides similar API to iCheck for easier migration */ (function($) { 'use strict'; // Plugin definition $.fn.scCheck = function(options, param) { // Handle method calls if (typeof options === 'string') { return this.each(function() { handleMethod($(this), options, param); }); } // Default options var settings = $.extend({ checkboxClass: 'sc-checkbox', radioClass: 'sc-radio', checkedClass: 'checked', disabledClass: 'disabled', color: 'blue', style: 'normal' // or 'flat' }, options); return this.each(function() { var $input = $(this); // Skip if already initialized if ($input.parent().hasClass('sc-checkbox') || $input.parent().hasClass('sc-radio')) { return; } initializeInput($input, settings); }); }; // Initialize input function initializeInput($input, settings) { var isCheckbox = $input.attr('type') === 'checkbox'; var baseClass = isCheckbox ? settings.checkboxClass : settings.radioClass; var markClass = isCheckbox ? 'checkmark' : 'radiomark'; // CRITICAL: Check if this exact input element is already initialized // Check both for data attributes AND parent wrapper if ($input.data('scCheck') || $input.data('iCheck') || $input.parent().hasClass('sc-checkbox') || $input.parent().hasClass('sc-radio') || ($input.parent().attr('class') && $input.parent().attr('class').indexOf('icheckbox') > -1)) { // Already initialized, skip return; } // Extract color and style from iCheck class format var color = settings.color; var style = settings.style; // Handle iCheck class format like 'icheckbox_flat-red' if (settings.checkboxClass && settings.checkboxClass.includes('_')) { // For 'icheckbox_flat-red', we want to extract 'flat' and 'red' var match = settings.checkboxClass.match(/icheckbox_([^-]+)(?:-(.+))?/); if (match) { style = match[1]; // 'flat' if (match[2]) { color = match[2]; // 'red' } } } // For iCheck compatibility, use the full class name as provided // Don't build redundant classes var wrapperClasses = [baseClass]; // Get label text from span.form-check-label if it exists var labelText = ''; var $labelSpan = $input.siblings('span.form-check-label'); if ($labelSpan.length) { labelText = $labelSpan.html(); // Don't remove the span, we'll move it after creating the wrapper } // Create wrapper var $wrapper = $('