Blame view

frontend/web/js/new-menu.js 10.8 KB
298bc0f4   Alexey Boroda   first commit
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
  $(function() {
      newMainMenu()
      function newMainMenu() {
          var newMenu = $('.main-menu-new');
  
          newMenu.find('li').each(function() {
              if ($(this).find('ul').length > 0) {
                  $(this).addClass('has-list')
              }
          });
  
          if(!(newMenu.hasClass('demo-main-menu'))){
              newMenu.children('ul').addClass('level-' + (+(newMenu.children('ul').index()) + 1));
              newMenu.children('ul').find('li').children('ul').addClass('level-' + (+(newMenu.children('ul').find('li').children('ul').index()) + 1));
              newMenu.children('ul').find('li').children('ul').find('li').children('ul').addClass('level-3').removeClass('level-2');
  
  
              if(newMenu.hasClass('menu-view-2')){
                  console.log('1111')
                  newMenu.find('.level-1').find('.has-list').find('ul').css({minHeight:newMenu.find('.level-1').height() + 2})
  
              } else if(newMenu.hasClass('menu-view-3')){
                  newMenu.children('ul').find('li').children('ul').find('li').children('ul').find('li').children('ul').addClass('level-4').removeClass('level-3');
  
              } else {
  
                  newMenu.find('.level-2 li.has-list').each(function() {
                      var countLi = $(this).find('ul').find('li').length;
                      $(this).attr('data-li', countLi);
                  });
  
                  newMenu.find('.level-2').attr('data-ul', '0');
  
                  newMenu.find('.level-2 li.has-list').each(function() {
  
                      var num1 = +($(this).attr('data-li'));
                      var num2 = +($(this).parent().attr('data-ul'));
  
                      if (num1 > num2) {
                          $(this).parent().attr('data-ul', num1)
                      }
                  });
  
                  newMenu.find('.level-2').each(function() {
                      var thisNum = +($(this).attr('data-ul'));
  
                      if ($(window).width() > 1200) {
                          $(this).attr('data-row', Math.ceil(thisNum / 4))
                      } else {
                          $(this).attr('data-row', Math.ceil(thisNum / 3))
                      }
  
                      $(this).attr('data-height', +($(this).attr('data-row')) * 140);
  
                      var minHeight = (+($(this).attr('data-height'))) + 47 + 2;
  
                      if($(this).find('ul').length>0) {
  
                          if(minHeight>=469) {
                              $(this).css({height: minHeight});
                              $(this).find('ul').css({minHeight: minHeight})
                          }
                      } else {
                          $(this).css({minHeight: 'auto'})
                      }
  
                  });
              }
  
  
              $(window).resize(function() {
                  newMenu.find('.level-2').each(function() {
                      var thisNum = +($(this)
                          .attr('data-ul'));
  
                      if ($(window)
                              .width() > 1200) {
                          $(this)
                              .attr('data-row', Math.ceil(thisNum / 4))
                      } else {
                          $(this)
                              .attr('data-row', Math.ceil(thisNum / 3))
                      }
                  })
              });
  
              var timeoutMenuSecondRemove;
              var timeoutMenuSecondShow;
              var timeoutMenuSecondShow2;
              var timeoutMenuSecondShow3;
  
              var listUl = $('.main-menu-new ul');
              $('.main-menu-new ul li').hover(function() {
                  var thisIs = $(this);
                  var thisNesting = thisIs.parent();
                  var thisParent = thisIs.parent('ul');
  
                  if(thisIs.parents('.main-menu-new').hasClass('menu-view-3')) {
                      timeoutMenuSecondShow = setTimeout(function() {
  
                          if (thisIs.hasClass('has-list')) {
  
                              if ($('body')
                                      .find('#overlay-menu').length <= 0) {
                                  $('body')
                                      .append('<div id="overlay-menu"></div>');
                              }
  
                              if (thisIs.hasClass('hover')) {
                              } else {
                                  //$('.main-menu-new ul li').removeClass('hover');
  
                                  thisIs.children('ul').removeClass('end-anim-ul');
  
                                  thisIs.parent().find('li').removeClass('hover');
                                  thisIs.addClass('hover');
  
                                  setTimeout(function() {
                                      thisIs.children('ul').addClass('start-anim-ul')
                                  }, 20);
  
                                  setTimeout(function() {
                                      thisIs.children('ul').addClass('end-anim-ul');
                                      thisIs.children('ul').removeClass('start-anim-ul')
                                  }, 310)
                              }
  
                          } else {
                              thisIs.parent().find('li').removeClass('hover');
                              thisIs.find('ul').removeClass('end-anim-ul');
                          }
  
                      }, 300)
                  } else {
                      if (thisNesting.hasClass('level-1')) {
                          timeoutMenuSecondShow = setTimeout(function() {
  
                              if (thisIs.hasClass('has-list')) {
  
                                  if ($('body')
                                          .find('#overlay-menu').length <= 0) {
                                      $('body')
                                          .append('<div id="overlay-menu"></div>');
                                  }
  
                                  if (thisIs.hasClass('hover')) {
                                  } else {
                                      $('.main-menu-new ul li')
                                          .removeClass('hover');
                                      $('.main-menu-new ul li')
                                          .removeClass('hover2');
  
                                      thisIs.children('ul')
                                          .removeClass('end-anim-ul');
                                      $('.main-menu-new ul li ul')
                                          .removeClass('end-anim-ul2');
                                      thisIs.addClass('hover');
  
                                      setTimeout(function() {
                                          thisIs.children('ul')
                                              .addClass('start-anim-ul')
                                      }, 20);
  
                                      setTimeout(function() {
                                          thisIs.children('ul')
                                              .addClass('end-anim-ul');
                                          thisIs.children('ul')
                                              .removeClass('start-anim-ul')
                                      }, 310)
                                  }
  
                              } else {
                                  $('.main-menu-new ul li')
                                      .removeClass('hover');
                                  $('.main-menu-new ul li')
                                      .removeClass('hover2');
                                  $('.main-menu-new ul')
                                      .removeClass('end-anim-ul');
                                  $('.main-menu-new ul li ul')
                                      .removeClass('end-anim-ul2');
                              }
  
                          }, 300)
                      }
                      if (thisNesting.hasClass('level-2') && thisNesting.hasClass('end-anim-ul')) {
                          timeoutMenuSecondShow2 = setTimeout(function() {
                              if (thisIs.hasClass('has-list')) {
                                  if (thisIs.hasClass('hover2')) {
  
                                  } else {
                                      $('.main-menu-new ul li')
                                          .removeClass('hover2');
  
                                      $('.main-menu-new ul')
                                          .removeClass('end-anim-ul2');
                                      thisIs.addClass('hover2');
  
                                      setTimeout(function() {
                                          console.log($(this)
                                              .height());
                                          thisIs.children('ul')
                                              .addClass('start-anim-ul2')
  
                                      }, 20);
  
                                      setTimeout(function() {
                                          thisIs.children('ul')
                                              .addClass('end-anim-ul2');
                                          thisIs.children('ul')
                                              .removeClass('start-anim-ul2')
                                      }, 410)
                                  }
                              } else {
                                  $('.main-menu-new ul li')
                                      .removeClass('hover2');
                                  $('.main-menu-new ul')
                                      .removeClass('end-anim-ul2');
                              }
  
                          }, 300)
  
                      }
                  }
  
  
  
  
  
              }, function() {
                  var thisNesting = $(this).parent();
                  var thisIs = $(this);
                  if(thisIs.parents('.main-menu-new').hasClass('menu-view-3')) {
                      clearTimeout(timeoutMenuSecondShow);
                  } else {
                      if (thisNesting.hasClass('level-1')) {
                          clearTimeout(timeoutMenuSecondShow);
                      }
                      if (thisNesting.hasClass('level-2')) {
                          clearTimeout(timeoutMenuSecondShow2);
                      }
                  }
  
              });
  
              var timeoutOverlay;
              $('body').on('mouseover', '#overlay-menu', function() {
                      timeoutOverlay = setTimeout(function() {
                          $('#overlay-menu').remove();
                          $('.main-menu-new ul li')
                              .removeClass('hover');
                          $('.main-menu-new ul li')
                              .removeClass('hover2');
                          $('.main-menu-new ul li ul')
                              .removeClass('end-anim-ul');
                          $('.main-menu-new ul li ul')
                              .removeClass('end-anim-ul2');
                          $('.main-nav-item').removeClass('open');
                      }, 300)
                  });
              $('body').on('mouseout', '#overlay-menu', function() {
                      clearTimeout(timeoutOverlay)
                  })
  
          } else {
  
  
          }
      }
  });