diff --git a/Code/Jose/javascript/lab05/app.py b/Code/Jose/javascript/lab05/app.py new file mode 100644 index 00000000..c6a8cd77 --- /dev/null +++ b/Code/Jose/javascript/lab05/app.py @@ -0,0 +1,8 @@ +from flask import Flask, render_template, request +app = Flask(__name__) + +@app.route('/') +def index(): + return render_template('index.html') + +app.run(debug = True) \ No newline at end of file diff --git a/Code/Jose/javascript/lab05/static/index.css b/Code/Jose/javascript/lab05/static/index.css new file mode 100644 index 00000000..e69de29b diff --git a/Code/Jose/javascript/lab05/static/js/index.js b/Code/Jose/javascript/lab05/static/js/index.js new file mode 100644 index 00000000..ee90aded --- /dev/null +++ b/Code/Jose/javascript/lab05/static/js/index.js @@ -0,0 +1,80 @@ +let requestedinputText, searchButton, previousPageButton, nextPageButton, +quoteText, quoteAuthor, quoteDiv, quoteDivAuthor, userSearch, pageNumber + +searchButton = document.querySelector('#searchButton'); +previousPageButton = document.querySelector('#previousPageButton'); +nextPageButton = document.querySelector('#nextPageButton'); +resultText = document.querySelector('#resultText'); +resultAuthor = document.querySelector('#resultAuthor'); + +quoteNumber = 0; +pageNumber = 1; + +let url = `https://favqs.com/api/quotes?page=${pageNumber}&filter=${requestedinputText}` + +const headers = { + Accept: 'application/json', + Authorization: `Token token=${FAVQS_API_KEY}` +} + + + +function fetchQuoteData() { + requestedinputText = document.querySelector('#searchInput').value; + + fetch(`https://favqs.com/api/quotes?page=${pageNumber}&filter=${requestedinputText}`, {headers}) + .then((response) => response.json()) + .then((data) => { + author = data.quotes[quoteNumber].author; + quoteText = data.quotes[quoteNumber].body; + resultText.innerHTML = quoteText; + resultAuthor.innerHTML = author; + amountofReturnedQuotes = data.quotes.length + // Saving the data in a variable to use outside this scope + returnedQuotes = data + //console.log(returnedQuotes) + //console.log(amountofReturnedQuotes) + }) +} + +function nextPage() { + if (quoteNumber < amountofReturnedQuotes-1){ + quoteNumber++ + author = returnedQuotes.quotes[quoteNumber].author; + quoteText = returnedQuotes.quotes[quoteNumber].body; + resultText.innerHTML = quoteText; + resultAuthor.innerHTML = author; + } else { + alert("You've reached the end of the quotes!") + } +} + +function previousPage() { + if (quoteNumber > 0) { + quoteNumber-- + author = returnedQuotes.quotes[quoteNumber].author; + quoteText = returnedQuotes.quotes[quoteNumber].body; + resultText.innerHTML = quoteText; + resultAuthor.innerHTML = author; + } else { + alert('This is the beginning of the quotes!') + } +} + + +searchButton.onclick = function(){ + fetchQuoteData() +} + +nextPageButton.onclick = function(){ + nextPage() +} + +previousPageButton.onclick = function(){ + previousPage() +} + +//quoteText = data.quote.body; +//quoteAuthor = data.quote.author; +//resultText.innerHTML = quoteText; +//resultAuthor.innerHTML = quoteAuthor; \ No newline at end of file diff --git a/Code/Jose/javascript/lab05/static/styles/mainpage.css b/Code/Jose/javascript/lab05/static/styles/mainpage.css new file mode 100644 index 00000000..a460a5e7 --- /dev/null +++ b/Code/Jose/javascript/lab05/static/styles/mainpage.css @@ -0,0 +1,52 @@ +body { + background-color: #8fbc8f; + font-family: sans-serif; +} + +.instructions{ + display: flex; + margin-top: 15%; + justify-content: center; + +} + +.instruction-text { + font-size: 3rem; + font-weight: 600; +} + +.btn { + justify-content: center; + text-align: center; + color: black; + font-weight: 700; + margin-top: 15px; +} + +.row { + margin-left: 45%; + width: 10% +} + +.quoteDiv { + display: flex; + margin-top: 5%; + justify-content: center; + width: 50%; + margin-left: 25%; + margin-bottom: -5%; + background-color: seagreen; + border-radius: 10px; + font-size: 1.5rem; + font-weight: 600; + color: darkslategrey; + padding-left: 5%; + padding-right: 5%; +} + +.searchBar { + display: flex; + margin-left: 25%; + width: 50%; +} + diff --git a/Code/Jose/javascript/lab05/templates/index.html b/Code/Jose/javascript/lab05/templates/index.html new file mode 100644 index 00000000..a8807e81 --- /dev/null +++ b/Code/Jose/javascript/lab05/templates/index.html @@ -0,0 +1,41 @@ + + + + + + + + + + Random Quote + + +
+

Enter text for a quote.

+
+ + + +
+ + + +
+ + +
+

(your quote will appear here)

+
+
+

+

(this is the author's name!)

+
+ + + + + \ No newline at end of file