File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 104104 </ div >
105105
106106< script >
107+
108+ let clickIndex = null ;
109+ const inputs = document . querySelectorAll ( 'input' ) ;
110+
111+ Array . from ( inputs ) . forEach ( ( input ) => {
112+ input . addEventListener ( 'click' , ( e ) => {
113+ // console.log(e, 'click');
114+ if ( e . target . checked === true ) {
115+ if ( e . shiftKey === true ) {
116+ toggleShiftInputs ( ) ;
117+ } else {
118+ findFocus ( ) ;
119+ }
120+ } else {
121+ clickIndex = null ;
122+ }
123+ } ) ;
124+ } ) ;
125+
126+ function findFocus ( ) {
127+ Array . from ( inputs ) . forEach ( ( input , index , array ) => {
128+ if ( input === document . activeElement ) {
129+ clickIndex = index ;
130+ }
131+ } ) ;
132+ }
133+
134+
135+ function toggleShiftInputs ( ) {
136+ let alpha = clickIndex ;
137+ findFocus ( ) ;
138+ let omega = clickIndex ;
139+
140+ if ( alpha !== null && omega !== null ) {
141+ if ( alpha > omega ) { //5, 1
142+ //step through descending
143+ Array . from ( inputs ) . forEach ( ( input , index ) => {
144+ if ( index <= alpha && index >= omega ) {
145+ input . checked = true ;
146+ }
147+ } ) ;
148+ } else {
149+ // step through ascending
150+ Array . from ( inputs ) . forEach ( ( input , index ) => {
151+ if ( index >= alpha && index <= omega ) {
152+ input . checked = true ;
153+ }
154+ } ) ;
155+ }
156+ }
157+ }
158+
107159</ script >
108160</ body >
109161</ html >
You can’t perform that action at this time.
0 commit comments