Blame view

frontend/web/count_form/js/input-style.js 2.73 KB
559be889   Alexander Karnovsky   Init test-9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  jQuery(document).ready( function(){

      var d = document;

      var safari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1) ? true : false;

      var gebtn = function(parEl,child) { return parEl.getElementsByTagName(child); };

  

      onload = function() {

  

          var body = gebtn(d,'body')[0];

          body.className = body.className && body.className != '' ? body.className + ' has-js' : 'has-js';

  

          if (!d.getElementById || !d.createTextNode) return;

          var ls = gebtn(d,'label');

          for (var i = 0; i < ls.length; i++) {

  

              var l = ls[i];

  

              if (l.className.indexOf('label_') == -1) continue;

              var inp = gebtn(l,'input')[0];

              if (l.className == 'label_checkbox') {

                  l.className = (safari && inp.checked == true || inp.checked) ? 'label_checkbox c_on' : 'label_checkbox c_off';

  

              };

              if (l.className == 'label_radio') {

                  l.className = (safari && inp.checked == true || inp.checked) ? 'label_radio r_on' : 'label_radio r_off';

              };

  

          };

      };

      $('#questionnaire').on('change', ".label_checkbox", function(){

  

          var inp = gebtn(this,'input')[0];

          if (this.className == 'label_checkbox c_off' || (!safari && inp.checked)) {

              $(this).children('input').prop('checked', true);

              this.className = 'label_checkbox c_on';

  

              if (safari) inp.click();

          } else {

              this.className = 'label_checkbox c_off';

              if (safari) inp.click();

          };

      });

      $('#questionnaire').on('change', ".label_radio", function(){

          console.log(this);

          var inp = gebtn(this,'input')[0];

          if (this.className == 'label_radio r_off' || inp.checked) {

              var names = $(this).children("input[type='radio']").attr('name');

              $(this).closest('.back-office-block').find("input[type='radio']").each(function(){

                  if($(this).attr('name') == names){

                      $(this).closest('label').attr('class','label_radio r_off' );

                      var li = $(this).closest('ul').children("li");

                      li.children("ul").each(function() {

                          $(this).remove();

                      });

                      li.children(".additional-question").each(function() {

                              $(this).css("display", "none");

                              $(this).removeClass('status-display');

                      });

                  }

              });

              this.className = 'label_radio r_on';

              if (safari) inp.click();

          } else {

              this.className = 'label_radio r_off';

              if (safari) inp.click();

          };

      });

  });