// CytoRadio v1.0 // By MacKinley Smith (function($){ var defaults = { widget:{ buttonList:{ buttons:{ css:{ display:'inline-block', height:30, padding:0, 'border-radius':0 }, elements:[] }, borderRadius:5, css:{ width:"100%" } }, inputList:{ css:{ display:'none' }, inputs:{ css:{}, elements:[] } }, labels:["On","Off"], wrapper:{ css:{ } } }, events:{ create:function(cy){}, change:function(cy,event){}, destroy:function(cy){} } }; var methods = { init:function(options,reinit){ if (reinit==null) reinit = false; var namelist = []; return this.each(function(){ var $this = $(this); if ($.inArray($this.attr('name'),namelist)>-1) return; if ($this.data('cytoRadio')!=null) return console.warn("You cannot reinstatiate $.cytoRadio before calling the destroy method.\nProtip: Use the refresh method to reinstantiate in one move."); // Initialize settings var settings = $.extend(true,{},defaults,options); // Generate widget settings.widget.inputList.inputs.elements = $('input[name="'+$this.attr('name')+'"]').addClass('cytoRadio'); // Data settings for individual radio buttons if (!reinit) settings.widget.inputList.inputs.elements.each(function(i){ if ($(this).data('label')!=null) settings.widget.labels[i] = $(this).data('label'); }); settings.widget.wrapper.element = $this.wrap("
").parent().css(settings.widget.wrapper.css); settings.widget.inputList.element = $('
').addClass('cytoRadio-inputList').appendTo(settings.widget.wrapper.element).css(settings.widget.inputList.css); // Move inputs to inputList settings.widget.inputList.inputs.elements.css(settings.widget.inputList.inputs.css).appendTo(settings.widget.inputList.element); settings.widget.buttonList.element = $('
').addClass('cytoRadio-buttonList').css(settings.widget.buttonList.css).appendTo(settings.widget.wrapper.element); settings.widget.inputList.inputs.elements.each(function(i){ if ($(this).data('label')!=null) settings.widget.labels[i] = $(this).data('label'); $(this).attr('data-cytoradio-input',i); var button = $('