2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import ContextualSidebar from './contextual_sidebar';
|
2017-09-10 17:25:29 +05:30
|
|
|
import initFlyOutNav from './fly_out_nav';
|
2021-02-22 17:27:13 +05:30
|
|
|
import { setNotification } from './whats_new/utils/notification';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
function hideEndFade($scrollingTabs) {
|
|
|
|
$scrollingTabs.each(function scrollTabsLoop() {
|
|
|
|
const $this = $(this);
|
2018-12-13 13:39:08 +05:30
|
|
|
$this
|
|
|
|
.siblings('.fade-right')
|
|
|
|
.toggleClass('scrolling', Math.round($this.width()) < $this.prop('scrollWidth'));
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
function initDeferred() {
|
|
|
|
$(document).trigger('init.scrolling-tabs');
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const appEl = document.getElementById('whats-new-app');
|
|
|
|
if (!appEl) return;
|
|
|
|
|
|
|
|
setNotification(appEl);
|
|
|
|
document.querySelector('.js-whats-new-trigger').addEventListener('click', () => {
|
|
|
|
import(/* webpackChunkName: 'whatsNewApp' */ '~/whats_new')
|
|
|
|
.then(({ default: initWhatsNew }) => {
|
|
|
|
initWhatsNew(appEl);
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
export default function initLayoutNav() {
|
|
|
|
const contextualSidebar = new ContextualSidebar();
|
|
|
|
contextualSidebar.bindEvents();
|
|
|
|
|
|
|
|
initFlyOutNav();
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
// We need to init it on DomContentLoaded as others could also call it
|
|
|
|
$(document).on('init.scrolling-tabs', () => {
|
|
|
|
const $scrollingTabs = $('.scrolling-tabs').not('.is-initialized');
|
|
|
|
$scrollingTabs.addClass('is-initialized');
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
$(window)
|
|
|
|
.on('resize.nav', () => {
|
|
|
|
hideEndFade($scrollingTabs);
|
|
|
|
})
|
|
|
|
.trigger('resize.nav');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
$scrollingTabs.on('scroll', function tabsScrollEvent() {
|
|
|
|
const $this = $(this);
|
|
|
|
const currentPosition = $this.scrollLeft();
|
|
|
|
const maxPosition = $this.prop('scrollWidth') - $this.outerWidth();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
$this.siblings('.fade-left').toggleClass('scrolling', currentPosition > 0);
|
|
|
|
$this.siblings('.fade-right').toggleClass('scrolling', currentPosition < maxPosition - 1);
|
|
|
|
});
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
$scrollingTabs.each(function scrollTabsEachLoop() {
|
|
|
|
const $this = $(this);
|
|
|
|
const scrollingTabWidth = $this.width();
|
|
|
|
const $active = $this.find('.active');
|
|
|
|
const activeWidth = $active.width();
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
if ($active.length) {
|
|
|
|
const offset = $active.offset().left + activeWidth;
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
if (offset > scrollingTabWidth - 30) {
|
|
|
|
const scrollLeft = offset - scrollingTabWidth / 2 - activeWidth / 2;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
$this.scrollLeft(scrollLeft);
|
2016-09-29 09:46:39 +05:30
|
|
|
}
|
2019-03-02 22:35:43 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
requestIdleCallback(initDeferred);
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|