|
| 1 | +## rcSwitcher Jquery Plugin |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +>rcSwitcher plugin *'Radio Checbox Switcher'* let you transform your input checkboxs and radios into a nice switch buttons with a nice interfaces. |
| 7 | + |
| 8 | + |
| 9 | +### Requirements |
| 10 | +>browser supports css3 transition and transform, latest versions of *__modern browsers support css3 transform and transitions__* |
| 11 | +
|
| 12 | +>built with jquery 2.3.1 |
| 13 | +>>*__requires jquery >= 1.7.0__* |
| 14 | +
|
| 15 | + |
| 16 | +### License |
| 17 | + |
| 18 | +>This Plugin is distributed under [GNU GPL V3 License](http://choosealicense.com/licenses/gpl-3.0/) |
| 19 | +
|
| 20 | + |
| 21 | +### Copyright |
| 22 | +>@author Ahmed Saad <a7mad.sa3d.2014@gmail.com> |
| 23 | +
|
| 24 | +### Version |
| 25 | +> 2.1.0 |
| 26 | +
|
| 27 | + |
| 28 | +---- |
| 29 | + |
| 30 | +### Features: |
| 31 | + |
| 32 | + |
| 33 | +1. no need for extra or specific html |
| 34 | +2. _`smooth`_ as uses css3 transform and transition properties with full vendor prefixs |
| 35 | +3. support checkbox of type array _ex: `<input name="delete_users[]">`_ |
| 36 | +4. multiple themes |
| 37 | +5. you can manipulate switch style as: |
| 38 | + * control switch width and height. |
| 39 | + * control switch blob offset. |
| 40 | + * control switch on off direction. |
| 41 | + * control switch on state text and off state text. |
| 42 | + * ability to automatic fit font size. |
| 43 | + * ability to automatic stick switch to its parent side. |
| 44 | + * show switch corresponding input for functionality testing. |
| 45 | + * fire custom events on turnon, turnoff and change. so you can perform your tasks depends on switch status. |
| 46 | + * >on firing events an information plain object is passed to event handler function as the second argument. it contains jquery objects of each switch piece and also input jquery object |
| 47 | + |
| 48 | + |
| 49 | +--- |
| 50 | +### Usage: |
| 51 | + |
| 52 | +This example explains: |
| 53 | + * Basic usage |
| 54 | + * Available options with its defaults |
| 55 | + * Using Custom Event |
| 56 | + |
| 57 | +```javascript |
| 58 | + |
| 59 | +// convert all checkboxs to switchs |
| 60 | +$('input[type=checkbox]').rcSwitcher(); |
| 61 | + |
| 62 | + |
| 63 | +// Options |
| 64 | +$('input[type=checkbox]').rcSwitcher({ |
| 65 | + // Default value // info |
| 66 | + |
| 67 | + theme: 'flat', // light select theme between 'flat, light, dark, modern' |
| 68 | + width: 80, // 56 in 'px' |
| 69 | + height: 26, // 22 |
| 70 | + blobOffset: 0, // 2 |
| 71 | + reverse: true, // false reverse on off order |
| 72 | + onText: 'YES', // 'ON' text displayed on ON state |
| 73 | + offText: 'NO', // 'OFF' text displayed on OFF state |
| 74 | + inputs: true, // false show corresponding inputs |
| 75 | + autoFontSize: true, // false auto fit text size with respect to switch height |
| 76 | + autoStick: true // false auto stick switch to its parent side |
| 77 | +}); |
| 78 | + |
| 79 | + |
| 80 | +// assign event handler |
| 81 | +$(':radio').rcSwitcher().on({ |
| 82 | + |
| 83 | + 'turnon.rcSwitcher': function( e, dataObj ){ |
| 84 | + |
| 85 | + // to do on turning on a switch |
| 86 | + |
| 87 | + // dataObj.$input current input jq object |
| 88 | + // dataObj.$switcher current switch jq object |
| 89 | + // dataObj.components.$toggler swich toggler jq object |
| 90 | + // dataObj.components.$on switch on jq object |
| 91 | + // dataObj.components.$off switch off jq object |
| 92 | + // dataObj.components.$blob switch blob jq object |
| 93 | + |
| 94 | + }, |
| 95 | + |
| 96 | + 'turnoff.rcSwitcher': function( e, dataObj ){ |
| 97 | + |
| 98 | + // to do on turning off a switch |
| 99 | + }, |
| 100 | + |
| 101 | + 'change.rcSwitcher': function( e, dataObj, changeType ){ |
| 102 | + |
| 103 | + // to do on turning on or off a switch |
| 104 | + // changeType is 'turnon' || 'turnoff' |
| 105 | + } |
| 106 | + |
| 107 | +}); |
| 108 | + |
| 109 | +``` |
| 110 | + |
| 111 | +__Options that could be set inside html input as attributes__ |
| 112 | + |
| 113 | +>_`rcswitcher-ontext=""`_ |
| 114 | +>_`rcswitcher-offtext=""`_ |
| 115 | +>>those attributes are equivalent to onText, offText options |
| 116 | +>>__*but they have more priority and if set they will override options values*__ |
| 117 | +
|
| 118 | +```html |
| 119 | +<!-- Set OnText and offText inside input element itself --> |
| 120 | +<input type="checkbox" name="" value="" rcswitcher-ontext="YES" rcswitcher-offtext="NO" /> |
| 121 | + |
| 122 | +``` |
0 commit comments