commit 5bea3d43c149e539fea1017270b2417076857262
parent 4420dffb6136799d74c5dbaf6256ad876a0d5543
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date: Thu, 17 Sep 2020 08:21:02 -0700
Add JSDoc documentation.
Diffstat:
5 files changed, 160 insertions(+), 20 deletions(-)
diff --git a/Scripts/Home.js b/Scripts/Home.js
@@ -1,9 +1,12 @@
// Declare global variables
let Sets; // List of parsed sets
-let quizzerType = null; // Type of quizzer
let app;
+
+/**
+ * Initialize the Vue app
+ */
function loadVue() {
app = new Vue({
el: "#app", // Mount to app div
@@ -23,6 +26,9 @@ function loadVue() {
},
methods: {
+ /**
+ * Return to the previous state.
+ */
Back: function() {
switch (app.state) {
case "verbQuizzer":
@@ -39,20 +45,44 @@ function loadVue() {
break;
}
},
+
+ /**
+ * Add a verb filter on the settings page.
+ */
AddVerbFilter: function() {
this.verbFilters.push({"tense":"All Tenses", "type":"All Types"});
},
+
+ /**
+ * Remove a verb filter from the settings page.
+ * @param {Number} index - The index of the verb filter.
+ */
RemoveVerbFilter: function(index) {
// Remove filter
this.verbFilters.splice(index, 1);
},
+
+ /**
+ * Add a vocab filter on the settings page.
+ */
AddVocabFilter: function() {
this.vocabFilters.push({"set":"Verbs", "type":"All Definitions"});
},
+
+ /**
+ * Remove a vocab filter from the settings page.
+ * @param {Number} index - The index of the vocab filter.
+ */
RemoveVocabFilter: function(index) {
// Remove filter
this.vocabFilters.splice(index, 1);
},
+
+ /**
+ * Get the regularity filters available for a verb filter.
+ * @param {Number} index - The index of the verb filter.
+ * @returns {object} - An object with boolean properties for each regularity filter.
+ */
getTenseTypes: function(index) {
// Get filter options
let filters = {"All Types":true, "Reflexive":true, "Regular":true, "Nonregular":true, "Stem Changing":true, "Orthographic":true, "Irregular":true}
@@ -83,6 +113,12 @@ function loadVue() {
// Return filters
return filters;
},
+
+ /**
+ * Get the filters available for a vocab Set.
+ * @param {Number} index - The index of the vocab filter.
+ * @returns {Array} - An array containing available filters.
+ */
getSetFilters: function(index) {
// Get filter options
var filters = [];
@@ -133,6 +169,12 @@ function loadVue() {
// Return filters
return filters;
},
+
+ /**
+ * Get the language code that matches a label.
+ * @param {String} label - The label.
+ * @returns {String} - The language code ("en", "es", etc.)
+ */
getLang: function(label) {
if (label.toLowerCase().includes("spanish")) {
return "es";
@@ -141,6 +183,12 @@ function loadVue() {
return "en";
}
},
+
+ /**
+ * Update the user's progress in localStorage.
+ * @param {Array} prompts - The list of prompts.
+ * @param {Number} index - The index of the current prompt.
+ */
updateProgress: function(prompts, index) {
// Get localStorage prefix
let prefix;
@@ -161,6 +209,9 @@ function loadVue() {
},
watch: {
+ /**
+ * Update the app theme.
+ */
darkTheme: function() {
// Get theme from localStorage if null
if (this.darkTheme === null) {
@@ -183,22 +234,40 @@ function loadVue() {
// Save theme
localStorage.setItem("darkTheme", this.darkTheme);
},
+
+ /**
+ * Update the promptType setting in localStorage.
+ * @param {String} value - The prompt type.
+ */
promptType: function(value) {
localStorage.setItem("promptType", value);
},
+
+ /**
+ * Update the inputType setting in localStorage.
+ * @param {String} value - The input type.
+ */
inputType: function(value) {
localStorage.setItem("inputType", value);
},
+
+ /**
+ * Update the repeatPrompts setting in localStorage.
+ * @param {String} value - The repeat prompts setting value.
+ */
repeatPrompts: function(value) {
localStorage.setItem("repeatPrompts", value);
},
+
+ /**
+ * Clear the error message when the state changes.
+ */
state: function() {
// Reset error message
app.errorMsg = "";
}
},
- // Called when the Vue is created
created: function() {
// Force theme to update
this.darkTheme = null;
@@ -208,8 +277,11 @@ function loadVue() {
-// Load the document
+/**
+ * Load the document.
+ */
function Load() {
+ // Initialize the Vue app
loadVue();
// Unhide hidden divs
@@ -243,7 +315,10 @@ function Load() {
-// Handles keyDown events (implements some keyboard shortcuts)
+/**
+ * Handle a keyDown event (implements some keyboard shortcuts).
+ * @param {object} e - The event args.
+ */
function KeyDown(e) {
if (e.key === "Escape") {
app.Back();
diff --git a/Scripts/Offline.js b/Scripts/Offline.js
@@ -3,7 +3,9 @@ let app;
-// Load the document
+/**
+ * Load the document.
+ */
function Load() {
// Initialize Vue
app = new Vue({
@@ -14,6 +16,9 @@ function Load() {
},
watch: {
+ /**
+ * Update the app theme.
+ */
darkTheme: function() {
// Get theme from localStorage if null
if (this.darkTheme === null) {
diff --git a/Scripts/Quizzer.js b/Scripts/Quizzer.js
@@ -41,6 +41,10 @@ let quizzer = Vue.component("quizzer", {
},
watch: {
+ /**
+ * Activates/deactivates the quizzer.
+ * @param {Boolean} value - The boolean value.
+ */
active: function(value) {
if (value) {
// Update prompts
@@ -54,7 +58,9 @@ let quizzer = Vue.component("quizzer", {
},
methods: {
- // Give the user a new prompt
+ /**
+ * Give the user the next prompt and reset the quizzer.
+ */
Reset: function() {
// Check is Quizzer is active
if (!this.active) {
@@ -117,7 +123,9 @@ let quizzer = Vue.component("quizzer", {
}
},
- // Processes a user's submitted responce
+ /**
+ * Process the user's responce.
+ */
Submit: function() {
// Check is Quizzer is active
if (!this.active) {
@@ -171,7 +179,9 @@ let quizzer = Vue.component("quizzer", {
}
},
- // Processes an incorrect responce and then resets the quizzer
+ /**
+ * Process an incorrect responce and then reset the quizzer.
+ */
Continue: function() {
// Check is Quizzer is active
if (!this.active) {
@@ -208,7 +218,9 @@ let quizzer = Vue.component("quizzer", {
this.Reset();
},
- // Called when the user hits enter or presses the enter button
+ /**
+ * Calls Submit or Continue depending on the value of responceActive.
+ */
Enter: function() {
// Check is Quizzer is active
if (!this.active) {
@@ -223,6 +235,11 @@ let quizzer = Vue.component("quizzer", {
}
},
+ /**
+ * Get the language code that matches a label.
+ * @param {String} label - The label.
+ * @returns {String} - The language code ("en", "es", etc.)
+ */
getLang: function(label) {
if (label.toLowerCase().includes("spanish")) {
return "es";
@@ -234,6 +251,10 @@ let quizzer = Vue.component("quizzer", {
},
computed: {
+ /**
+ * Get The current prompt.
+ * @returns {Array} - The current prompt.
+ */
prompt: function() {
if (this.index < this.prompts.length) {
return this.prompts[this.index];
@@ -277,7 +298,11 @@ let quizzer = Vue.component("quizzer", {
-// Reads a peice of text
+/**
+ * Read a peice of text.
+ * @param {String} text - The text to read.
+ * @param {String} label - The language of the text.
+ */
function Read(text, label)
{
var msg = new SpeechSynthesisUtterance(text);
diff --git a/Scripts/Reference.js b/Scripts/Reference.js
@@ -3,7 +3,9 @@ let app;
-// Initializes the Vue
+/**
+ * Initializes the Vue app
+ */
function loadVue() {
app = new Vue({
el: "#app", // Mount to app div
@@ -16,6 +18,11 @@ function loadVue() {
},
methods: {
+ /**
+ * Get the language code that matches a label.
+ * @param {String} label - The label.
+ * @returns {String} - The language code ("en", "es", etc.)
+ */
getLang: function(label) {
if (label.toLowerCase().includes("spanish")) {
return "es";
@@ -27,6 +34,9 @@ function loadVue() {
},
watch: {
+ /**
+ * Update the app theme.
+ */
darkTheme: function() {
// Get theme from localStorage if null
if (this.darkTheme === null) {
@@ -55,7 +65,9 @@ function loadVue() {
-// Load the document
+/**
+ * Load the document
+ */
function Load() {
// Initialize the Vue
loadVue();
@@ -96,7 +108,9 @@ function Load() {
-// Set table height
+/**
+ * Set the table height.
+ */
function setTableHeight() {
var tableY = document.getElementById("referenceTable").offsetTop;
document.getElementById("referenceTable").style.height = `${window.innerHeight - tableY - 50}px`;
@@ -104,7 +118,11 @@ function setTableHeight() {
-// Reads a vocab word
+/**
+ * Read a term.
+ * @param {Number} row - The row of the term.
+ * @param {Number} column - The column of the term.
+ */
function Read(row, column)
{
var msg = new SpeechSynthesisUtterance(app.sets[app.set][row][column]);
diff --git a/Scripts/Settings.js b/Scripts/Settings.js
@@ -1,4 +1,6 @@
-// Start a new session
+/**
+ * Start a new quizzer session
+ */
function CreateSession() {
// Get prompts
if (app.state == "vocabSettings") {
@@ -41,7 +43,9 @@ function CreateSession() {
-// Resume the previous session
+/**
+ * Resume the previous quizzer session.
+ */
function ResumeSession() {
// Get localStorage prefix
let prefix;
@@ -80,7 +84,9 @@ function ResumeSession() {
-// Performs validations and then starts the quizzer
+/**
+ * Perform validation checks and then start the quizzer.
+ */
function StartSession() {
// Validate prompts and promptIndex
if (!app.prompts) {
@@ -124,7 +130,11 @@ function StartSession() {
-// Filters a vocabulary set given the filter name
+/**
+ * Filter a vocab set.
+ * @param {Array} vocabSet - The vocab set to filter.
+ * @param {String} name - The name of the filter.
+ */
function ApplyVocabFilter(vocabSet, name) {
// Declare variables
var io; // Format: [[<output index>, <input index>]]
@@ -208,7 +218,11 @@ function ApplyVocabFilter(vocabSet, name) {
-// Filters verbs set given the filter information
+/**
+ * Filter verb conjugations.
+ * @param {Array} terms - The list of verb conjugations to filter.
+ * @param {Array} filterInfo - A list of filters,
+ */
function ApplyVerbFilter(terms, filterInfo) {
// Create filters
let filters = []; // Format: [{outputIndex:0, inputIndex:0, filterIndex:0, filterValue:"regex"}]
@@ -313,7 +327,10 @@ function ApplyVerbFilter(terms, filterInfo) {
-// Shuffles a list of items
+/**
+ * Shuffles an array of items.
+ * @param {Array} items - The array.
+ */
function Shuffle(items) {
// Initialize variables
var currentIndex = items.length;