123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- var m = require('mithril');
- var markdown = require('markdown-it')()
- .use(require('markdown-it-footnote'));
- var _dbs = require('./dbs');
- var _Ui = require('./ui.js');
- var _Link = {
- parent_id:null,
- tid:"",
- opened:false,
- oninit(vn){
-
-
- this.tid = vn.attrs.href;
- },
- onbeforeupdate(vn){
- this.tid = vn.attrs.href;
- },
- view(vn){
- this.tid_known = typeof _dbs.data_byid[_dbs.lang][this.tid] === 'undefined' ? false : true;
- if (!this.tid_known) {
-
- }
- if(this.opened && this.tid_known){
-
-
- 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){
-
- console.log('click close btn', this);
- vn.state.opened = false;
-
- }
- }, m('span', m.trust("🗙"))),
- typeof _dbs.data_byid[_dbs.lang][this.tid].childs != "undefined"
- ? m(_Enonce, this.tob)
- : m(_Item, this.tob)
- ]
- );
- }else{
-
- return m('a', {
- 'class':'link',
- 'href':'#'+this.tid,
- 'rel':this.tid,
- onclick(e){
- e.preventDefault();
- console.log('click', this);
- vn.state.opened = true;
- return false;
- }
- }, vn.children);
- }
- }
- }
- function parseTextDom(nodes){
- var list = [];
-
- for (var i = 0; i < nodes.length; i++) {
- var n = {};
- if(typeof nodes[i].localName != "undefined"){
- n.tag=nodes[i].localName;
- if (n.tag == 'p') {
-
- n.tag = 'div';
- n.attrs = {'class':'paragraph'};
- }
- if (n.tag == 'a') {
-
- n.attrs = {'href':nodes[i].attributes.href.value};
- }
- if (n.tag == 'img') {
-
- n.attrs = {
- 'src':nodes[i].attributes.src.value,
- 'alt':nodes[i].attributes.alt.value
- };
- }
- if(nodes[i].childNodes.length){
-
- n.childs = parseTextDom(nodes[i].childNodes);
- }
- }else if (nodes[i].textContent.length > 0){
-
-
- n.tag='#text';
- n.text=nodes[i].textContent;
- }
-
- if(typeof n.tag != "undefined")
- list.push(n);
- }
- return list;
- }
- function populateTextDom(n,i){
-
- return n.tag == "#text"
- ? m.trust(n.text)
- : m(
- n.tag != 'a' ? n.tag : _Link,
- typeof n.attrs != "undefined" ? n.attrs : {},
- typeof n.childs != "undefined"
- ? n.childs.map(populateTextDom)
- : typeof n.text != "undefined"
- ? m.trust(n.text)
- : null
- );
- }
- var _Text = {
- id:null,
- text:"",
- texthtml:"",
- textdom:null,
- textchilds:[],
- parsetext(){
-
-
-
- this.texthtml = markdown.render(this.text)
-
- this.textdom = new DOMParser().parseFromString(this.texthtml, "text/html");
-
- this.textchilds = parseTextDom(this.textdom.getElementsByTagName('body')[0].childNodes);
- },
- oninit(vn){
- this.id = vn.attrs.id;
- this.text = vn.attrs.text || "";
- this.parsetext();
- },
- onbeforeupdate(vn,old){
- this.text = vn.attrs.text;
- this.parsetext();
- },
- view(vn){
-
- return m('div',
- {'class':'text'},
-
- this.textchilds.map(populateTextDom)
- );
- }
- }
- var _Item = {
- id:null,
- part:null,
- type:null,
- nested:false,
- oninit(vn){
-
- this.id = vn.attrs.id;
- this.type = vn.attrs.type;
-
- 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;
- this.type = vn.attrs.type;
- this.text = vn.attrs.text;
- },
- view(vn){
-
-
-
- return m("section", {
- 'id':this.id,
-
- 'class' :`item${this.nested ? ' nested':''} ${this.dottype}`
- },
- [
-
- !this.nested ? m("h3", {
-
-
-
-
- }, m.trust(markdown.renderInline(this.type))) : null,
-
- m(_Text, {'text':this.text, 'id':this.id})
- ]
- )
- }
- };
- var _Enonce = {
- partid:null,
- id:null,
- title:null,
- text:null,
- nested:false,
- childs:[],
- oninit(vn){
-
- this.partid = vn.attrs.partid;
- 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.dottype = vn.attrs.dottype || "no-dottype";
- },
- onbeforeupdate(vn, old) {
-
- this.title = vn.attrs.title || "";
- this.text = vn.attrs.text;
- this.childs = vn.attrs.childs || [];
- this.nested = vn.attrs.nested || false;
-
- },
- view(vn){
-
- return m("section", {
- 'id' :this.id,
- 'class' :`enonce${this.nested ? ' nested':''} ${this.dottype}`
- },
- [
-
- !this.nested ? m("h2", {}, m.trust(markdown.renderInline(this.title))) : null,
-
- m(_Text, {'text':this.text, 'id':this.id}),
-
- !this.nested ? this.childs.map(c => { return m(_Item, c); }) : null
- ])
- }
- }
- var _Part = {
- oninit(vn){
- this.id = vn.attrs.id;
- this.title = vn.attrs.title || '';
- this.enonces = vn.attrs.enonces;
- },
- onbeforeupdate(vn, old){
-
- this.title = vn.attrs.title || '';
- this.enonces = vn.attrs.enonces;
- },
- view(vn){
-
- return m("section", {
- 'id' :this.id,
- 'class' :'part'
- },
- [
-
- m("h1", {'class':'part-title', 'part':this.id}, m.trust(markdown.renderInline(this.title))),
-
- this.enonces.map(e => {
-
-
- switch (e.type) {
- case "title":
-
-
- return m("h2", {'class':'title'}, m.trust(markdown.renderInline(e.title)));
- break;
- case "filet":
-
-
- return m("h4", {'class':'filet'}, m.trust(markdown.renderInline(e.title)));
- break;
- default:
-
- return m(_Enonce, Object.assign({"partid":this.id},e));
- }
- })
- ]
- )
- }
- }
- var _Intro = {
- oninit(vn){
-
- this.id = vn.attrs.id;
- this.text = vn.attrs.text || '';
- },
- onbeforeupdate(vn, old){
- this.id = vn.attrs.id;
- this.text = vn.attrs.text || '';
- },
- view(vn){
- return m("section", {'class':'intro'}, m("p",m.trust(markdown.renderInline(this.text))));
- }
- }
- module.exports = {
-
-
-
-
-
- oncreate(vn){
- document.body.classList.add('mode-text');
- _Ui.init();
- },
-
-
-
-
- view(vn){
-
- return m('main', {id:"content", 'class':'mode-text'}, _dbs.data[vn.attrs.lang].map((p) => {
-
- if(p.id == 'intro'){
- return m(_Intro,p);
- }else{
- return m(_Part,p);
- }
- })
- );
- }
- }
|