typo styles ok, text mode ok with close bouton, bugfixes
This commit is contained in:
@@ -41,12 +41,22 @@ var _Dot = {
|
||||
this.text = vn.attrs.text || '';
|
||||
this.rendered_text = markdown.render(this.text);
|
||||
|
||||
// construct summary
|
||||
// TODO: summary needs more work (strip tags, markdown render)
|
||||
this.summary = this.text.match('([^ ]*[ ]{0,1}){1,6}')[0];
|
||||
this.summary = this.summary.trim().replace(/_([^_]+)$/g, "_$1_");
|
||||
this.summary = this.summary.replace(/\[([^\]]+)$/g, "$1");
|
||||
this.summary = markdown.renderInline(this.summary) + " …";
|
||||
if(this.dottype == "preface"){
|
||||
this.summary = this.rendered_text;
|
||||
}else{
|
||||
// construct summary
|
||||
// TODO: summary needs more work (strip tags, markdown render)
|
||||
// remove img
|
||||
this.summary = this.text.replace(/!\[[^\]]+\]\([^\)]+\)/g, "");
|
||||
// get portion of text
|
||||
this.summary = this.summary.match('([^ ]*[ ]{0,1}){1,6}')[0];
|
||||
// end underscores (italic)
|
||||
this.summary = this.summary.trim().replace(/_([^_]+)$/g, "_$1_");
|
||||
// end brackets (links)
|
||||
this.summary = this.summary.replace(/\[([^\]]+)$/g, "$1");
|
||||
// render the marckdown
|
||||
this.summary = markdown.renderInline(this.summary) + " …";
|
||||
}
|
||||
|
||||
},
|
||||
oninit(vn){
|
||||
@@ -89,73 +99,15 @@ var _Dot = {
|
||||
this.setupTitle(vn);
|
||||
}
|
||||
},
|
||||
view(vn){
|
||||
if (this.active && this.opened) {
|
||||
// full view of dot with linked dots
|
||||
// console.log('_Dot view '+this.id+' parents :',this.parents);
|
||||
var dot_content = [
|
||||
// links to
|
||||
this.links.to.length
|
||||
? m('nav', {'class':'links to'}, this.links.to.map(id => {
|
||||
// console.log(id);
|
||||
if(typeof _dbs.data_byid[_dbs.lang][id] !== 'undefined'){
|
||||
var obj = _dbs.data_byid[_dbs.lang][id];
|
||||
// console.log('link to : obj', obj);
|
||||
return m(_Dot, {
|
||||
"id":id,
|
||||
'text':obj.text,
|
||||
'dottype':obj.dottype,
|
||||
'type':obj.type,
|
||||
// passe the memory of crossed dots plus the current one
|
||||
'parents':vn.state.parents.concat([vn.state.id]),
|
||||
// activate link only if not in parents (already went through it)
|
||||
'active':vn.state.parents.indexOf(id) == -1 ? true:false
|
||||
});
|
||||
}
|
||||
})
|
||||
)
|
||||
: null, // if no links to, add nothing
|
||||
// id
|
||||
// m('span', {'class':'id'}, this.id), // this.type+' '+
|
||||
// bullet
|
||||
// m('span', {'class':'bullet'}, m.trust('⚫')),
|
||||
// Title
|
||||
m('span', {'class':'title'}, m.trust(this.title)),
|
||||
// full text
|
||||
m('section', {
|
||||
'class':'text',
|
||||
onmouseover(e){
|
||||
e.preventDefault();
|
||||
if(e.target.nodeName == "A" ){
|
||||
// console.log("over e.target", e.target);
|
||||
// console.log('over vn', vn);
|
||||
var id = e.target.getAttribute("href");
|
||||
// add highlight class
|
||||
vn.dom.querySelector('nav.links>div[uid="'+id+'"]').classList.add('highlight');
|
||||
}else{
|
||||
// remove all hilight class
|
||||
for (link of vn.dom.querySelectorAll('nav.links>div.dot')) {
|
||||
link.classList.remove('highlight');
|
||||
}
|
||||
}
|
||||
},
|
||||
onclick(e){
|
||||
e.preventDefault();
|
||||
if(e.target.nodeName == "A" ){
|
||||
// console.log("over e.target", e.target);
|
||||
// console.log('over vn', vn);
|
||||
var id = e.target.getAttribute("href");
|
||||
// add highlight class
|
||||
vn.dom.querySelector('nav.links>div[uid="'+id+'"]>.summary').click();
|
||||
}
|
||||
}
|
||||
}, m.trust(this.rendered_text)),
|
||||
// links from
|
||||
this.links.from.length
|
||||
? m('nav', {'class':'links from'}, this.links.from.map(id => {
|
||||
setOpenedContent(vn){
|
||||
this.dot_content = [
|
||||
// links to
|
||||
this.links.to.length
|
||||
? m('nav', {'class':'links to'}, this.links.to.map(id => {
|
||||
// console.log(id);
|
||||
if(typeof _dbs.data_byid[_dbs.lang][id] !== 'undefined'){
|
||||
var obj = _dbs.data_byid[_dbs.lang][id];
|
||||
// console.log('link from : obj', obj);
|
||||
// return a dot
|
||||
// console.log('link to : obj', obj);
|
||||
return m(_Dot, {
|
||||
"id":id,
|
||||
'text':obj.text,
|
||||
@@ -166,41 +118,100 @@ var _Dot = {
|
||||
// activate link only if not in parents (already went through it)
|
||||
'active':vn.state.parents.indexOf(id) == -1 ? true:false
|
||||
});
|
||||
})
|
||||
)
|
||||
: null, // if no links from, add nothing
|
||||
];
|
||||
}
|
||||
})
|
||||
)
|
||||
: null, // if no links to, add nothing
|
||||
// id
|
||||
// m('span', {'class':'id'}, this.id), // this.type+' '+
|
||||
// bullet
|
||||
// m('span', {'class':'bullet'}, m.trust('⚫')),
|
||||
// Title
|
||||
m('span', {'class':'title'}, m.trust(this.title)),
|
||||
// full text
|
||||
m('section', {
|
||||
'class':'text',
|
||||
onmouseover(e){
|
||||
e.preventDefault();
|
||||
if(e.target.nodeName == "A" ){
|
||||
// console.log("over e.target", e.target);
|
||||
// console.log('over vn', vn);
|
||||
var id = e.target.getAttribute("href");
|
||||
// add highlight class
|
||||
vn.dom.querySelector('nav.links>div[uid="'+id+'"]').classList.add('highlight');
|
||||
}else{
|
||||
// remove all hilight class
|
||||
for (link of vn.dom.querySelectorAll('nav.links>div.dot')) {
|
||||
link.classList.remove('highlight');
|
||||
}
|
||||
}
|
||||
},
|
||||
onclick(e){
|
||||
e.preventDefault();
|
||||
if(e.target.nodeName == "A" ){
|
||||
// console.log("over e.target", e.target);
|
||||
// console.log('over vn', vn);
|
||||
var id = e.target.getAttribute("href");
|
||||
// add highlight class
|
||||
vn.dom.querySelector('nav.links>div[uid="'+id+'"]>.summary').click();
|
||||
}
|
||||
}
|
||||
}, m.trust(this.rendered_text)),
|
||||
// links from
|
||||
this.links.from.length
|
||||
? m('nav', {'class':'links from'}, this.links.from.map(id => {
|
||||
var obj = _dbs.data_byid[_dbs.lang][id];
|
||||
// console.log('link from : obj', obj);
|
||||
// return a dot
|
||||
return m(_Dot, {
|
||||
"id":id,
|
||||
'text':obj.text,
|
||||
'dottype':obj.dottype,
|
||||
'type':obj.type,
|
||||
// passe the memory of crossed dots plus the current one
|
||||
'parents':vn.state.parents.concat([vn.state.id]),
|
||||
// activate link only if not in parents (already went through it)
|
||||
'active':vn.state.parents.indexOf(id) == -1 ? true:false
|
||||
});
|
||||
})
|
||||
)
|
||||
: null, // if no links from, add nothing
|
||||
];
|
||||
},
|
||||
setPreviewContent(vn){
|
||||
this.dot_content = [
|
||||
// m('span', {'class':'id'}, this.id), // this.type+' '+
|
||||
// m('span', {'class':'bullet'}, m.trust('•')),
|
||||
m('span', {
|
||||
'class':'title',
|
||||
onclick(e){
|
||||
// TODO: animate openening (text and links separatly)
|
||||
vn.state.opened = true;
|
||||
}
|
||||
}, m.trust(this.title)), // TODO: on nested dot add full description : Part 1, Prop 8, scolie
|
||||
m('p', {
|
||||
'class':'summary',
|
||||
onclick(e){
|
||||
// TODO: animate openening (text and links separatly)
|
||||
vn.state.opened = true;
|
||||
}
|
||||
}, m.trust(this.summary))
|
||||
];
|
||||
},
|
||||
view(vn){
|
||||
if (this.active && this.opened) {
|
||||
// full view of dot with linked dots
|
||||
this.setOpenedContent(vn);
|
||||
}else{
|
||||
// preview dot
|
||||
var dot_content = [
|
||||
// m('span', {'class':'id'}, this.id), // this.type+' '+
|
||||
// m('span', {'class':'bullet'}, m.trust('•')),
|
||||
m('span', {
|
||||
'class':'title',
|
||||
onclick(e){
|
||||
// TODO: animate openening (text and links separatly)
|
||||
vn.state.opened = true;
|
||||
}
|
||||
}, m.trust(this.title)), // TODO: on nested dot add full description : Part 1, Prop 8, scolie
|
||||
m('p', {
|
||||
'class':'summary',
|
||||
onclick(e){
|
||||
// TODO: animate openening (text and links separatly)
|
||||
vn.state.opened = true;
|
||||
}
|
||||
}, m.trust(this.summary))
|
||||
];
|
||||
this.setPreviewContent(vn);
|
||||
}
|
||||
|
||||
return m('div',{
|
||||
'uid':this.id,
|
||||
'class':`dot ${this.dottype}`,
|
||||
// onclick(e){
|
||||
// // TODO: animate openening (text and links separatly)
|
||||
// vn.state.opened = true;
|
||||
// }
|
||||
},
|
||||
dot_content
|
||||
this.dot_content
|
||||
);
|
||||
},
|
||||
onupdate(vn){
|
||||
|
||||
Reference in New Issue
Block a user