aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/main.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2016-12-06 16:14:27 +0100
committerNoah Loomans <noahloomans@gmail.com>2016-12-06 16:14:27 +0100
commit309781965eb9fbc6e035bbe7a774f2a90f021c52 (patch)
treeabe0c1de1075642a2bcdaf0e6b6a3b4d8923d8a7 /public/javascripts/main.js
parent54b9362d9548c8137d242fe5d30b3b0bbea72189 (diff)
optimized file size
Diffstat (limited to 'public/javascripts/main.js')
-rw-r--r--public/javascripts/main.js26
1 files changed, 4 insertions, 22 deletions
diff --git a/public/javascripts/main.js b/public/javascripts/main.js
index 31645e8..a1e7dcf 100644
--- a/public/javascripts/main.js
+++ b/public/javascripts/main.js
@@ -1,4 +1,4 @@
-/* global ga FLAGS */
+/* global ga FLAGS USERS */
require('flexibility')
@@ -36,28 +36,10 @@ let selectedUser
let results = []
let offset = 0
-function getUsers () {
- const nodes = document.querySelector('#data')
- .querySelectorAll('.data-user')
- const elements = Array.prototype.slice.call(nodes)
- const users = elements.map(userNode => {
- const type = userNode.querySelector('.data-type').textContent
- const value = userNode.querySelector('.data-value').textContent
- const index = Number(userNode.querySelector('.data-index').textContent)
- return { type, value, index }
- })
-
- document.querySelector('#data').outerHTML = ''
-
- return users
-}
-
-const users = getUsers()
-
function getCurrentFav () {
if (!window.localStorage.getItem('fav')) return
const favCode = window.localStorage.getItem('fav').split(':')
- const fav = users.filter(user => user.type === favCode[0] && user.index === Number(favCode[1]))
+ const fav = USERS.filter(user => user.type === favCode[0] && user.index === Number(favCode[1]))
return fav[0]
}
@@ -112,7 +94,7 @@ searchNode.addEventListener('input', function (e) {
if (inputNode.value.trim() === '') return
selectedResult = -1
- results = fuzzy.filter(removeDiacritics(inputNode.value), users, {
+ results = fuzzy.filter(removeDiacritics(inputNode.value), USERS, {
extract: function (el) { return removeDiacritics(el.value) }
}).slice(0, 7)
@@ -129,7 +111,7 @@ function submitForm (e) {
if (e) e.preventDefault()
if (results.length !== 0) {
const indexInResult = selectedResult === -1 ? 0 : selectedResult
- selectedUser = users[results[indexInResult].index]
+ selectedUser = USERS[results[indexInResult].index]
}
if (selectedUser == null) return