aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/main.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2016-09-14 14:32:46 +0200
committerNoah Loomans <noahloomans@gmail.com>2016-09-14 14:32:46 +0200
commit338f38fa94cb5f02069e3475b896b5ffffd38f0e (patch)
tree128a559c275e6518ff9501306522976129bdafe8 /public/javascripts/main.js
parente6c5f98051a2eda2e62e91736633dd0b976b22d6 (diff)
fixed fav icon not updating
Diffstat (limited to 'public/javascripts/main.js')
-rw-r--r--public/javascripts/main.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/public/javascripts/main.js b/public/javascripts/main.js
index d2b60ff..2dc4fe3 100644
--- a/public/javascripts/main.js
+++ b/public/javascripts/main.js
@@ -58,8 +58,13 @@ function changeFav (isFav) {
updateFavNode()
}
+function usersEqual (user1, user2) {
+ if (user1 == null || user2 == null) return false
+ return user1.type === user2.type && user1.index === user2.index
+}
+
function updateFavNode () {
- if (getCurrentFav() === selectedUser) {
+ if (usersEqual(getCurrentFav(), selectedUser)) {
favNode.innerHTML = '&#xE838;'
} else {
favNode.innerHTML = '&#xE83A'
@@ -108,8 +113,8 @@ searchNode.addEventListener('input', function (e) {
searchNode.addEventListener('submit', submitForm)
function submitForm (e) {
- if (results == null) return
if (e) e.preventDefault()
+ if (results == null) return
const indexInResult = selectedResult === -1 ? 0 : selectedResult
selectedUser = users[results[indexInResult].index]
@@ -186,7 +191,7 @@ searchNode.addEventListener('blur', function (e) {
})
favNode.addEventListener('click', function () {
- if (getCurrentFav() === selectedUser) {
+ if (usersEqual(getCurrentFav(), selectedUser)) {
changeFav(false)
} else {
changeFav(true)