YaWK  24.1
Yet another WebKit
custom.js
Go to the documentation of this file.
1 /**
2  * @file custom.js
3  * @brief This file contains all custom javascript functions for the YaWK bootstrap4 template
4  * @details this file is loaded after all other javascript files, so you can overwrite any function you like
5  * this provides generic methods to set a navbar sticky on scroll, smooth scrolling to any element on the page
6  * and a scroll to top button handling. You can add / change / remove any function you like.
7  * This gives you the flexibility to customize your template to your needs.
8  *
9  * If you are not familiar with javascript, you can find a lot of tutorials on the web.
10  */
11 $(document).ready(function() // all functions are loaded after document is ready
12 {
13  /**
14  * @brief fadeInNavbar adds a fadeIn animation to the navbar on page load
15  * @details you can change the animation type and speed by changing the class name
16  * Take a look at https://daneden.github.io/animate.css/ for a list of all available animations
17  */
18  // add animated fadeIn class to navbar on page load
19  $('#navbar').addClass('animated fadeIn slow'); // if you don't want the animation, remove this line
20 
21  /**
22  * @brief setSticky makes a navbar sticky on scroll
23  * @details this is achieved by adding a fixed-top class to the navbar
24  * @param domElement the id of the navbar element
25  * @param stickTo the id of the element to stick to
26  * @param offset the offset in px to stick to
27  */
28  function setSticky(domElement, stickTo, offset)
29  { // check if domElement and stickTo are set
30  if (domElement) {
31  console.log('domElement: '+domElement);
32  }
33  else {
34  console.error('Unable to setSticky - domElement is null or undefined: '+domElement);
35  alert('Unable to setSticky - domElement is null or undefined: '+domElement);
36  }
37  if (!stickTo) {
38  console.error('Unable to setSticky - stickTo is null or undefined: '+stickTo);
39  alert('Unable to setSticky - stickTo is null or undefined: '+stickTo);
40  }
41 
42  // check if offset is set, if not, set to 0
43  if (!offset) offset = 0;
44 
45  // add fixed-top class to navbar on scroll
46  $(window).scroll(function()
47  { // if scrolled to top is greater than the current height of intro position
48  // this ensures that the navbar is only fixed, if the intro section is scrolled out of view
49  if ($(window).scrollTop() > $(stickTo).outerHeight())
50  { // add shadow class to navbar if scrolled to top
51  $('#'+domElement).addClass('fixed-top shadow');
52  // get height of navbar
53  var navbar_height = $('.'+domElement).outerHeight();
54  // set padding-top of body to the height of the navbar
55  $('body').css('padding-top', navbar_height + 'px');
56  }
57  else // if scrolled to top is less than the current height of intro position
58  { // = not scrolled to top, then remove fixed-top class from navbar
59  $('#'+domElement).removeClass('fixed-top');
60  // remove padding top from body to reset to default
61  $('body').css('padding-top', 0);
62  }
63  });
64  } // end function setSticky
65 
66  // call setSticky function on this elements to make them sticky on scroll:
67  // you can add / remove / change them to any element you like
68  setSticky('navbar', '#intro', 0);
69  setSticky('MySidebar', '#intro', 100);
70 
71  // smooth scrolling to any element on the page, if it got an anchor link
72  // this adds smooth scrolling to the subMenu.
73  $('#subMenu li').click(function(e) {
74  e.preventDefault();
75  // Submenu Smooth scrolling REQUIRES velocity.js as loaded asset for smooth animation
76  var linkObject = $(this).find('a'); // get link object
77  var href = linkObject.attr('href'); // extract href
78  var target = linkObject.attr('target'); // extract target
79 
80  // The target starts with a "#" character
81  if (href.charAt(0) === '#') {
82  try {
83  // this will smooth scroll to the target element using velocity
84  $('html, body').velocity('scroll', {
85  offset: $(href).offset().top - 250,
86  duration: 2400,
87  easing: 'easeOutQuart'
88  });
89  }
90  catch (error) {
91  // velocity.js is not loaded: fallback to jquery animate method
92  console.log('Info: Velocity.js is not loaded. Please consider loading velocity.js within the template assets if you want the smoothest scroll experience. Error message: ', error.message);
93  // scroll to target element
94  $('html, body').animate({
95  scrollTop: $(href).offset().top - 250
96  }, 2400);
97  }
98  }
99  // handling of non-anchor, external links
100  else
101  { // The link does NOT start with a "#" character (so it must be an external link)
102  // let's check if the target is set
103  if (target) {
104  // target is set, open link with target
105  window.open(href, target);
106  }
107  else
108  { // target is not set, so open link in same window
109  window.open(href, '_self');
110  }
111  }
112  });
113 
114  // scroll to top method REQUIRES VELOCITY.JS loaded before!
115  // if you want to use this, add a div with class="scrollup" to your html element
116  $('.scrollup').click(function() {
117  try{
118  // this will smooth scroll to top of page using velocity
119  $("html, body").velocity("scroll", {
120  duration: 2400,
121  easing: "easeOutExpo"
122  //easing: "ease-out"
123  });
124  }
125  catch {
126  // velocity.js is not loaded: fallback to jquery animate method
127  console.log('Error: Velocity.js is not loaded. Please consider loading velocity.js within the assets if you want the smoothest scroll experience. Error message: ', error.message);
128  // scroll to target element
129 
130  $("html, body").animate({scrollTop:0}, 1200);
131  }
132  });
133 
134  /**
135  * @brief if enabled, this will set a cookie to remember the user choice of dark or light mode
136  * @brief this code sets the cookie for the frontend switch
137  */
138  // switch between dark and light mode
139  // set cookie to remember user choice
140  $('#darkMode').click(function() {
141  var id = $('#darkMode').data('id');
142  document.cookie = 'frontendSwitchID=' + id;
143  });
144  // on click of an element with id="lightMode", set cookie to remember user choice
145  $('#lightMode').click(function() {
146  var id = $('#lightMode').data('id');
147  document.cookie = 'frontendSwitchID=' + id;
148  });
149 
150  /**
151  * @brief this code will fade out an element on scroll down
152  * @details this works well with images, like a carousel on top of the page that fades out on scroll down
153  * If you want to use this, add a div with class="scrollDownFadeOut" or add scrollDownFadeOut class to any element.
154  */
155  $(window).scroll(function() {
156  var screenWidth = $(window).width();
157  var scrollTop = $(window).scrollTop();
158  var fadeOutValue = 1 - (scrollTop / (screenWidth / 3));
159  $(".scrollDownFadeOut").css("opacity", fadeOutValue);
160  });
161 
162  // this will make a div sticky on scroll
163  var $scrollingDiv = $("#scrollingDiv");
164  $(window).scroll(function() {
165  $scrollingDiv.stop().animate({"marginTop": ($(window).scrollTop())}, 0);
166  });
167  // this will add smooth scrolling to all anchor links with class="sliding-link"
168  $(".sliding-link").click(function(e) {
169  e.preventDefault();
170  var aid = $(this).attr("href");
171  $('html,body').animate({scrollTop: $(aid).offset().top - 150}, 'slow');
172  window.location.hash = aid;
173  });
174 
175  /**
176  * @brief this code will add a tooltip to any element with data-toggle="tooltip"
177  * @details this works well with any elemnt that has a title attribute
178  */
179  $(function() {
180  $('[data-toggle="tooltip"]').tooltip();
181  });
182 
183  /**
184  * @brief import image compare viewer
185  * @details this will add a before/after image comparison slider to any element with class="image-compare"
186  * take a look at the options below to customize the slider
187  */
188  const options = {
189  // UI Theme Defaults
190  controlColor: "#FFFFFF",
191  controlShadow: true,
192  addCircle: true,
193  addCircleBlur: true,
194 
195  // Label Defaults
196  showLabels: true,
197  labelOptions: {
198  before: 'Before',
199  after: 'After',
200  onHover: true
201  },
202  // Smoothing
203  smoothing: true,
204  smoothingAmount: 80,
205 
206  // Other options
207  hoverStart: true,
208  verticalMode: false,
209  startingPoint: 50,
210  fluidMode: false
211  };
212  // on each element with class="image-compare", create a new image compare viewer
213  $('.image-compare').each(function() {
214  let view = new ImageCompare(this, options).mount();
215  });
216 
217  // import single image compare viewer
218  // import ImageCompare from "image-compare-viewer";
219  // if you just need a single image compare viewer, you can use this code:
220  // Get your element
221  // const element = document.getElementById("image-compare");
222  // const viewer = new ImageCompare(element).mount();
223 
224 }); // EOF document ready
document ready(function() { $('#navbar').addClass('animated fadeIn slow');function setSticky(domElement, stickTo, offset) { if(domElement) { console.log('domElement:'+domElement);} else { console.error('Unable to setSticky - domElement is null or undefined:'+domElement);alert('Unable to setSticky - domElement is null or undefined:'+domElement);} if(!stickTo) { console.error('Unable to setSticky - stickTo is null or undefined:'+stickTo);alert('Unable to setSticky - stickTo is null or undefined:'+stickTo);} if(!offset) offset=0;$(window).scroll(function() { if($(window).scrollTop() > $(stickTo).outerHeight()) { $('#'+domElement).addClass('fixed-top shadow');var navbar_height=$('.'+domElement).outerHeight();$('body').css('padding-top', navbar_height+ 'px');} else { $('#'+domElement).removeClass('fixed-top');$('body').css('padding-top', 0);} });} setSticky('navbar', '#intro', 0);setSticky('MySidebar', '#intro', 100);$('#subMenu li').click(function(e) { e.preventDefault();var linkObject=$(this).find('a');var href=linkObject.attr('href');var target=linkObject.attr('target');if(href.charAt(0)==='#') { try { $('html, body').velocity('scroll', { offset:$(href).offset().top - 250, duration:2400, easing:'easeOutQuart' });} catch(error) { console.log('Info:Velocity.js is not loaded. Please consider loading velocity.js within the template assets if you want the smoothest scroll experience. Error message:', error.message);$('html, body').animate({ scrollTop:$(href).offset().top - 250 }, 2400);} } else { if(target) { window.open(href, target);} else { window.open(href, '_self');} } });$('.scrollup').click(function() { try{ $("html, body").velocity("scroll", { duration:2400, easing:"easeOutExpo" });} catch { console.log('Error:Velocity.js is not loaded. Please consider loading velocity.js within the assets if you want the smoothest scroll experience. Error message:', error.message);$("html, body").animate({scrollTop:0}, 1200);} });$('#darkMode').click(function() { var id=$('#darkMode').data('id');document.cookie='frontendSwitchID='+id;});$('#lightMode').click(function() { var id=$('#lightMode').data('id');document.cookie='frontendSwitchID='+id;});$(window).scroll(function() { var screenWidth=$(window).width();var scrollTop=$(window).scrollTop();var fadeOutValue=1 -(scrollTop/(screenWidth/3));$(".scrollDownFadeOut").css("opacity", fadeOutValue);});var $scrollingDiv=$("#scrollingDiv");$(window).scroll(function() { $scrollingDiv.stop().animate({"marginTop":($(window).scrollTop())}, 0);});$(".sliding-link").click(function(e) { e.preventDefault();var aid=$(this).attr("href");$('html, body').animate({scrollTop:$(aid).offset().top - 150}, 'slow');window.location.hash=aid;});$(function() { $('[data-toggle="tooltip"]').tooltip();});const options={ controlColor:"#FFFFFF", controlShadow:true, addCircle:true, addCircleBlur:true, showLabels:true, labelOptions:{ before:'Before', after:'After', onHover:true }, smoothing:true, smoothingAmount:80, hoverStart:true, verticalMode:false, startingPoint:50, fluidMode:false };$('.image-compare').each(function() { let view=new ImageCompare(this, options).mount();});})
function window
Definition: fuckAdBlock.js:8
c jPlayer error
function e
Definition: plyr.js:1
if(!isset($template)) if(!isset($user)) $template id