Difference between revisions of "Template:Queens Canada/Scripts"

m
m
Line 11: Line 11:
 
var foodItems = document.getElementsByClassName("food-item-inner");
 
var foodItems = document.getElementsByClassName("food-item-inner");
 
var navBtn = document.getElementById("nav-icon");
 
var navBtn = document.getElementById("nav-icon");
 +
var wordArray = ["Humans", "Scientists", "Researchers", "Engineers", "Designers"]
 +
var wordIndex = 0; //Start at first word in wordArray
 +
var displayWord = wordArray[wordIndex];
 +
var stateChange = 0;
 +
var wordIncrement = -1 //controls whether the word is being generated or deleted
 +
const wordTime = 2000;
 +
const changeWordTime = 250;
 +
  
 
$(document).ready(function(){
 
$(document).ready(function(){
Line 117: Line 125:
 
}
 
}
  
//Word generator script
+
//Call word generator functions
var wordArray = ["Humans","Scientists", "Engineers", "Designers"]; // Create Array with buzzwords
+
setTimeout(alterDisplayWord,wordTime); //Set the first time delay
var wordIndex = 0; // Start at the first word in the array
+
updateWord();
var displayWord = wordArray[wordIndex]; // display the first word
+
var stateChange = 0;
+
var wordIncrement = -1; // variable that controls wether the word is being generated or deleted
+
const wordTime = 2000;
+
const changeWordTime = 250;
+
//setTimeout(alterDisplayWord,wordTime); // Set the first time delay
+
//updateWord(); // set the display word in the span element
+
 
+
  
/*
 
    Generates or deletes the display word letter by letter depending on the state.
 
*/
 
 
function alterDisplayWord(){
 
function alterDisplayWord(){
     if(stateChange == 0){ // if the word is in the process of being deleted or generated
+
     if(stateChange == 0){ //if word is in process of being generated
+
         displayWord = wordArray[wordIndex].substring(0,displayWord.length + wordIncrement); //Add or delete a letter
         displayWord = wordArray[wordIndex].substring(0,displayWord.length+wordIncrement); // add a letter or delete a letter from the display word
+
         if(wordArray[wordIndex] == displayWord || displayWord.length ==0){ //if word is fully generated or deleted
          
+
             stateChange = 1; //let next function call know about the change in state
if(wordArray[wordIndex] == displayWord || displayWord.length == 0){ // if the word is fully generated or fully deleted
+
             stateChange = 1; // let the next function call know about the change in state
+
 
         }
 
         }
+
         setTimeout(alterDisplayWord, changeWordTime); //call function again after a delay
         setTimeout(alterDisplayWord,changeWordTime);// call the function again after a delay and update the display word on the website
+
 
         updateWord();
 
         updateWord();
 
     }
 
     }
     else{ // if the word has been fully deleted or generated
+
     else{
          
+
         stateChange = 0;
stateChange = 0;
+
         if(displayWord.length == 0){
          
+
             if(wordIndex == wordArray.length - 1)
if(displayWord.length == 0){ // if there is no word being displayed (this means that a word was just deleted)
+
                wordIndex = 0;
           
+
            // move to the next word
+
             if(wordIndex == wordArray.length-1)
+
    wordIndex = 0;
+
 
             else
 
             else
 
                 wordIndex++;
 
                 wordIndex++;
           
+
             wordIncrement = 1; //change to the generating word increment
             wordIncrement = 1; // change to the generating word increment
+
             setTimeout(alterDisplayWord, changeWordTime); //set a short time for the next call of the function
             setTimeout(alterDisplayWord,changeWordTime); // set a short time for the next call of the function
+
         }
          
+
         else{
}
+
             wordIncrement = -1;
         else{ // when the word has been fully generated
+
             setTimeout(alterDisplayWord,wordTime);
              
+
         }
wordIncrement = -1; // change to the deleting state
+
             setTimeout(alterDisplayWord,wordTime); // display the word for a longer time before calling the function again
+
          
+
}
+
 
     }
 
     }
 
}
 
}
  
 
function updateWord(){
 
function updateWord(){
 
 
     document.getElementById("Changing-Text").innerHTML = displayWord;
 
     document.getElementById("Changing-Text").innerHTML = displayWord;
 
 
}
 
}
  
 
</script>
 
</script>
 
</html>
 
</html>

Revision as of 15:53, 10 July 2020