aboutsummaryrefslogtreecommitdiff
path: root/assets/web.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/web.js')
-rw-r--r--assets/web.js78
1 files changed, 45 insertions, 33 deletions
diff --git a/assets/web.js b/assets/web.js
index 3801335..bc01532 100644
--- a/assets/web.js
+++ b/assets/web.js
@@ -1,65 +1,77 @@
const web = new Vue({
- el: '#web',
+ el: "#web",
data: {
- word: '',
+ word: "",
timer: undefined,
definitions: null,
is_word: null,
- placeholders: ['mot', 'bonjour', 'manger', 'rire', 'jour', 'gagner', 'chanter', 'danser', 'village',
- 'France', 'baguette', 'cola', 'marguerite']
+ placeholders: [
+ "mot",
+ "bonjour",
+ "manger",
+ "rire",
+ "jour",
+ "gagner",
+ "chanter",
+ "danser",
+ "village",
+ "France",
+ "baguette",
+ "cola",
+ "marguerite",
+ ],
},
methods: {
- searchWord: function() {
- if(!this.word) return;
- if(this.timer) {
+ searchWord: function () {
+ if (!this.word) return;
+ if (this.timer) {
clearTimeout(this.timer);
this.timer = undefined;
}
- fetch(`/def?w=${this.word}`)
- .then((response) => {
- this.is_word = response.ok;
+ fetch(`/${this.word}`).then((response) => {
+ this.is_word = response.ok;
- if( response.ok ) {
- response.arrayBuffer().then(res => {
- this.definitions = msgpack.decode(new Uint8Array(res));
- if( this.definitions && this.definitions[0] && this.definitions[0].mot) {
- if(!this.word.includes('_')) {
- this.word = this.definitions[0].mot;
- }
+ if (response.ok) {
+ response.arrayBuffer().then((res) => {
+ this.definitions = json.decode(res);
+ if (this.Def && this.Def[0] && this.Def[0].écriture) {
+ /*
+ if (!this.word.includes("_")) {
+ this.word = this.Def[0].mot;
}
- });
- }
- })
+ */
+ }
+ });
+ }
+ });
},
- rand: (min,max) =>
- Math.floor(Math.random()*(max-min+1)+min)
- ,
- randomplaceholder: function() {
- const r = this.rand(0, this.placeholders.length-1);
+ rand: (min, max) => Math.floor(Math.random() * (max - min + 1) + min),
+ randomplaceholder: function () {
+ const r = this.rand(0, this.placeholders.length - 1);
const a = this.placeholders[r];
return a;
},
},
watch: {
- word: function(w) {
- if( w === '' ) {
+ word: function (w) {
+ if (w === "") {
this.is_word = null;
}
- if(this.timer) {
+ if (this.timer) {
clearTimeout(this.timer);
this.timer = undefined;
}
this.timer = setTimeout(this.searchWord, 800);
- }
+ },
},
- mounted: function() {
+ mounted: function () {
const param = window.location.search.substr(1);
- param.split('&').forEach( p => {
- if (p.startsWith('w=')) {
+ param.split("&").forEach((p) => {
+ if (p.startsWith("w=")) {
this.word = p.slice(2);
}
});
- }
+ },
});