Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1030223 // hCheckBoxMultiSelect_v2 - works with all checkboxes that have a class

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3080L/20K).

1  
sS hCheckBoxMultiSelect_v2(O... _) {
2  
  optPar bool verbose;
3  
  
4  
  ret hscript(replaceDollarVars([[
5  
    var lastChecked;
6  
7  
    $(document).ready(function() {
8  
      console.log("document ready");
9  
      $("input[type=checkbox]").click(function(e) {
10  
        var verbose = $verbose;
11  
        var cls = this.className;
12  
        if (verbose) console.log("cls=" + cls);
13  
        if (!cls) return;
14  
        
15  
        if (!lastChecked || lastChecked.className != cls) {
16  
          lastChecked = this;
17  
          return;
18  
        }
19  
        
20  
        var $chkboxes = $('input[type=checkbox].' + cls);
21  
  
22  
        if (e.shiftKey) {
23  
          var start = $chkboxes.index(this);
24  
          var end = $chkboxes.index(lastChecked);
25  
26  
          // change checkboxes, trigger their change event in case there are handlers installed
27  
          $chkboxes.slice(Math.min(start, end), Math.max(start,end)+1).prop('checked', lastChecked.checked)
28  
            .each(function(idx, chkbox) {
29  
              chkbox.dispatchEvent(new Event('change'));
30  
            });
31  
        }
32  
  
33  
        lastChecked = this;
34  
      });
35  
    });
36  
  ]], +verbose));
37  
}

Author comment

Began life as a copy of #1008423

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030223
Snippet name: hCheckBoxMultiSelect_v2 - works with all checkboxes that have a class
Eternal ID of this version: #1030223/8
Text MD5: 7dacb06b02a20121d307e09c6e3d985c
Transpilation MD5: 9bbc0860f8fae9a3a22921f9384032b6
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-17 14:29:40
Source code size: 1136 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 159 / 230
Version history: 7 change(s)
Referenced in: [show references]