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

m
m
Line 16: Line 16:
 
var stateChange = 0;
 
var stateChange = 0;
 
var wordIncrement = -1 //controls whether the word is being generated or deleted
 
var wordIncrement = -1 //controls whether the word is being generated or deleted
const wordTime = 1000;
+
const wordTime = 1000;  
const changeWordTime = 200;
+
const changeWordTime = 100; //Time to switch letters
//Call word generator functions
+
setTimeout(alterDisplayWord,wordTime); //Set the first time delay
+
updateWord();
+
 
+
function alterDisplayWord(){
+
    if(stateChange == 0){ //if word is in process of being generated
+
        displayWord = wordArray[wordIndex].substring(0,displayWord.length + wordIncrement); //Add or delete a letter
+
        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
+
        }
+
        setTimeout(alterDisplayWord, changeWordTime); //call function again after a delay
+
        updateWord();
+
    }
+
    else{
+
        stateChange = 0;
+
        if(displayWord.length == 0){
+
            if(wordIndex == wordArray.length - 1)
+
                wordIndex = 0;
+
            else
+
                wordIndex++;
+
            wordIncrement = 1; //change to the generating word increment
+
            setTimeout(alterDisplayWord, changeWordTime); //set a short time for the next call of the function
+
        }
+
        else{
+
            wordIncrement = -1;
+
            setTimeout(alterDisplayWord,wordTime);
+
        }
+
    }
+
}
+
 
+
function updateWord(){
+
    document.getElementById("Changing-Text").innerHTML = displayWord;
+
}
+
  
  
Line 158: Line 125:
 
}
 
}
  
 +
//Call word generator functions
 +
setTimeout(alterDisplayWord,wordTime); //Set the first time delay
 +
updateWord();
  
 +
function alterDisplayWord(){
 +
    if(stateChange == 0){ //if word is in process of being generated
 +
        displayWord = wordArray[wordIndex].substring(0,displayWord.length + wordIncrement); //Add or delete a letter
 +
        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
 +
        }
 +
        setTimeout(alterDisplayWord, changeWordTime); //call function again after a delay
 +
        updateWord();
 +
    }
 +
    else{
 +
        stateChange = 0;
 +
        if(displayWord.length == 0){
 +
            if(wordIndex == wordArray.length - 1)
 +
                wordIndex = 0;
 +
            else
 +
                wordIndex++;
 +
            wordIncrement = 1; //change to the generating word increment
 +
            setTimeout(alterDisplayWord, changeWordTime); //set a short time for the next call of the function
 +
        }
 +
        else{
 +
            wordIncrement = -1;
 +
            setTimeout(alterDisplayWord,wordTime);
 +
        }
 +
    }
 +
}
 +
 +
function updateWord(){
 +
    document.getElementById("Changing-Text").innerHTML = displayWord;
 +
}
  
  

Revision as of 16:00, 10 July 2020