YaWK  24.1
Yet another WebKit
sidebar.js
Go to the documentation of this file.
1 /**
2  * @file system/widgets/submenu/sidebar.js
3  * @brief Javascript for the Submenu module.
4  * @details The $(window).scroll() function is used to detect when the user has scrolled beyond startPosition,
5  * at which point the openBtn and mySidebar elements are faded in using .fadeIn(). If the user scrolls back up,
6  * the elements are faded out
7  *
8  * The introBottom and sidebarBottom variables are set to the bottom position of the intro and sidebar elements
9  * respectively, and are used to determine if mySidebar should be hidden because it overlaps with intro. If
10  * introBottom is greater than or equal to sidebarBottom, the opacity and width of mySidebar are set to 0.
11  *
12  * this code will should only be executed, if the submenu property 'sidebar' is set to true
13  *
14  */
15 function openNav() {
16  document.getElementById("mySidebar").style.width = "300px"; // how many pixels wide the sidebar is
17  document.getElementById("main").style.marginLeft = "125px"; // how many pixels will the main content be pushed to the right
18 
19 }
20 function closeNav() {
21  document.getElementById("mySidebar").style.width = "0"; // set width to zero to hide the sidebar
22  document.getElementById("main").style.marginLeft= "0"; // reset margin to zero to push main content back to the left
23 }
24 
25 $(document).ready(function()
26 {
27  var sidebarOpen = false; // is the sidebar open?
28  const openBtn = $('#openSubmenuBtn'); // button to open the sidebar
29  const sidebar = $('#mySidebar'); // sidebar div box element (defined in submenu widget class)
30  var showOpenBtnPositionThreshold = 600; // position from where the 'open sidebar btn' gets shown (in pixels)
31  // - above this position the button will be hidden. This ensures, it will not be interfering with the global menu
32  // or any other element on top of page (eg. a carousel or header image) - if this is not wanted, set this value to 0
33 
34  // check if openBtn has been clicked
35  openBtn.click(function()
36  { // if clicked, open the sidebar
37  openNav();
38  });
39 
40  // Initially hide the button
41  openBtn.hide(); // hide the button on page load
42 
43  // which element should be used to determine, if the sidebar should be hidden, because it overlaps with another element?
44  var overlapPositionOrDivBox = $('#globalmenu'); // use globalmenu as overlap indicator to hide sidebar
45 
46  // Get the current scroll position
47  $(window).scroll(function()
48  { // get position of overlap element
49  var overlapPosition = overlapPositionOrDivBox.offset().top + overlapPositionOrDivBox.outerHeight();
50  // get the bottom position of the sidebar element
51  var sidebarCollider = sidebar.offset().top + sidebar.outerHeight();
52  // store the sidebar element in a variable
53  var thisSidebar = document.getElementById("mySidebar");
54 
55  // if the sidebar overlaps with the overlap element, hide the sidebar
56  if (overlapPosition >= sidebarCollider) {
57  // thisSidebar.style.opacity="0";
58  thisSidebar.style.width="0px";
59  }
60 
61  // Get the current scroll position
62  let scrollPosition = $(window).scrollTop();
63 
64  // If the user has scrolled beyond threshold, fadeIn the button
65  if (scrollPosition >= showOpenBtnPositionThreshold) {
66  openBtn.fadeIn();
67  }
68  else
69  { // user has scrolled back up, so fadeOut button + sidebar
70  closeNav();
71  openBtn.fadeOut();
72  }
73  });
74 });
function window
Definition: fuckAdBlock.js:8
function openNav()
Definition: sidebar.js:15
document ready(function() { var sidebarOpen=false;const openBtn=$('#openSubmenuBtn');const sidebar=$('#mySidebar');var showOpenBtnPositionThreshold=600;openBtn.click(function() { openNav();});openBtn.hide();var overlapPositionOrDivBox=$('#globalmenu');$(window).scroll(function() { var overlapPosition=overlapPositionOrDivBox.offset().top+overlapPositionOrDivBox.outerHeight();var sidebarCollider=sidebar.offset().top+sidebar.outerHeight();var thisSidebar=document.getElementById("mySidebar");if(overlapPosition >=sidebarCollider) { thisSidebar.style.width="0px";} let scrollPosition=$(window).scrollTop();if(scrollPosition >=showOpenBtnPositionThreshold) { openBtn.fadeIn();} else { closeNav();openBtn.fadeOut();} });})
function closeNav()
Definition: sidebar.js:20