aboutsummaryrefslogtreecommitdiff
path: root/src/client/javascript/favorite.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2017-12-10 00:22:36 +0100
committerNoah Loomans <noahloomans@gmail.com>2017-12-10 00:22:36 +0100
commit503f94199f7fc730da4a1a1165c2863956d10000 (patch)
tree035e47f4a734a6c9b9649e77333ed49dce4ac710 /src/client/javascript/favorite.js
parentf18692872cdc28d29917247ef4f8ef7553a8b023 (diff)
Setup react-redux env
Diffstat (limited to 'src/client/javascript/favorite.js')
-rw-r--r--src/client/javascript/favorite.js79
1 files changed, 0 insertions, 79 deletions
diff --git a/src/client/javascript/favorite.js b/src/client/javascript/favorite.js
deleted file mode 100644
index 92c87f7..0000000
--- a/src/client/javascript/favorite.js
+++ /dev/null
@@ -1,79 +0,0 @@
-/* global USERS */
-
-const EventEmitter = require('events')
-
-const self = new EventEmitter()
-
-self._nodes = {
- toggle: document.querySelector('.fav')
-}
-
-self.get = function () {
- try {
- const localStorageUser = JSON.parse(window.localStorage.getItem('fav'))
- if (localStorageUser == null) return
-
- const correctedUser = USERS.filter(function (user) {
- return user.type === localStorageUser.type &&
- user.value === localStorageUser.value
- })[0]
- return correctedUser
- } catch (e) {
- self.delete()
- return
- }
-}
-
-self.set = function (user) {
- window.localStorage.setItem('fav', JSON.stringify(user))
- self._nodes.innerHTML = '&#xE838;'
-}
-
-self.delete = function () {
- window.localStorage.removeItem('fav')
-}
-
-self.updateDom = function (isFavorite) {
- if (isFavorite) {
- self._nodes.toggle.innerHTML = '&#xE838;'
- } else {
- self._nodes.toggle.innerHTML = '&#xE83A'
- }
-}
-
-self.update = function (selectedUser) {
- const currentUser = self.get()
-
- if (currentUser == null || selectedUser == null) {
- self.updateDom(false)
- return
- }
-
- const isEqual = currentUser.type === selectedUser.type &&
- currentUser.index === selectedUser.index
-
- self.updateDom(isEqual)
-}
-
-self.toggle = function (selectedUser) {
- const currentUser = self.get()
- const isEqual = currentUser != null &&
- currentUser.type === selectedUser.type &&
- currentUser.index === selectedUser.index
-
- if (isEqual) {
- self.delete()
- self.updateDom(false)
- } else {
- self.set(selectedUser)
- self.updateDom(true)
- }
-}
-
-self._handleClick = function () {
- self.emit('click')
-}
-
-self._nodes.toggle.addEventListener('click', self._handleClick)
-
-module.exports = self