Update
This commit is contained in:
parent
3515603e93
commit
e803d25a37
|
@ -38,7 +38,6 @@ export function px2rem(px) {
|
|||
*
|
||||
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
|
||||
*/
|
||||
|
||||
export function getTextWidth(text, font) {
|
||||
// re-use canvas object for better performance
|
||||
const canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
||||
|
@ -109,4 +108,11 @@ export function validatePosNumber(event,input,callback,max) {
|
|||
else {
|
||||
callback(input.value)
|
||||
}
|
||||
}
|
||||
|
||||
export function shuffleArray(array) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
}
|
|
@ -92,10 +92,10 @@ export function loadLocaleContent(content,componentName,loaded,callback) {
|
|||
}
|
||||
}
|
||||
getData("/locales/" + locale + "/" + componentName + ".json" ,function(response) {
|
||||
if (callback!=undefined) {
|
||||
callback(locale)
|
||||
}
|
||||
let parsed = JSON.parse(response)
|
||||
if (callback!=undefined) {
|
||||
callback(parsed)
|
||||
}
|
||||
content.set(parsed)
|
||||
loaded = 1
|
||||
})
|
||||
|
|
|
@ -5,13 +5,14 @@
|
|||
import { onMount } from 'svelte'
|
||||
import { writable } from 'svelte/store';
|
||||
import { loadLocaleContent } from "/js/libraries/serverTools.js"
|
||||
import { shuffleArray } from "/js/libraries/miscTools.js"
|
||||
|
||||
// Import components
|
||||
|
||||
// Main code
|
||||
let loaded
|
||||
let content = writable({})
|
||||
let locale = loadLocaleContent(content,"compass-component",loaded)
|
||||
let locale = loadLocaleContent(content,"compass-component",loaded,contentCallback)
|
||||
|
||||
let qTag = 0
|
||||
let answers = []
|
||||
|
@ -20,6 +21,12 @@
|
|||
let vanguardismScore = ""
|
||||
let socialismScore = ""
|
||||
|
||||
function contentCallback(content) {
|
||||
for (let q of content.qs) {
|
||||
shuffleArray(q.as)
|
||||
}
|
||||
}
|
||||
|
||||
function next(i) {
|
||||
if (answers[i]!=undefined) {
|
||||
if (qTag < $content.qs.length) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -38,7 +38,6 @@ export function px2rem(px) {
|
|||
*
|
||||
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
|
||||
*/
|
||||
|
||||
export function getTextWidth(text, font) {
|
||||
// re-use canvas object for better performance
|
||||
const canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
||||
|
@ -109,4 +108,11 @@ export function validatePosNumber(event,input,callback,max) {
|
|||
else {
|
||||
callback(input.value)
|
||||
}
|
||||
}
|
||||
|
||||
export function shuffleArray(array) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
}
|
|
@ -92,10 +92,10 @@ export function loadLocaleContent(content,componentName,loaded,callback) {
|
|||
}
|
||||
}
|
||||
getData("/locales/" + locale + "/" + componentName + ".json" ,function(response) {
|
||||
if (callback!=undefined) {
|
||||
callback(locale)
|
||||
}
|
||||
let parsed = JSON.parse(response)
|
||||
if (callback!=undefined) {
|
||||
callback(parsed)
|
||||
}
|
||||
content.set(parsed)
|
||||
loaded = 1
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue