date-picker.js
1 year ago
duplicate-field.js
2 years ago
email-reports.js
2 years ago
notices.js
2 years ago
scroll-to-top.js
2 years ago
sticky-sidebar.js
2 years ago
support.js
2 years ago
user-roles.js
1 year ago
sticky-sidebar.js
100 lines
| 1 | const $ = jQuery; |
| 2 | |
| 3 | const StickySidebar = { |
| 4 | setup() { |
| 5 | if ($('#iawp-layout-sidebar').length == 0) { |
| 6 | return; |
| 7 | } |
| 8 | |
| 9 | let scrollPosition = window.scrollY; |
| 10 | const sidebar = document.getElementById('iawp-layout-sidebar'); |
| 11 | const sidebarContainer = document.querySelector('.iawp-layout-sidebar'); |
| 12 | const layoutContainer = document.getElementById('iawp-layout'); |
| 13 | var self = this; |
| 14 | |
| 15 | if(!sidebar && !layoutContainer) { |
| 16 | return; // These elements aren't visible on an interrupt page such as migration pending page |
| 17 | } |
| 18 | |
| 19 | sidebar.scroll(0, window.scrollY); |
| 20 | this.setMinMainHeight(); |
| 21 | |
| 22 | document.addEventListener('scroll', () => { |
| 23 | const change = scrollPosition - window.scrollY; |
| 24 | |
| 25 | if (window.scrollY < 1 || window.scrollY > ($(document).height() - $(window).height() - 1)) { |
| 26 | scrollPosition = window.scrollY; |
| 27 | return; |
| 28 | } |
| 29 | sidebar.scroll(0, sidebar.scrollTop - change); |
| 30 | scrollPosition = window.scrollY; |
| 31 | }); |
| 32 | |
| 33 | window.addEventListener('resize', () => { |
| 34 | this.setMinMainHeight(); |
| 35 | }); |
| 36 | |
| 37 | document.getElementById('collapse-sidebar').addEventListener('click', () => { |
| 38 | const isSidebarCollapsed = layoutContainer.classList.toggle('collapsed'); |
| 39 | this.saveSidebarState(isSidebarCollapsed) |
| 40 | sidebar.scroll(0, window.scrollY); |
| 41 | this.setMinMainHeight(); |
| 42 | this.setTableHorizontal(); |
| 43 | }); |
| 44 | |
| 45 | $('#mobile-menu-toggle').on('click', function() { |
| 46 | if ($('#menu-container').hasClass('open')) { |
| 47 | $('#menu-container').removeClass('open'); |
| 48 | $(this).find('.text').text(iawpText.openMobileMenu); |
| 49 | } else { |
| 50 | $('#menu-container').addClass('open'); |
| 51 | $(this).find('.text').text(iawpText.closeMobileMenu); |
| 52 | } |
| 53 | }); |
| 54 | |
| 55 | var dataTableContainer = $('#data-table-container'); |
| 56 | var dataTable = $('#data-table'); |
| 57 | |
| 58 | // Data table resizing |
| 59 | if (dataTable.width() > dataTableContainer.width()) { |
| 60 | self.setTableHorizontal(); |
| 61 | } |
| 62 | $(window).on('resize', function() { |
| 63 | self.setTableHorizontal(); |
| 64 | self.setReportTitleMaxWidth(); |
| 65 | }); |
| 66 | |
| 67 | this.setReportTitleMaxWidth(); |
| 68 | }, |
| 69 | saveSidebarState(isSidebarCollapsed) { |
| 70 | const data = { |
| 71 | ...iawpActions.update_user_settings, |
| 72 | 'is_sidebar_collapsed': isSidebarCollapsed |
| 73 | }; |
| 74 | |
| 75 | jQuery.post(ajaxurl, data, (response) => { |
| 76 | |
| 77 | }).fail(() => { |
| 78 | |
| 79 | }); |
| 80 | }, |
| 81 | setMinMainHeight() { |
| 82 | $('.iawp-layout-main').css('min-height', $('.iawp-layout-sidebar .inner').outerHeight(true) + 32); |
| 83 | }, |
| 84 | setTableHorizontal() { |
| 85 | if ($('#data-table').width() > $('#data-table-container').width()) { |
| 86 | $('#data-table-container').addClass('horizontal'); |
| 87 | } else { |
| 88 | $('#data-table-container').removeClass('horizontal'); |
| 89 | } |
| 90 | }, |
| 91 | setReportTitleMaxWidth() { |
| 92 | if ($(window).width() < 600) { |
| 93 | $('.rename-report').css('max-width', ''); |
| 94 | } else { |
| 95 | $('.rename-report').css('max-width', 'calc(100% - ' + $('.report-title-bar .buttons').width() + 'px)'); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | export { StickySidebar }; |