Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var clickOnce = false;
  2. var intervalID;
  3.  
  4. $(function() {
  5.     var quote_index = getUrlParameter('quote');
  6.     if(quote_index) {
  7.         alert("Quote ID is " + quote_index);
  8.     } else {
  9.         startQuote();
  10.     }
  11. });
  12.  
  13. function startQuote() {
  14.     if(clickOnce) {
  15.         intervalID = setInterval(function() {
  16.             var tempIndex = Math.floor(Math.random()*quotes.length);
  17.             document.getElementById("trump").innerHTML = quotes[tempIndex].body;
  18.             document.getElementById("dateObj").innerHTML = quotes[tempIndex].date;
  19.             document.getElementById("dateObj").setAttribute('href', quotes[tempIndex].source);
  20.         }, 1000);  
  21.         clickOnce = false;
  22.     }
  23. }
  24.  
  25. function stopQuote() {
  26.     if(!clickOnce) {
  27.         clearInterval(intervalID);
  28.         clickOnce = true;
  29.         history.pushState({}, document.title, newURL);
  30.     }
  31. }
  32.  
  33. var getUrlParameter = function getUrlParameter(sParam) {
  34.     var sPageURL = decodeURIComponent(window.location.search.substring(1)),
  35.         sURLVariables = sPageURL.split('&'),
  36.         sParameterName,
  37.         i;
  38.  
  39.     for (i = 0; i < sURLVariables.length; i++) {
  40.         sParameterName = sURLVariables[i].split('=');
  41.         if (sParameterName[0] === sParam) {
  42.             return sParameterName[1] === undefined ? true : sParameterName[1];
  43.         }
  44.     }
  45. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement