Advertisement
DenChu

Mixin для нормального отображения кнопки больше в меню

Mar 1st, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.       <script type="text/javascript">
  2.       ips.controller.mixin('test','core.front.core.navBar', true, function () {
  3.             this._mushMenu =function(bar, widthAdjustment) {
  4.             var self = this;
  5.             var padding = parseInt(this.scope.css('padding-left')) + parseInt(this.scope.css('padding-right'));
  6.             var availableSpace = this.scope.width() - widthAdjustment - padding;
  7.             var changed = false;
  8.                var moreItem = bar.find('> [data-role="navMore"]');
  9.             var moreMenuSize = moreItem.outerWidth();
  10.             var menuItems = bar.find('> li[data-role="navBarItem"]');
  11.             var sizeIncrement = 0;
  12.             var dropdown = bar.find('[data-role="moreDropdown"]');
  13.                    console.log('availableSpace: '+availableSpace);
  14.                
  15.  
  16.             if (!moreItem.is(':visible')) {
  17.                 moreMenuSize = moreItem.removeClass('ipsHide').outerWidth();
  18.                 moreItem.addClass('ipsHide');
  19.             }
  20.                console.log('moresize2: '+moreMenuSize);
  21.             menuItems.each(function() {
  22.                 var item = $(this);
  23.                 var itemSize = 0;
  24.                 if (item.attr('data-originalWidth')) {
  25.                     itemSize = parseInt(item.attr('data-originalWidth'));
  26.                 } else {
  27.                     var o = item.outerWidth() + parseInt(item.css('margin-right')) + parseInt(item.css('margin-left'));
  28.                     item.attr('data-originalWidth', o);
  29.                     itemSize = o;
  30.                 }
  31.                   console.log(item.identify().attr('id')+' sizeIncrement + itemSize + moreMenuSize: '+(sizeIncrement + itemSize + moreMenuSize));
  32.                 if (((sizeIncrement + itemSize + moreMenuSize) > availableSpace && moreItem.is(':visible')) || (sizeIncrement + itemSize) > availableSpace ) {
  33.                     if (!item.attr('data-mushed')) {
  34.                         var newLI = $('<li/>').attr('data-originalItem', item.identify().attr('id')).append(item.contents());
  35.                         if (self._usingSubBars) {
  36.                             if (bar.is('[data-role="primaryNavBar"]')) {
  37.                                 bar.find('> [data-role="navMore"] > [data-role="secondaryNavBar"]').prepend(newLI);
  38.                                 if (newLI.find('> [data-role="secondaryNavBar"] > li').length) {
  39.                                     var newA = newLI.find('> a');
  40.                                     var newDropdown = $('<ul/>').addClass('ipsMenu ipsMenu_auto ipsHide').attr('id', newA.identify().attr('id') + '_menu').attr('data-mushedDropdown', item.identify().attr('id'));
  41.                                     newLI.find('> [data-role="secondaryNavBar"] > li').each(function() {
  42.                                         if ($(this).is('[data-role="navMore"]')) {
  43.                                             return;
  44.                                         }
  45.                                         var newMenuItem = $('<li/>').addClass('ipsMenu_item');
  46.                                         if ($(this).find('.ipsMenu').length) {
  47.                                             newMenuItem.addClass('ipsMenu_subItems');
  48.                                         }
  49.                                         newDropdown.append(newMenuItem.append($(this).contents()).attr('data-originalItem', $(this).identify().attr('id')));
  50.                                     });
  51.                                     newA.attr('data-ipsMenu', '').attr('data-ipsMenu-appendTo', '#' + self.scope.identify().attr('id')).append("<i class='fa fa-caret-down' data-role='mushedCaret'></i>");
  52.                                     newLI.append(newDropdown);
  53.                                 }
  54.                             } else {
  55.                                 newLI.addClass('ipsMenu_item');
  56.                                 if (newLI.find('.ipsMenu').length) {
  57.                                     newLI.addClass('ipsMenu_subItems');
  58.                                 }
  59.                                 dropdown.append(newLI);
  60.                             }
  61.                         } else {
  62.                             self.scope.find('#elNavigationMore_dropdown_menu').append(newLI.addClass('ipsMenu_item'));
  63.                             if (newLI.find('.ipsMenu').length) {
  64.                                 newLI.addClass('ipsMenu_subItems');
  65.                             }
  66.                         }
  67.                         var linkInList = newLI.children('a');
  68.                         if (linkInList.is('[data-ipsMenu]')) {
  69.                             linkInList.attr('data-ipsMenu-appendTo', '#' + newLI.identify().attr('id'));
  70.                         }
  71.                         item.addClass('ipsHide').attr('data-mushed', true);
  72.                         changed = true;
  73.                     }
  74.                 } else if (item.attr('data-mushed')) {
  75.                     var mushedParent = null;
  76.                     var mushedItem = null;
  77.                     if (!self._usingSubBars) {
  78.                         mushedParent = self.scope.find('#elNavigationMore_dropdown_menu');
  79.                     } else if (bar.is('[data-role="primaryNavBar"]')) {
  80.                         mushedParent = bar.find('> [data-role="navMore"] > [data-role="secondaryNavBar"]');
  81.                     } else {
  82.                         mushedParent = dropdown;
  83.                     }
  84.                     var mushedItem = mushedParent.find('[data-originalItem="' + item.identify().attr('id') + '"]');
  85.                     if (mushedItem.children('a').is('[data-ipsMenu]')) {
  86.                         mushedItem.children('a').attr('data-ipsMenu-appendTo', '#' + item.identify().attr('id'));
  87.                     }
  88.                     if (mushedItem.length) {
  89.                         item.append(mushedItem.contents()).removeClass('ipsHide');
  90.                     }
  91.                     if (self._usingSubBars && bar.is('[data-role="primaryNavBar"]')) {
  92.                         var mushedDropdown = self.scope.find('[data-mushedDropdown="' + item.attr('id') + '"]');
  93.                         var secondaryMenu = item.find('> [data-role="secondaryNavBar"]');
  94.                         if (mushedDropdown.length) {
  95.                             mushedDropdown.find('> .ipsMenu_item').each(function() {
  96.                                 var originalItem = self.scope.find('#' + $(this).attr('data-originalItem'));
  97.                                 originalItem.append($(this).contents());
  98.                             });
  99.                             mushedDropdown.remove();
  100.                         }
  101.                         item.find('[data-role="mushedCaret"]').remove();
  102.                     }
  103.                     mushedItem.remove();
  104.                     item.removeAttr('data-mushed');
  105.                   changed = true;
  106.                 }
  107.                
  108.                 sizeIncrement += itemSize;
  109.             });
  110.             if (bar.is('[data-role="primaryNavBar"]')) {
  111.                 if (this._usingSubBars) {
  112.                     moreItem.toggleClass('ipsHide', bar.find('> [data-role="navMore"] > [data-role="secondaryNavBar"] > li').length <= 1);
  113.                 } else {
  114.                     moreItem.toggleClass('ipsHide', !this.scope.find('#elNavigationMore_dropdown_menu > li').length);
  115.                 }
  116.             } else {
  117.                 moreItem.toggleClass('ipsHide', dropdown.find('> li').length < 1);
  118.             }
  119.             if(changed) self._mushMenu(bar, widthAdjustment);
  120.             this._makeDefaultActive();
  121.         },
  122.      
  123.        
  124.        
  125.             this._mushAllMenus = function() {
  126.            
  127.             this._mushMenu(this.scope.find('[data-role="primaryNavBar"]'),$('#elUserNav').outerWidth()+$('#elLogo').outerWidth()+161);
  128.             this._mushMenu(this.scope.find('[data-role="secondaryNavBar"]:visible'), 0);
  129.             }
  130.  
  131.     });
  132.       </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement