File tree Expand file tree Collapse file tree
10 - Hold Shift and Check Checkboxes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 104104 </ div >
105105
106106< script >
107+ var Api = ( function ( ) {
108+ var $ = ( sel ) => Array . from ( document . querySelectorAll ( sel ) ) ;
109+ var boxlist = $ ( '.item input' ) ;
110+ var indexes = { } ;
111+ var self ;
112+
113+ function reverser ( bool ) {
114+ var [ start , end ] = [ indexes . last , indexes . this ] . sort ( ) ;
115+ var arr = boxlist . slice ( start , end + 1 ) ;
116+ arr . forEach ( el => el . checked = bool ) ;
117+ }
118+
119+ function updateLast ( evt , num ) {
120+ indexes . last = evt . shiftKey ? indexes . this : num ;
121+ indexes . this = num ;
122+ reverser ( evt . target . checked ) ;
123+ }
124+
125+ function doBinding ( arr ) {
126+ arr . forEach ( ( ele , idx ) => {
127+ ele . addEventListener ( 'click' , ( evt ) => updateLast ( evt , idx ) ) ;
128+ } ) ;
129+ return self ;
130+ }
131+
132+ self = {
133+ init : doBinding ,
134+ boxlist, indexes,
135+ } ;
136+
137+ return self . init ( boxlist ) ;
138+ } ( ) ) ;
139+
107140</ script >
108141</ body >
109142</ html >
You can’t perform that action at this time.
0 commit comments