fixed translation switch bugs
This commit is contained in:
+65
-35
@@ -28,14 +28,24 @@ var _Link = {
|
||||
this.tid = vn.attrs.href;
|
||||
},
|
||||
view(vn){
|
||||
this.tid_known = typeof _dbs.data_byid[_dbs.lang][this.tid] === 'undefined' ? false : true;
|
||||
// console.log(vn.attrs);
|
||||
|
||||
this.tid_known =
|
||||
typeof vn.attrs.lang === 'undefined'
|
||||
? false
|
||||
: typeof _dbs.data_byid[vn.attrs.lang][this.tid] === 'undefined'
|
||||
? false
|
||||
: true;
|
||||
if (!this.tid_known) {
|
||||
// console.log(`!! in ${this.id}, target id ${this.tid} is unkonwn !!`);
|
||||
}
|
||||
if(this.opened && this.tid_known){
|
||||
// console.log('this.tid', vn.state);
|
||||
console.log('link vn.state', vn.state);
|
||||
// traget object
|
||||
this.tob = Object.assign({"nested":true},_dbs.data_byid[_dbs.lang][this.tid]);
|
||||
|
||||
this.tob = Object.assign({"nested":true},_dbs.data_byid[vn.attrs.lang][this.tid]);
|
||||
// this.tob = Object.assign({'lang':vn.attrs.lang}, this.tob);
|
||||
console.log('this.tob',this.tob);
|
||||
|
||||
return m('div', {'class':'opened-link'},
|
||||
[
|
||||
@@ -48,8 +58,8 @@ var _Link = {
|
||||
vn.state.opened = false;
|
||||
// return false;
|
||||
}
|
||||
}, m('span', m.trust("🗙"))),
|
||||
typeof _dbs.data_byid[_dbs.lang][this.tid].childs != "undefined"
|
||||
}),//, m('span', m.trust("🗙"))),
|
||||
typeof this.tob.childs !== "undefined"
|
||||
? m(_Enonce, this.tob)
|
||||
: m(_Item, this.tob)
|
||||
]
|
||||
@@ -66,7 +76,7 @@ var _Link = {
|
||||
vn.state.opened = true;
|
||||
return false;
|
||||
}
|
||||
}, vn.children); // c'est quoi ce vn.children ?
|
||||
}, vn.children);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -120,15 +130,15 @@ function parseTextDom(nodes){
|
||||
}
|
||||
|
||||
// recusive fucntion to generate mithril object from information recorded with parseTextDom()
|
||||
function populateTextDom(n,i){
|
||||
function populateTextDom(n){
|
||||
// console.log('populateTextDom : '+i,n);
|
||||
return n.tag == "#text"
|
||||
? m.trust(n.text)
|
||||
: m(
|
||||
n.tag != 'a' ? n.tag : _Link,
|
||||
typeof n.attrs != "undefined" ? n.attrs : {},
|
||||
typeof n.attrs != "undefined" ? Object.assign({"lang":this.attrs.lang},n.attrs) : {},
|
||||
typeof n.childs != "undefined"
|
||||
? n.childs.map(populateTextDom)
|
||||
? n.childs.map(populateTextDom, this)
|
||||
: typeof n.text != "undefined"
|
||||
? m.trust(n.text)
|
||||
: null
|
||||
@@ -141,31 +151,39 @@ var _Text = {
|
||||
texthtml:"",
|
||||
textdom:null,
|
||||
textchilds:[],
|
||||
parsetext(){
|
||||
parsetext(vn){
|
||||
// if(vn.attrs.nested){debugger;}
|
||||
// console.log('parsetext', this);
|
||||
// !! we need to convert markdown to html here because parseTextDom() is recursive through nodes tree
|
||||
// convert markdown to html
|
||||
this.texthtml = markdown.render(this.text)
|
||||
// if(typeof this.text === "undefined"){
|
||||
// debugger;
|
||||
// }
|
||||
this.texthtml = markdown.render(this.text);
|
||||
// convert html string to virtual dom
|
||||
this.textdom = new DOMParser().parseFromString(this.texthtml, "text/html");
|
||||
// get the text nodes (avoid html document extra) and apply some transformations
|
||||
this.textchilds = parseTextDom(this.textdom.getElementsByTagName('body')[0].childNodes);
|
||||
},
|
||||
oninit(vn){
|
||||
// if(vn.attrs.nested){debugger;}
|
||||
this.id = vn.attrs.id;
|
||||
this.text = vn.attrs.text || "";
|
||||
this.parsetext();
|
||||
// if(vn.attrs.nested){debugger;}
|
||||
this.parsetext(vn);
|
||||
},
|
||||
onbeforeupdate(vn,old){
|
||||
// if(vn.attrs.nested){debugger;}
|
||||
this.text = vn.attrs.text;
|
||||
this.parsetext();
|
||||
this.parsetext(vn);
|
||||
},
|
||||
view(vn){
|
||||
// console.log('_Text :: view : '+vn.attrs.slug, vn);
|
||||
return m('div',
|
||||
{'class':'text'},
|
||||
// loop through childNodes list generated by parseTextDom() in init
|
||||
this.textchilds.map(populateTextDom)
|
||||
// TODO : pass lang to populateTextDom
|
||||
this.textchilds.map(populateTextDom, vn)
|
||||
); // /m.div.text
|
||||
} // view:
|
||||
}
|
||||
@@ -181,6 +199,9 @@ var _Item = {
|
||||
type:null,
|
||||
nested:false,
|
||||
oninit(vn){
|
||||
// if(vn.attrs.nested){debugger;}
|
||||
// TODO: what to do with items without text ? as type title for example
|
||||
// if(typeof vn.attrs.text === 'undefined'){debugger;}
|
||||
// console.log('vn.attrs', vn.attrs);
|
||||
this.id = vn.attrs.id;
|
||||
this.type = vn.attrs.type;
|
||||
@@ -214,7 +235,9 @@ var _Item = {
|
||||
}, m.trust(markdown.renderInline(this.type)))
|
||||
: null,
|
||||
// create text node
|
||||
m(_Text, {'text':this.text, 'id':this.id}),
|
||||
typeof vn.attrs.text !== "undefined"
|
||||
? m(_Text, {'text':this.text, 'id':this.id, 'lang':vn.attrs.lang})
|
||||
: null,
|
||||
// add children (only if not nested)
|
||||
// typeof vn.attrs.childs !== 'undefined' && !this.nested
|
||||
// ? vn.attrs.childs.map(c => { return m(_Item, c); })
|
||||
@@ -231,43 +254,49 @@ var _Item = {
|
||||
// /_____/_/ /_/\____/_/ /_/\___/\___/
|
||||
var _Enonce = {
|
||||
partid:null,
|
||||
id:null,
|
||||
// id:null,
|
||||
title:null,
|
||||
text:null,
|
||||
nested:false,
|
||||
childs:[],
|
||||
// text:null,
|
||||
// nested:false,
|
||||
// childs:[],
|
||||
oninit(vn){
|
||||
// if(vn.attrs.nested){debugger;}
|
||||
// // console.log('Enonce on init', vn);
|
||||
this.partid = vn.attrs.partid;
|
||||
this.id = vn.attrs.id;
|
||||
// this.id = vn.attrs.id;
|
||||
this.title = vn.attrs.title || "";
|
||||
this.text = vn.attrs.text;
|
||||
this.childs = vn.attrs.childs || [];
|
||||
this.nested = vn.attrs.nested || false;
|
||||
// this.text = vn.attrs.text;
|
||||
// this.childs = vn.attrs.childs || [];
|
||||
// this.nested = vn.attrs.nested || false;
|
||||
this.dottype = vn.attrs.dottype || "no-dottype";
|
||||
},
|
||||
onbeforeupdate(vn, old) {
|
||||
// console.log(vn.attrs.childs);
|
||||
this.title = vn.attrs.title || "";
|
||||
this.text = vn.attrs.text;
|
||||
this.childs = vn.attrs.childs || [];
|
||||
this.nested = vn.attrs.nested || false;
|
||||
// this.text = vn.attrs.text;
|
||||
// this.childs = vn.attrs.childs || [];
|
||||
// this.nested = vn.attrs.nested || false;
|
||||
// if(vn.attrs.id == '1d1') console.log('_Enonce UPDATE, text :', vn.attrs.text);
|
||||
},
|
||||
view(vn){
|
||||
// if(vn.attrs.id == '1d1') console.log('_Enonce VIEW, text :', vn.attrs.text);
|
||||
// if(vn.attrs.nested){
|
||||
// console.log('ennonce vn.attrs', vn.attrs);
|
||||
// }
|
||||
return m("section", {
|
||||
'id' :this.id,
|
||||
'class' :`enonce${this.nested ? ' nested':''} ${this.dottype}`
|
||||
'id' :vn.attrs.id,
|
||||
'class' :`enonce${vn.attrs.nested ? ' nested':''} ${this.dottype}`
|
||||
},
|
||||
[
|
||||
// create title node (only if not nested)
|
||||
!this.nested ? m("h2", {}, m.trust(markdown.renderInline(this.title))) : null,
|
||||
!vn.attrs.nested ? m("h2", {}, m.trust(markdown.renderInline(this.title))) : null,
|
||||
// create text node
|
||||
m(_Text, {'text':this.text, 'id':this.id}),
|
||||
m(_Text, {'text':vn.attrs.text, 'id':vn.attrs.id, 'nested':vn.attrs.nested}),
|
||||
// add children (only if not nested)
|
||||
typeof this.childs !== 'undefined' && !this.nested
|
||||
? this.childs.map(c => { return m(_Item, c); })
|
||||
typeof vn.attrs.childs !== 'undefined' && !vn.attrs.nested
|
||||
? vn.attrs.childs.map(c => {
|
||||
c.lang = vn.attrs.lang;
|
||||
return m(_Item, c);
|
||||
})
|
||||
: null
|
||||
])
|
||||
}
|
||||
@@ -315,6 +344,7 @@ var _Part = {
|
||||
break;
|
||||
default:
|
||||
// or build structure
|
||||
e.lang = vn.attrs.lang;
|
||||
return m(_Enonce, Object.assign({"partid":vn.attrs.id},e));
|
||||
}
|
||||
})
|
||||
@@ -343,7 +373,6 @@ var _Intro = {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ______ __
|
||||
// /_ __/__ _ __/ /_
|
||||
// / / / _ \| |/_/ __/
|
||||
@@ -364,9 +393,10 @@ module.exports = {
|
||||
// // i18next.changeLanguage(vn.attrs.lang);
|
||||
// },
|
||||
view(vn){
|
||||
// console.log('_ModeText view : _dbs.data', _dbs.data);
|
||||
// console.log('_ModeText view', vn.attrs.lang);
|
||||
return m('main', {id:"content", 'class':'mode-text'}, _dbs.data[vn.attrs.lang].map((p) => {
|
||||
// console.log("MAP _dbs", p);
|
||||
p.lang = vn.attrs.lang;
|
||||
if(p.id == 'intro'){
|
||||
return m(_Intro,p);
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user