Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- ips.controller.mixin('test','core.front.core.navBar', true, function () {
- this._mushMenu =function(bar, widthAdjustment) {
- var self = this;
- var padding = parseInt(this.scope.css('padding-left')) + parseInt(this.scope.css('padding-right'));
- var availableSpace = this.scope.width() - widthAdjustment - padding;
- var changed = false;
- var moreItem = bar.find('> [data-role="navMore"]');
- var moreMenuSize = moreItem.outerWidth();
- var menuItems = bar.find('> li[data-role="navBarItem"]');
- var sizeIncrement = 0;
- var dropdown = bar.find('[data-role="moreDropdown"]');
- console.log('availableSpace: '+availableSpace);
- if (!moreItem.is(':visible')) {
- moreMenuSize = moreItem.removeClass('ipsHide').outerWidth();
- moreItem.addClass('ipsHide');
- }
- console.log('moresize2: '+moreMenuSize);
- menuItems.each(function() {
- var item = $(this);
- var itemSize = 0;
- if (item.attr('data-originalWidth')) {
- itemSize = parseInt(item.attr('data-originalWidth'));
- } else {
- var o = item.outerWidth() + parseInt(item.css('margin-right')) + parseInt(item.css('margin-left'));
- item.attr('data-originalWidth', o);
- itemSize = o;
- }
- console.log(item.identify().attr('id')+' sizeIncrement + itemSize + moreMenuSize: '+(sizeIncrement + itemSize + moreMenuSize));
- if (((sizeIncrement + itemSize + moreMenuSize) > availableSpace && moreItem.is(':visible')) || (sizeIncrement + itemSize) > availableSpace ) {
- if (!item.attr('data-mushed')) {
- var newLI = $('<li/>').attr('data-originalItem', item.identify().attr('id')).append(item.contents());
- if (self._usingSubBars) {
- if (bar.is('[data-role="primaryNavBar"]')) {
- bar.find('> [data-role="navMore"] > [data-role="secondaryNavBar"]').prepend(newLI);
- if (newLI.find('> [data-role="secondaryNavBar"] > li').length) {
- var newA = newLI.find('> a');
- var newDropdown = $('<ul/>').addClass('ipsMenu ipsMenu_auto ipsHide').attr('id', newA.identify().attr('id') + '_menu').attr('data-mushedDropdown', item.identify().attr('id'));
- newLI.find('> [data-role="secondaryNavBar"] > li').each(function() {
- if ($(this).is('[data-role="navMore"]')) {
- return;
- }
- var newMenuItem = $('<li/>').addClass('ipsMenu_item');
- if ($(this).find('.ipsMenu').length) {
- newMenuItem.addClass('ipsMenu_subItems');
- }
- newDropdown.append(newMenuItem.append($(this).contents()).attr('data-originalItem', $(this).identify().attr('id')));
- });
- newA.attr('data-ipsMenu', '').attr('data-ipsMenu-appendTo', '#' + self.scope.identify().attr('id')).append("<i class='fa fa-caret-down' data-role='mushedCaret'></i>");
- newLI.append(newDropdown);
- }
- } else {
- newLI.addClass('ipsMenu_item');
- if (newLI.find('.ipsMenu').length) {
- newLI.addClass('ipsMenu_subItems');
- }
- dropdown.append(newLI);
- }
- } else {
- self.scope.find('#elNavigationMore_dropdown_menu').append(newLI.addClass('ipsMenu_item'));
- if (newLI.find('.ipsMenu').length) {
- newLI.addClass('ipsMenu_subItems');
- }
- }
- var linkInList = newLI.children('a');
- if (linkInList.is('[data-ipsMenu]')) {
- linkInList.attr('data-ipsMenu-appendTo', '#' + newLI.identify().attr('id'));
- }
- item.addClass('ipsHide').attr('data-mushed', true);
- changed = true;
- }
- } else if (item.attr('data-mushed')) {
- var mushedParent = null;
- var mushedItem = null;
- if (!self._usingSubBars) {
- mushedParent = self.scope.find('#elNavigationMore_dropdown_menu');
- } else if (bar.is('[data-role="primaryNavBar"]')) {
- mushedParent = bar.find('> [data-role="navMore"] > [data-role="secondaryNavBar"]');
- } else {
- mushedParent = dropdown;
- }
- var mushedItem = mushedParent.find('[data-originalItem="' + item.identify().attr('id') + '"]');
- if (mushedItem.children('a').is('[data-ipsMenu]')) {
- mushedItem.children('a').attr('data-ipsMenu-appendTo', '#' + item.identify().attr('id'));
- }
- if (mushedItem.length) {
- item.append(mushedItem.contents()).removeClass('ipsHide');
- }
- if (self._usingSubBars && bar.is('[data-role="primaryNavBar"]')) {
- var mushedDropdown = self.scope.find('[data-mushedDropdown="' + item.attr('id') + '"]');
- var secondaryMenu = item.find('> [data-role="secondaryNavBar"]');
- if (mushedDropdown.length) {
- mushedDropdown.find('> .ipsMenu_item').each(function() {
- var originalItem = self.scope.find('#' + $(this).attr('data-originalItem'));
- originalItem.append($(this).contents());
- });
- mushedDropdown.remove();
- }
- item.find('[data-role="mushedCaret"]').remove();
- }
- mushedItem.remove();
- item.removeAttr('data-mushed');
- changed = true;
- }
- sizeIncrement += itemSize;
- });
- if (bar.is('[data-role="primaryNavBar"]')) {
- if (this._usingSubBars) {
- moreItem.toggleClass('ipsHide', bar.find('> [data-role="navMore"] > [data-role="secondaryNavBar"] > li').length <= 1);
- } else {
- moreItem.toggleClass('ipsHide', !this.scope.find('#elNavigationMore_dropdown_menu > li').length);
- }
- } else {
- moreItem.toggleClass('ipsHide', dropdown.find('> li').length < 1);
- }
- if(changed) self._mushMenu(bar, widthAdjustment);
- this._makeDefaultActive();
- },
- this._mushAllMenus = function() {
- this._mushMenu(this.scope.find('[data-role="primaryNavBar"]'),$('#elUserNav').outerWidth()+$('#elLogo').outerWidth()+161);
- this._mushMenu(this.scope.find('[data-role="secondaryNavBar"]:visible'), 0);
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement