Blame view

js/modalBox/modalBox.js 2.05 KB
bde80a8f   andryeyev   + Модальные окна
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  
      // =============
      // ==== VAR ====
      // =============
   
      var $modalBoxTotal = 0;
      
      // ===============
      // ==== METOD ====
      // =============== 
     
      function percentToPix ($value) 
      {
          return $value == null ? 0 : parseInt (screen.width * $value / 100);
      }
   
      function modalBoxLoad (content, $option) 
      { 
          var ID = $modalBoxTotal;
          $width = 80;
          $modalBoxId = 'modalBoxId-' + ID;
          $style = 'style="max-width:' + percentToPix ($width) + 'px;"';
33349e3d   andryeyev   + callback
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  
          var $modal =
          '<div id="' + $modalBoxId + '" class="modal fade" tabindex="-1" role="dialog">'
              + '<div class="modal-dialog">'
              + '<div class="modal-content">'
                  + '<div class="modal-header">'
                      + '<button aria-label="Close" data-dismiss="modal" class="close" type="button">'
                          + '<span aria-hidden="true">x</span>'
                      + '</button>'
                  + '</div>'
              + '<div class="modal-body">'
                  + content
              + '</div>'
  /*
              + '<div class="modal-footer">'
                  + '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>'
                  + '<button type="button" class="btn btn-primary">Save changes</button>'
              + '</div>'
  */
              + '</div>'
              + '</div>'
bde80a8f   andryeyev   + Модальные окна
44
          + '</div>';
33349e3d   andryeyev   + callback
45
46
47
48
49
  
          $modalBoxTotal++;
  
          if ($('#duty').length == 0) {
              $('body').append('<div id="duty"></div>');
bde80a8f   andryeyev   + Модальные окна
50
          }
33349e3d   andryeyev   + callback
51
52
  
          $('#duty').html($modal).promise().done(function()
bde80a8f   andryeyev   + Модальные окна
53
          {
33349e3d   andryeyev   + callback
54
55
56
57
58
59
60
61
62
              $('#' + $modalBoxId)
                  .modal('show')
                  .on('hidden.bs.modal', function (e)
                  {
                      $(this).data('bs.modal', null);
                      $('#' + $modalBoxId).remove();
                      window.modalBoxTotal--;
                  });
          });
bde80a8f   andryeyev   + Модальные окна
63
64
65
66
      }
      
      function modalBoxClose () 
      {
33349e3d   andryeyev   + callback
67
          $('#modal').hide();
bde80a8f   andryeyev   + Модальные окна
68
      }
33349e3d   andryeyev   + callback
69
  
bde80a8f   andryeyev   + Модальные окна
70
71
72
73
      function isModalBox () 
      {  
          return ($modalBoxTotal > 0) ? true : false;
      }