Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Declaring constants
  2. // Meant to represent number of items per page
  3. var MAXITEMSPERPAGE = 5;
  4.  
  5. function openTab(evt, tabName) {
  6.     // Declare all variables
  7.     var i, tabcontent, tablinks;
  8.  
  9.     // Get all elements with class="tabcontent" and hide them
  10.     tabcontent = document.getElementsByClassName("tabcontent");
  11.     for (i = 0; i < tabcontent.length; i++) {
  12.         tabcontent[i].style.display = "none";
  13.     }
  14.  
  15.     // Get all elements with class="tablinks" and remove the class "active"
  16.     tablinks = document.getElementsByClassName("tablinks");
  17.     for (i = 0; i < tablinks.length; i++) {
  18.         tablinks[i].className = tablinks[i].className.replace(" active", "");
  19.     }
  20.  
  21.     // Show the current tab, and add an "active" class to the button that opened the tab
  22.     document.getElementById(tabName).style.display = "block";
  23.     evt.currentTarget.className += " active";
  24. }
  25.  
  26.  
  27. // Toggles hamburger-menu
  28. function toggleMenu(){
  29.       $('.hamburger').toggleClass('is-active');
  30.       $('#main-nav').toggleClass('toggled');
  31. }
  32.  
  33. // Scroll to top
  34. $(window).scroll(function() {
  35.     if ($(this).scrollTop() >= 50) {      
  36.         $('.scrollMobile').fadeIn(200);    
  37.     } else {
  38.         $('.scrollMobile').fadeOut(200);  
  39.     }
  40. });
  41.  
  42. $(".scrollMobile").click(function() {
  43.     $('html, body').animate({
  44.         scrollTop: $("#navbar-wrapper").offset().top
  45.     }, ($(document).height() - 800));
  46. });
  47.  
  48. // Display current amount of items in shopping cart
  49. function getAmount() {
  50.     var amount = 0;
  51.     $.each(document.cookie.split(/; */), function()  {
  52.         var splitCookie = this.split('=');
  53.         if (splitCookie[0].length == 36) {
  54.             amount++;
  55.         }
  56.     });
  57.     if (amount > 0) {
  58.         $('#shopping-items').html(amount);
  59.     }
  60.     else {
  61.         $('#shopping-items').html('');
  62.     }
  63. }
  64.  
  65. $(document).ready(function(){
  66.     getAmount();
  67. });
  68.  
  69.  
  70. // Add item to cart
  71. function addItem(){
  72.     var expires;
  73.     var date = new Date();
  74.     date.setDate(date.getDate() + 7);
  75.     expires = "; expires=" + date.toGMTString();
  76.    
  77.     // set cookie
  78.     document.cookie = $('#courseID').html() + "=" +  $('#courseID').html() + expires + "; path=/site/";
  79.  
  80.     showPopup();
  81.     getAmount();
  82. }
  83.  
  84. // Shopping cart popup
  85. function showPopup() {
  86.     $('.pop-up').toggleClass('hidden').fadeIn('slow');
  87.     $('.pop-up').css('opacity', '1');
  88. }
  89.  
  90. // Delete item from cart
  91. function deleteItem(id) {
  92.     document.cookie = id + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/site/;";
  93.     location.reload();
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement