File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 104104 </ div >
105105
106106< script >
107+ const checkboxes = Array . from ( document . querySelectorAll ( '.inbox [type="checkbox"]' ) ) ;
108+
109+ let previousChecked ;
110+
111+ function handleCheck ( e ) {
112+
113+ if ( e . shiftKey && this . checked && previousChecked ) {
114+ let lower = Number ( previousChecked . dataset . index ) ;
115+ let upper = Number ( this . dataset . index ) ;
116+
117+ if ( previousChecked . dataset . index > this . dataset . index ) {
118+
119+ const temp = lower ;
120+ lower = upper ;
121+ upper = temp ;
122+ }
123+
124+ const toUnCheck = [ ...checkboxes . slice ( 0 , lower ) , ...checkboxes . slice ( upper + 1 ) ] ;
125+ checkboxes . forEach ( x => x . checked = toUnCheck . indexOf ( x ) === - 1 ) ;
126+ } ;
127+
128+ previousChecked = this ;
129+ }
130+
131+ checkboxes . forEach ( ( checkbox , index ) => {
132+ checkbox . dataset . index = index ;
133+ checkbox . addEventListener ( 'click' , handleCheck ) ;
134+ } ) ;
135+
107136</ script >
108137</ body >
109138</ html >
You can’t perform that action at this time.
0 commit comments