diff --git a/Server/app/svelte/public/js/libraries/miscTools.js b/Server/app/svelte/public/js/libraries/miscTools.js index bae2244..7581711 100644 --- a/Server/app/svelte/public/js/libraries/miscTools.js +++ b/Server/app/svelte/public/js/libraries/miscTools.js @@ -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]]; + } } \ No newline at end of file diff --git a/Server/app/svelte/public/js/libraries/serverTools.js b/Server/app/svelte/public/js/libraries/serverTools.js index 274a8f8..9977c48 100644 --- a/Server/app/svelte/public/js/libraries/serverTools.js +++ b/Server/app/svelte/public/js/libraries/serverTools.js @@ -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 }) diff --git a/Server/app/svelte/src/compass-component.svelte b/Server/app/svelte/src/compass-component.svelte index 119ba04..a8de0b6 100644 --- a/Server/app/svelte/src/compass-component.svelte +++ b/Server/app/svelte/src/compass-component.svelte @@ -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) { diff --git a/Server/public/js/components/compass-component.js b/Server/public/js/components/compass-component.js index c9cefec..8452d79 100644 --- a/Server/public/js/components/compass-component.js +++ b/Server/public/js/components/compass-component.js @@ -1 +1 @@ -import{S as t,i as n,a as e,b as i,s as o,e as s,n as r,d as a,c as l,o as m,f as c,t as u,g as p,h as d,j as g,l as h,m as f,q as b,p as v,r as x}from"./index-4348483d.js";import{w as q}from"./index-71440b21.js";import{loadLocaleContent as _}from"../../../../../../../../../js/libraries/serverTools.js";function y(t,n,e){const i=t.slice();return i[17]=n[e],i[19]=e,i}function z(t){let n,e,s,r,l,m,b,v,x=t[5].heading+"",q=t[0],_=C(t);return{c(){n=c("div"),e=c("div"),s=c("h1"),r=u(x),l=p(),m=c("img"),v=p(),_.c(),d(m,"id","compass-img"),g(m.src,b="/img/common/compass.svg")||d(m,"src","/img/common/compass.svg"),d(m,"alt","compass"),d(e,"id","text-container"),d(n,"id","container")},m(t,o){i(t,n,o),h(n,e),h(e,s),h(s,r),h(e,l),h(e,m),h(e,v),_.m(e,null)},p(t,n){32&n&&x!==(x=t[5].heading+"")&&f(r,x),1&n&&o(q,q=t[0])?(_.d(1),_=C(t),_.c(),_.m(e,null)):_.p(t,n)},d(t){t&&a(n),_.d(t)}}}function k(t){let n,e,o,s,r,l,m,g,v,x,q,_,y,z,k,w,j,C,S,B,M,O,D,E;return{c(){n=c("p"),n.textContent="You are compatible with ...",e=p(),o=c("ul"),s=c("li"),r=u("capitalism by "),l=c("span"),m=u(t[2]),g=u("%"),v=p(),x=c("li"),q=u("vanguardism by "),_=c("span"),y=u(t[3]),z=u("%"),k=p(),w=c("li"),j=u("libertarian socialism by "),C=c("span"),S=u(t[4]),B=u("%"),M=p(),O=c("button"),O.textContent="back",d(o,"class","results-list"),d(O,"class","quiz-buttons")},m(a,c){i(a,n,c),i(a,e,c),i(a,o,c),h(o,s),h(s,r),h(s,l),h(l,m),h(s,g),h(o,v),h(o,x),h(x,q),h(x,_),h(_,y),h(x,z),h(o,k),h(o,w),h(w,j),h(w,C),h(C,S),h(w,B),i(a,M,c),i(a,O,c),D||(E=b(O,"click",t[15]),D=!0)},p(t,n){4&n&&f(m,t[2]),8&n&&f(y,t[3]),16&n&&f(S,t[4])},d(t){t&&a(n),t&&a(e),t&&a(o),t&&a(M),t&&a(O),D=!1,E()}}}function w(t){let n,e,o,s,r,l,m,g,q,_=t[5].qs[t[0]].q+"",z=t[5].qs[t[0]].as,k=[];for(let n=0;ne(5,i=t))),_(s,"compass-component",o);let r=0,a=[],c="",u="",p="";function d(t){null!=a[t]&&rt.includes("C"))).filter(Boolean).length/a.length).toString()),e(3,u=Math.round(100*a.map((t=>t.includes("V"))).filter(Boolean).length/a.length).toString()),e(4,p=Math.round(100*a.map((t=>t.includes("LS"))).filter(Boolean).length/a.length).toString())),e(0,r+=1))}function g(t){0!=r&&e(0,r-=1)}m((()=>{}));return[r,a,c,u,p,i,o,s,d,g,function(){a[r]=this.__value,e(1,a)},[[]],t=>e(1,a[r]=t[1],a),()=>g(),()=>d(r),()=>g()]}class M extends t{constructor(t){super(),this.shadowRoot.innerHTML="",n(this,{target:this.shadowRoot,props:e(this.attributes),customElement:!0},B,S,o,{},null),t&&t.target&&i(t.target,this,t.anchor)}}customElements.define("compass-component",M);export{M as default}; +import{S as t,i as n,a as e,b as i,s as o,e as s,n as r,d as a,c as l,o as m,f as c,t as u,g as p,h as d,j as g,l as h,m as f,q as b,p as v,r as q}from"./index-4348483d.js";import{w as x}from"./index-71440b21.js";import{loadLocaleContent as _}from"../../../../../../../../../js/libraries/serverTools.js";import{shuffleArray as y}from"../../../../../../../../../js/libraries/miscTools.js";function z(t,n,e){const i=t.slice();return i[18]=n[e],i[20]=e,i}function k(t){let n,e,s,r,l,m,b,v,q=t[5].heading+"",x=t[0],_=S(t);return{c(){n=c("div"),e=c("div"),s=c("h1"),r=u(q),l=p(),m=c("img"),v=p(),_.c(),d(m,"id","compass-img"),g(m.src,b="/img/common/compass.svg")||d(m,"src","/img/common/compass.svg"),d(m,"alt","compass"),d(e,"id","text-container"),d(n,"id","container")},m(t,o){i(t,n,o),h(n,e),h(e,s),h(s,r),h(e,l),h(e,m),h(e,v),_.m(e,null)},p(t,n){32&n&&q!==(q=t[5].heading+"")&&f(r,q),1&n&&o(x,x=t[0])?(_.d(1),_=S(t),_.c(),_.m(e,null)):_.p(t,n)},d(t){t&&a(n),_.d(t)}}}function w(t){let n,e,o,s,r,l,m,g,v,q,x,_,y,z,k,w,j,C,S,B,M,O,T,D;return{c(){n=c("p"),n.textContent="You are compatible with ...",e=p(),o=c("ul"),s=c("li"),r=u("capitalism by "),l=c("span"),m=u(t[2]),g=u("%"),v=p(),q=c("li"),x=u("vanguardism by "),_=c("span"),y=u(t[3]),z=u("%"),k=p(),w=c("li"),j=u("libertarian socialism by "),C=c("span"),S=u(t[4]),B=u("%"),M=p(),O=c("button"),O.textContent="back",d(o,"class","results-list"),d(O,"class","quiz-buttons")},m(a,c){i(a,n,c),i(a,e,c),i(a,o,c),h(o,s),h(s,r),h(s,l),h(l,m),h(s,g),h(o,v),h(o,q),h(q,x),h(q,_),h(_,y),h(q,z),h(o,k),h(o,w),h(w,j),h(w,C),h(C,S),h(w,B),i(a,M,c),i(a,O,c),T||(D=b(O,"click",t[15]),T=!0)},p(t,n){4&n&&f(m,t[2]),8&n&&f(y,t[3]),16&n&&f(S,t[4])},d(t){t&&a(n),t&&a(e),t&&a(o),t&&a(M),t&&a(O),T=!1,D()}}}function j(t){let n,e,o,s,r,l,m,g,x,_=t[5].qs[t[0]].q+"",y=t[5].qs[t[0]].as,k=[];for(let n=0;ne(5,i=t))),_(s,"compass-component",o,(function(t){for(let n of t.qs)y(n.as)}));let r=0,a=[],c="",u="",p="";function d(t){null!=a[t]&&rt.includes("C"))).filter(Boolean).length/a.length).toString()),e(3,u=Math.round(100*a.map((t=>t.includes("V"))).filter(Boolean).length/a.length).toString()),e(4,p=Math.round(100*a.map((t=>t.includes("LS"))).filter(Boolean).length/a.length).toString())),e(0,r+=1))}function g(t){0!=r&&e(0,r-=1)}m((()=>{}));return[r,a,c,u,p,i,o,s,d,g,function(){a[r]=this.__value,e(1,a)},[[]],t=>e(1,a[r]=t[1],a),()=>g(),()=>d(r),()=>g()]}class O extends t{constructor(t){super(),this.shadowRoot.innerHTML="",n(this,{target:this.shadowRoot,props:e(this.attributes),customElement:!0},M,B,o,{},null),t&&t.target&&i(t.target,this,t.anchor)}}customElements.define("compass-component",O);export{O as default}; diff --git a/Server/public/js/libraries/miscTools.js b/Server/public/js/libraries/miscTools.js index bae2244..7581711 100644 --- a/Server/public/js/libraries/miscTools.js +++ b/Server/public/js/libraries/miscTools.js @@ -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]]; + } } \ No newline at end of file diff --git a/Server/public/js/libraries/serverTools.js b/Server/public/js/libraries/serverTools.js index 274a8f8..9977c48 100644 --- a/Server/public/js/libraries/serverTools.js +++ b/Server/public/js/libraries/serverTools.js @@ -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 })