File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 9696 </ div >
9797
9898< script >
99+ let checkBoxes = document . querySelectorAll ( '.inbox input' ) ;
100+ let lastPressed
101+ let toCheck = false ;
102+ checkBoxes . forEach ( checkBox => checkBox . addEventListener ( 'click' , ( e ) => {
103+ if ( e . shiftKey && lastPressed ) {
104+ // console.log([...checkBoxes].indexOf(e.target));
105+ if ( [ ...checkBoxes ] . indexOf ( e . target ) > [ ...checkBoxes ] . indexOf ( lastPressed ) ) {
106+ for ( let i = 0 ; i < checkBoxes . length ; i ++ ) {
107+ if ( ! toCheck ) {
108+ if ( checkBoxes [ i ] === lastPressed ) {
109+ toCheck = true
110+ }
111+ } else {
112+ checkBoxes [ i ] . checked = true ;
113+ if ( checkBoxes [ i ] === e . target ) {
114+ toCheck = false ;
115+ }
116+ }
117+ }
118+ } else {
119+ for ( let i = checkBoxes . length ; i > 0 ; i -- ) {
120+ if ( ! toCheck ) {
121+ if ( checkBoxes [ i ] === lastPressed ) {
122+ toCheck = true
123+ }
124+ } else {
125+ checkBoxes [ i ] . checked = true ;
126+ if ( checkBoxes [ i ] === e . target ) {
127+ toCheck = false ;
128+ }
129+ }
130+ }
131+ }
132+ } else {
133+ lastPressed = e . target ;
134+ }
135+ } ) )
99136</ script >
100137</ body >
101138</ html >
You can’t perform that action at this time.
0 commit comments