Blame view

frontend/web/js/goods.js 5.76 KB
40e4f314   Mihail   rewrite js skript...
1
  $(document).ready(function () {
b13c67c3   Mihail   output price in g...
2
3
      // для таблицы кроссов, классы обозначаются через cross_
      var cross_prefix = '';
b13c67c3   Mihail   output price in g...
4
5
      // по умолчанию - цены в долларах, остальные скрываем
      var show_currency = ['usd'];
40e4f314   Mihail   rewrite js skript...
6
      var hidden_currency = ['uah', 'eur'];
b13c67c3   Mihail   output price in g...
7
  
89640009   Mihail   add sort function...
8
9
10
11
      // первоначальная инициация цен
      priceInitialisation();
  
      // привяжем обработчик смены валюты
40e4f314   Mihail   rewrite js skript...
12
      $(document).on("click", ".currency", changeCurrency);
b13c67c3   Mihail   output price in g...
13
  
89640009   Mihail   add sort function...
14
15
16
17
18
      // привяжем обработчик обновления страницы pjax
      $(document).on('pjax:complete', function() {
          console.log(document.location);
          priceInitialisation();
      })
b13c67c3   Mihail   output price in g...
19
  
89640009   Mihail   add sort function...
20
21
  
      function changeCurrency() {
36a8dd60   Mihail   add pjax to goods...
22
23
          $('.currency').removeClass('active_button_purple1');
          $(this).addClass('active_button_purple1');
89640009   Mihail   add sort function...
24
25
26
          // после смены валюты - покажем  цены в выбранной валюте
          priceInitialisation();
      }
b13c67c3   Mihail   output price in g...
27
  
89640009   Mihail   add sort function...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
      function priceInitialisation() {
  
          // найдем текущую установленную валюту, и пересчитаем цены в ней
          var current_currency = $('.active_button_purple1')[0];
          if (typeof current_currency === 'object'){
  
              if (current_currency.getAttribute('id') === 'grivna') {
                  show_currency = ['uah'];
                  hidden_currency = ['eur', 'usd'];
              } else if (current_currency.getAttribute('id') === 'euro') {
                  show_currency = ['eur'];
                  hidden_currency = ['uah', 'usd'];
              } else if (current_currency.getAttribute('id') === 'dollars') {
                  show_currency = ['usd'];
                  hidden_currency = ['uah', 'eur'];
              }
              setVisiblePrice();
          }
b13c67c3   Mihail   output price in g...
46
47
      }
  
40e4f314   Mihail   rewrite js skript...
48
      function setVisiblePrice() {
b13c67c3   Mihail   output price in g...
49
          // элементы с классами из show_currency отобразим
40e4f314   Mihail   rewrite js skript...
50
          for (var i = 0; i < show_currency.length; i++) {
b13c67c3   Mihail   output price in g...
51
              var arr_elements = document.getElementsByClassName(show_currency[i] + cross_prefix);
b13c67c3   Mihail   output price in g...
52
  
40e4f314   Mihail   rewrite js skript...
53
54
              for (var j = 0; j < arr_elements.length; j++) {
                  if (arr_elements[j].classList.contains('hidden'))
b13c67c3   Mihail   output price in g...
55
56
57
                      arr_elements[j].classList.remove('hidden');
              }
          }
b13c67c3   Mihail   output price in g...
58
          // элементы с классами из hidden_currency спрячем
40e4f314   Mihail   rewrite js skript...
59
          for (var i = 0; i < hidden_currency.length; i++) {
b13c67c3   Mihail   output price in g...
60
              var arr_elements = document.getElementsByClassName(hidden_currency[i] + cross_prefix);
40e4f314   Mihail   rewrite js skript...
61
62
              for (var j = 0; j < arr_elements.length; j++) {
                  if (!arr_elements[j].classList.contains('hidden'))
b13c67c3   Mihail   output price in g...
63
64
65
66
67
                      arr_elements[j].classList.add('hidden');
              }
          }
      }
  
e0e82549   OlenaKl   table
68
  //модальное окно для фото
40e4f314   Mihail   rewrite js skript...
69
70
      // ловим клик по ссылки с id="go"
      $(document).on("click", 'a#go_photo', function (event) {
e0e82549   OlenaKl   table
71
72
73
          event.preventDefault(); // выключаем стандартную роль элемента
          var scrollTop = window.pageYOffset ? window.pageYOffset : (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
          viewportHeight = $(window).height();
40e4f314   Mihail   rewrite js skript...
74
75
          var modalWidth = $('#modal_form_photo').width() / 2;
          var modalHeight = $('#modal_form_photo').outerHeight() / 2;
e0e82549   OlenaKl   table
76
          $('#overlay').fadeIn(400, // сначала плавно показываем темную подложку
40e4f314   Mihail   rewrite js skript...
77
              function () { // после выполнения предъидущей анимации
e0e82549   OlenaKl   table
78
                  $('#modal_form_photo')
40e4f314   Mihail   rewrite js skript...
79
80
                      .css({'display': 'block', opacity: 1, marginTop: -modalHeight, marginLeft: -modalWidth}) // убираем у модального окна display: none;
                      .animate({opacity: 1, top: scrollTop + (viewportHeight / 2)}, 200); // плавно прибавляем прозрачность одновременно со съезжанием вниз
e0e82549   OlenaKl   table
81
82
83
84
              });
  
      });
      /* Закрытие модального окна, тут делаем то же самое но в обратном порядке */
40e4f314   Mihail   rewrite js skript...
85
      $(document).on( "click",'#modal_close, #overlay', function () { // ловим клик по крестику или подложке
e0e82549   OlenaKl   table
86
87
          $('#modal_form_photo')
              .animate({opacity: 0, top: '45%'}, 200,  // плавно меняем прозрачность на 0 и одновременно двигаем окно вверх
40e4f314   Mihail   rewrite js skript...
88
              function () { // после анимации
e0e82549   OlenaKl   table
89
90
91
92
93
                  $(this).css('display', 'none'); // делаем ему display: none;
                  $('#overlay').fadeOut(400); // скрываем подложку
              }
          );
      });
89640009   Mihail   add sort function...
94
  
e0e82549   OlenaKl   table
95
96
      //открытие-закрытие карточки товара и смена текста на бирке карточки товара
      function changeText() {
e0e82549   OlenaKl   table
97
          e = document.getElementById('button_grey_card');
e0e82549   OlenaKl   table
98
99
          e.innerHTML = e.innerHTML == "Скрыть карточку товара" ? "Открыть карточку товара" : "Скрыть карточку товара";
      }
40e4f314   Mihail   rewrite js skript...
100
101
  
      $(document).on( "click",'#button_grey_card' , function () {
e0e82549   OlenaKl   table
102
103
104
105
106
          changeText();
          $(this).toggleClass('change_b');
          $('.tovar_card').toggleClass('tovar_card_visible');
          $('.table').toggleClass('table_height');
      });
89640009   Mihail   add sort function...
107
108
109
110
111
112
      // модальная форма с инфой по тех-доку
      $(document).on("click", '.tecdoc_id_info', function(e){
          var tecdoc_id = $(this).data('id');
          $.post( "/detail/get-details-for-item", {tecdoc_id:tecdoc_id},function( data ) {
              $('#details_content').empty();
              $('#details_content').html(data);
e0e82549   OlenaKl   table
113
  
89640009   Mihail   add sort function...
114
          });
e0e82549   OlenaKl   table
115
  
89640009   Mihail   add sort function...
116
      });});
e0e82549   OlenaKl   table