Switch
Installation
Standalone:
<link rel="stylesheet" href="dist/switch.css" />
<script src="dist/switch.js"></script>npm:
$ npm install weatherstar-switch --save-devUsage
<input type="checkbox" class="checkbox-switch" />standalone version
var el = document.querySelector('.checkbox-switch');
var mySwitch = new Switch(el, options);work with module bundle
require('weatherstar-switch/dist/switch.css');
var Switch = require('weatherstar-switch');
var el = document.querySelector('.checkbox-switch');
var mySwitch = new Switch(el, options);Settings and Defaults
defaults = {
size : 'default'
, checked : undefined
, onText : 'Y'
, offText : 'N'
, onSwitchColor : '#64BD63'
, offSwitchColor : '#fff'
, onJackColor : '#fff'
, offJackColor : '#fff'
, showText : false
, disabled : false
, onInit : function(){}
, beforeChange : function(){}
, onChange : function(){}
, beforeRemove : function(){}
, onRemove : function(){}
, beforeDestroy : function(){}
, onDestroy : function(){}
};size: size of switch element, can bedefault|small|largechecked: state of switch and checbox, ifundefinedthe switch state according to the checkboxonText: text in the jack when switch ONoffText: text in the jack when switch OFFonSwitchColor: color of checked switch elementoffSwitchColor: color of unchecked switch elementonJackColor: color of checked jack elementoffJackColor: color of unchecked jack elementshowText: show or hide text in the jack of switchdisabled: enable or disable click events and changing the state of the switchonInit: called when switch init finishbeforeChange: called before original checkbox'scheckedchangeonChange: called when original checkbox'scheckedchangebeforeRemove: called beforeremove switch element from DOMonRemove: called whenremove switch element from DOMdonebeforeDestroy: called beforeremove all events on switch elementonDestroy: called whenremove all events on switch elementdone
Predefined Classes
switch-danger
switch-primary
switch-black
switch-success
switch-warning
switch-info
switch-transparent
API
.getChecked()
Get switch element checked status.
.on()
Set switch ON.
.off()
Set switch OFF.
.toggle()
Toggle switch.
.disable()
Disable events bind to switch.
.enable()
Enable events bind to switch.
.destroy()
Remove all events bind to switch.
.remove()
Remove switch form DOM and show the checkbox.
License
MIT © zhiyul

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
