typo styles ok, text mode ok with close bouton, bugfixes

This commit is contained in:
Bachir Soussi Chiadmi
2018-02-26 18:52:44 +01:00
parent f69747ac0a
commit 4ce48857bb
9 changed files with 541 additions and 360 deletions
+38 -24
View File
@@ -16,6 +16,7 @@ var _Ui = require('./ui.js');
// / /___/ / / / / ,<
// /_____/_/_/ /_/_/|_|
var _Link = {
parent_id:null,
tid:"",
opened:false,
oninit(vn){
@@ -29,16 +30,28 @@ var _Link = {
view(vn){
this.tid_known = typeof _dbs.data_byid[_dbs.lang][this.tid] === 'undefined' ? false : true;
if (!this.tid_known) {
// console.log('!! target id '+this.tid+' unkonwn !!');
// console.log(`!! in ${this.id}, target id ${this.tid} is unkonwn !!`);
}
if(this.opened && this.tid_known){
// console.log('this.tid', vn.state);
// traget object
this.tob = Object.assign({"nested":true},_dbs.data_byid[_dbs.lang][this.tid]);
return m('div', {'class':'opened-link'},
[
m('span', {'class':"link text"}, vn.children),
m('div', {
'class':'close-link-btn',
onclick(e){
// e.preventDefault();
console.log('click close btn', this);
vn.state.opened = false;
// return false;
}
}, m('span', m.trust("&#128473;"))),
typeof _dbs.data_byid[_dbs.lang][this.tid].childs != "undefined"
? m(_Enonce, _dbs.data_byid[_dbs.lang][this.tid])
: m(_Item, _dbs.data_byid[_dbs.lang][this.tid])
? m(_Enonce, this.tob)
: m(_Item, this.tob)
]
);
}else{
@@ -93,7 +106,7 @@ function parseTextDom(nodes){
// again parse node's childs
n.childs = parseTextDom(nodes[i].childNodes);
}
}else if (nodes[i].textContent.length > 1){
}else if (nodes[i].textContent.length > 0){
// if node has no localName it is probably a #text node
// we record it if it's not empty
n.tag='#text';
@@ -133,15 +146,10 @@ var _Text = {
// !! 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)
// TODO: fixe number link text disapear [3](1d3) ( in 104d )
// TODO: fixe parenthèse disparait _(par les Défin. [test 3](1d3) et [test 5](1d5))_ ( in 104d )
// parse html string to virtual dom
// convert html string to virtual dom
this.textdom = new DOMParser().parseFromString(this.texthtml, "text/html");
// get the text nodes (avoid html document extra)
// get the text nodes (avoid html document extra) and apply some transformations
this.textchilds = parseTextDom(this.textdom.getElementsByTagName('body')[0].childNodes);
if(this.id == "115sc"){
// console.log(this.textchilds);
}
},
oninit(vn){
this.id = vn.attrs.id;
@@ -179,6 +187,7 @@ var _Item = {
// vn.state.part = vn.state.slug.match(/^(\d)(.+)/)[1];
this.text = vn.attrs.text;
this.nested = vn.attrs.nested || false;
this.dottype = vn.attrs.dottype || null;
},
onbeforeupdate(vn, old){
this.nested = vn.attrs.nested || false;
@@ -186,18 +195,22 @@ var _Item = {
this.text = vn.attrs.text;
},
view(vn){
// if(this.id == "340c2"){
// console.log(`${this.id} vn.attrs `,vn.attrs);
// }
return m("section", {
'id':this.id,
'class':'item'+(this.nested ? ' nested':'')
// 'class':'item'+(this.nested ? ' nested':'')
'class' :`item${this.nested ? ' nested':''} ${this.dottype}`
},
[
// create title node
m("h3", {
// create title node (only if not nested)
!this.nested ? m("h3", {
// 'ref':vn.attrs.href,
onclick(e){
vn.state.active = vn.state.active ? 0 : 1;
}
}, m.trust(markdown.renderInline(this.type))),
// onclick(e){ WHAT IS THIS STATE ACTIVE ???
// vn.state.active = vn.state.active ? 0 : 1;
// }
}, m.trust(markdown.renderInline(this.type))) : null,
// create text node
m(_Text, {'text':this.text, 'id':this.id})
]
@@ -225,6 +238,7 @@ var _Enonce = {
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);
@@ -238,15 +252,15 @@ var _Enonce = {
// if(vn.attrs.id == '1d1') console.log('_Enonce VIEW, text :', vn.attrs.text);
return m("section", {
'id' :this.id,
'class' :'enonce'+(this.nested ? ' nested':'')
'class' :`enonce${this.nested ? ' nested':''} ${this.dottype}`
},
[
// create title node
m("h2", {}, m.trust(markdown.renderInline(this.title))),
// create title node (only if not nested)
!this.nested ? m("h2", {}, m.trust(markdown.renderInline(this.title))) : null,
// create text node
m(_Text, {'text':this.text, 'id':this.id}),
// addd children
this.childs.map(c => { return m(_Item, c); })
// add children (only if not nested)
!this.nested ? this.childs.map(c => { return m(_Item, c); }) : null
])
}
}
@@ -268,7 +282,7 @@ var _Part = {
this.enonces = vn.attrs.enonces;
},
view(vn){
console.log("part enonces", vn.attrs.enonces);
// console.log("part enonces", vn.attrs.enonces);
return m("section", {
'id' :this.id,
'class' :'part'