1212 </ style >
1313
1414
15-
16-
17- <!-- //////////////////////////////////////////////// -->
18- <!-- REQUIRED ELEMENTS -->
19-
20- < script src ="https://code.jquery.com/jquery-3.3.1.min.js " type ="text/javascript "> </ script >
21- < script src ="lc_switch.js " type ="text/javascript "> </ script >
22- < link rel ="stylesheet " href ="lc_switch.css ">
23-
24- <!-- //////////////////////////////////////////////// -->
25-
26-
27-
2815 < style >
2916 # second_div {
3017 width : 90% ;
31- max-width : 600 px ;
18+ max-width : 700 px ;
3219 min-width : 340px ;
3320 margin : 50px auto 0 ;
3421 background : # f3f3f3 ;
4229 }
4330 # third_div {
4431 width : 90% ;
45- max-width : 600 px ;
32+ max-width : 700 px ;
4633 min-width : 340px ;
47- margin : 30px auto 0 ;
34+ margin : 30px auto;
4835 }
4936 # third_div small {
5037 float : right;
51- color : # aaa ;
52- cursor : pointer;
5338 padding-top : 5px ;
5439 }
40+ small {
41+ color : # 929292 ;
42+ cursor : pointer;
43+ font-size : 90% ;
44+ }
5545 # third_div ul {
56- padding-left : 12 px ;
46+ padding : 15 px 0 ;
5747 max-height : 200px ;
5848 overflow : auto;
5949 }
6252 font-size : 14px ;
6353 line-height : normal;
6454 margin : 7px 0 ;
55+ padding : 6px 2px ;
56+ margin : 0 ;
57+ transition : all .2s ease;
6558 }
59+ # third_div li : hover {
60+ background-color : # f3f3f3 ;
61+ }
6662 # third_div li em {
6763 display : inline-block;
68- width : 130 px ;
64+ width : 200 px ;
6965 color : # 555 ;
7066 font-style : normal;
7167 }
8076 < img id ="logo " src =" data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAlCAMAAAD7q3BLAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRFS1NFfsJCx8jKNDQ0SyWmjgAAAAR0Uk5T////AEAqqfQAAACySURBVHja7JTLFsQgCEOD/P8/jw9EgjiLWU88XQi3sSoUSgJaQwrRRNqQ4EWgbQEVcfKTuQgwEGxQGZANXnlnUCzAS0Hf+WXTB3lA1vDAPBxHEMWbWnM+bnFXse1g2ZnOBjshlhuPbPVZIIzRk7+JGYnAr4R8J/RPXGcaxXd77i71JxHi7+pVY0KMEVTudKXji69aj5WVidUvSgwRiH1bEMi9n4jc+26zCdT/ICdi9CPAAHRlCGHRLtsqAAAAAElFTkSuQmCC " />
8177 LC Switch
8278 </ h2 >
83- < h4 > Superlight jQuery plugin improving forms look and functionality, by < a href ="https://lcweb.it " target ="_blank "> LCweb</ a > </ h4 >
79+ < h4 > Superlight javascript plugin improving forms look and functionality, by < a href ="https://lcweb.it " target ="_blank "> LCweb</ a > </ h4 >
8480
8581 < svg width ="100% " height ="100% ">
8682 < pattern id ="pattern-cubes " x ="0 " patternUnits ="userSpaceOnUse " viewBox ="0 0 10 16 " height ="100 " width ="116 " y ="68 ">
@@ -112,16 +108,20 @@ <h4>Superlight jQuery plugin improving forms look and functionality, by <a href=
112108 < p > < input type ="checkbox " name ="check-2 " value ="2 " class ="lcs_check " disabled ="disabled " autocomplete ="off " /> </ p >
113109
114110 < p > < input type ="checkbox " name ="check-3 " value ="3 " class ="lcs_check lcs_tt1 " checked ="checked " autocomplete ="off " /> </ p >
111+
112+ < p > < br /> < small id ="enable_ckb "> (enable all)</ small > < small id ="disable_ckb "> (disable all)</ small > </ p >
115113 </ div >
116114
117115 < div style ="float: right; width: 50%; ">
118- < p style ="padding-bottom: 13px; "> < em > Radio</ em > </ p >
116+ < p style ="padding-bottom: 13px; "> < em > Radio< br /> (compact mode + custom color) < /em > </ p >
119117
120118 < p > < input type ="radio " name ="radio-1 " value ="1 " class ="lcs_check lcs_tt2 " autocomplete ="off " /> </ p >
121119
122120 < p > < input type ="radio " name ="radio-1 " value ="2 " class ="lcs_check lcs_tt2 " disabled ="disabled " autocomplete ="off " /> </ p >
123121
124122 < p > < input type ="radio " name ="radio-1 " value ="3 " class ="lcs_check lcs_tt2 " checked ="checked " autocomplete ="off " /> </ p >
123+
124+ < p > < br /> < small id ="enable_radio "> (enable all)</ small > < small id ="disable_radio "> (disable all)</ small > </ p >
125125 </ div >
126126 </ form >
127127 < div style =" clear: both; "> </ div >
@@ -147,8 +147,85 @@ <h3>
147147
148148 <!-- //////////////////////////////////////////////// -->
149149 <!-- REQUIRED JAVASCRIPT -->
150+
151+
152+ < script src ="lc_switch.min.js " type ="text/javascript "> </ script >
153+
150154 < script type ="text/javascript ">
151- $ ( document ) . ready ( function ( e ) {
155+ const checkboxes = document . querySelectorAll ( 'input[type=checkbox]' ) ,
156+ radios = document . querySelectorAll ( 'input[type=radio]' ) ;
157+
158+ // initialization
159+ checkboxes . lc_switch ( ) ;
160+ radios . lc_switch ( {
161+ compact_mode : true ,
162+ on_color : 'teal' ,
163+ } ) ;
164+
165+
166+
167+ // enable/disable
168+ document . getElementById ( 'enable_ckb' ) . addEventListener ( 'click' , ( ) => { checkboxes . lcs_enable ( ) ; } ) ;
169+ document . getElementById ( 'disable_ckb' ) . addEventListener ( 'click' , ( ) => { checkboxes . lcs_disable ( ) ; } ) ;
170+
171+ document . getElementById ( 'enable_radio' ) . addEventListener ( 'click' , ( ) => { radios . lcs_enable ( ) ; } ) ;
172+ document . getElementById ( 'disable_radio' ) . addEventListener ( 'click' , ( ) => { radios . lcs_disable ( ) ; } ) ;
173+
174+
175+
176+ // events log
177+ const log_wrap = document . querySelector ( '#third_div ul' ) ;
178+
179+ const toLeadingZero = ( val ) => {
180+ return ( val . toString ( ) . length < 2 ) ? '0' + val : val ;
181+ } ;
182+
183+ const getTime = ( ) => {
184+ const d = new Date ;
185+ return '(' + toLeadingZero ( d . getHours ( ) ) + ':' + toLeadingZero ( d . getMinutes ( ) ) + ':' + toLeadingZero ( d . getSeconds ( ) ) + ')' ;
186+ } ;
187+
188+ document . querySelectorAll ( 'input' ) . forEach ( function ( el ) {
189+ const subj = el . getAttribute ( 'type' ) + ' #' + el . value ;
190+
191+ el . addEventListener ( 'lcs-statuschange' , ( e ) => {
192+ let status = ( el . checked ) ? 'checked' : 'unchecked' ;
193+ status += ( el . disabled ) ? ' disabled' : ' enabled' ;
194+
195+ log_wrap . innerHTML = '<li><em>' + getTime ( ) + ' [lcs-statuschange]</em>' + subj + ' changed status: ' + status + '</li>' + log_wrap . innerHTML ;
196+ } ) ;
197+
198+ el . addEventListener ( 'lcs-on' , ( e ) => {
199+ const status = ( el . checked ) ? 'checked' : 'unchecked' ;
200+ log_wrap . innerHTML = '<li><em>' + getTime ( ) + ' [lcs-on]</em>' + subj + ' changed status: ' + status + '</li>' + log_wrap . innerHTML ;
201+ } ) ;
202+
203+ el . addEventListener ( 'lcs-off' , ( e ) => {
204+ const status = ( el . checked ) ? 'checked' : 'unchecked' ;
205+ log_wrap . innerHTML = '<li><em>' + getTime ( ) + ' [lcs-off]</em>' + subj + ' changed status: ' + status + '</li>' + log_wrap . innerHTML ;
206+ } ) ;
207+
208+ el . addEventListener ( 'lcs-enabled' , ( e ) => {
209+ const status = ( el . disabled ) ? 'disabled' : 'enabled' ;
210+ log_wrap . innerHTML = '<li><em>' + getTime ( ) + ' [lcs-enabled]</em>' + subj + ' changed status: ' + status + '</li>' + log_wrap . innerHTML ;
211+ } ) ;
212+
213+ el . addEventListener ( 'lcs-disabled' , ( e ) => {
214+ const status = ( el . disabled ) ? 'disabled' : 'enabled' ;
215+ log_wrap . innerHTML = '<li><em>' + getTime ( ) + ' [lcs-disabled]</em>' + subj + ' changed status: ' + status + '</li>' + log_wrap . innerHTML ;
216+ } ) ;
217+ } ) ;
218+
219+
220+ // clear events log
221+ document . querySelector ( '#third_div small' ) . addEventListener ( 'click' , ( ) => {
222+ log_wrap . innerHTML = '' ;
223+ } ) ;
224+
225+
226+ //$('input')[0].lc_switch();
227+
228+ /*$(document).ready(function(e) {
152229 $('input').lc_switch();
153230
154231 // triggered each time a field changes status
184261 // clean events log
185262 $('#third_div small').click(function() {
186263 $('#third_div ul').empty();
187- } ) ;
264+ });*/
188265 </ script >
189266 <!-- //////////////////////////////////////////////// -->
190267
0 commit comments