fixed translation switch bugs

This commit is contained in:
2018-06-20 12:30:44 +02:00
parent dcdd8e0011
commit 30443960ab
11 changed files with 7576 additions and 12171 deletions
+3
View File
@@ -0,0 +1,3 @@
{
"plugins": ["transform-object-rest-spread"]
}
+5 -2
View File
@@ -889,13 +889,15 @@ main#content.mode-text .enonce.nested, main#content.mode-text .item.nested {
main#content.mode-text .opened-link .close-link-btn { main#content.mode-text .opened-link .close-link-btn {
width: 20px; width: 20px;
height: 20px;
margin: 1em 0 -2.1em 61px; margin: 1em 0 -2.1em 61px;
position: relative; position: relative;
background-color: white; background-color: white;
z-index: 10; z-index: 10;
cursor: pointer; cursor: pointer;
text-align: center; } text-align: center; }
main#content.mode-text .opened-link .close-link-btn span { main#content.mode-text .opened-link .close-link-btn:before {
content: "\1F7AC";
font-style: normal; font-style: normal;
font-size: 0.7em; font-size: 0.7em;
font-weight: 300; } font-weight: 300; }
@@ -991,7 +993,8 @@ main#content.mode-text .opened-link .close-link-btn {
font-weight: 300; } font-weight: 300; }
.dot .close-link-btn { .dot .close-link-btn {
cursor: pointer; } cursor: pointer; }
.dot .close-link-btn span { .dot .close-link-btn:before {
content: "\1F7AC";
font-style: normal; font-style: normal;
font-size: 0.7em; font-size: 0.7em;
font-weight: 300; } font-weight: 300; }
+1 -12077
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+15 -3
View File
@@ -390,7 +390,7 @@ main#content.mode-text{
// position:relative; // position:relative;
// outline: 1px solid red; // outline: 1px solid red;
.close-link-btn{ .close-link-btn{
width:20px; width:20px; height: 20px;
margin:1em 0 -2.1em $margin_left - 9px; margin:1em 0 -2.1em $margin_left - 9px;
// outline: 1px solid green; // outline: 1px solid green;
// display:inline-block; // display:inline-block;
@@ -400,11 +400,17 @@ main#content.mode-text{
// top:0; left:-1em; // top:0; left:-1em;
cursor: pointer; cursor: pointer;
text-align: center; text-align: center;
span{ &:before{
content:"\1f7ac";
font-style: normal; font-style: normal;
font-size: 0.7em; font-size: 0.7em;
font-weight: 300; font-weight: 300;
} }
// span{
// font-style: normal;
// font-size: 0.7em;
// font-weight: 300;
// }
} }
} }
} }
@@ -589,11 +595,17 @@ main#content.mode-connections{
.close-link-btn{ .close-link-btn{
cursor: pointer; cursor: pointer;
span{ &:before{
content:"\1f7ac";
font-style: normal; font-style: normal;
font-size: 0.7em; font-size: 0.7em;
font-weight: 300; font-weight: 300;
} }
// span{
// font-style: normal;
// font-size: 0.7em;
// font-weight: 300;
// }
} }
&.nested{ &.nested{
+1 -1
View File
@@ -173,7 +173,7 @@ var _Dot = {
vn.dom.querySelector(`nav.links>div[uid="${id}"]`).classList.add('highlight'); vn.dom.querySelector(`nav.links>div[uid="${id}"]`).classList.add('highlight');
}else{ }else{
// remove all hilight class // remove all hilight class
for (link of vn.dom.querySelectorAll('nav.links>div.dot')) { for (let link of vn.dom.querySelectorAll('nav.links>div.dot')) {
link.classList.remove('highlight'); link.classList.remove('highlight');
} }
} }
+65 -35
View File
@@ -28,14 +28,24 @@ var _Link = {
this.tid = vn.attrs.href; this.tid = vn.attrs.href;
}, },
view(vn){ 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) { if (!this.tid_known) {
// console.log(`!! in ${this.id}, target id ${this.tid} is unkonwn !!`); // console.log(`!! in ${this.id}, target id ${this.tid} is unkonwn !!`);
} }
if(this.opened && this.tid_known){ if(this.opened && this.tid_known){
// console.log('this.tid', vn.state); console.log('link vn.state', vn.state);
// traget object // 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'}, return m('div', {'class':'opened-link'},
[ [
@@ -48,8 +58,8 @@ var _Link = {
vn.state.opened = false; vn.state.opened = false;
// return false; // return false;
} }
}, m('span', m.trust("🗙"))), }),//, m('span', m.trust("🗙"))),
typeof _dbs.data_byid[_dbs.lang][this.tid].childs != "undefined" typeof this.tob.childs !== "undefined"
? m(_Enonce, this.tob) ? m(_Enonce, this.tob)
: m(_Item, this.tob) : m(_Item, this.tob)
] ]
@@ -66,7 +76,7 @@ var _Link = {
vn.state.opened = true; vn.state.opened = true;
return false; 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() // recusive fucntion to generate mithril object from information recorded with parseTextDom()
function populateTextDom(n,i){ function populateTextDom(n){
// console.log('populateTextDom : '+i,n); // console.log('populateTextDom : '+i,n);
return n.tag == "#text" return n.tag == "#text"
? m.trust(n.text) ? m.trust(n.text)
: m( : m(
n.tag != 'a' ? n.tag : _Link, 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" typeof n.childs != "undefined"
? n.childs.map(populateTextDom) ? n.childs.map(populateTextDom, this)
: typeof n.text != "undefined" : typeof n.text != "undefined"
? m.trust(n.text) ? m.trust(n.text)
: null : null
@@ -141,31 +151,39 @@ var _Text = {
texthtml:"", texthtml:"",
textdom:null, textdom:null,
textchilds:[], textchilds:[],
parsetext(){ parsetext(vn){
// if(vn.attrs.nested){debugger;}
// console.log('parsetext', this); // console.log('parsetext', this);
// !! we need to convert markdown to html here because parseTextDom() is recursive through nodes tree // !! we need to convert markdown to html here because parseTextDom() is recursive through nodes tree
// convert markdown to html // 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 // convert html string to virtual dom
this.textdom = new DOMParser().parseFromString(this.texthtml, "text/html"); this.textdom = new DOMParser().parseFromString(this.texthtml, "text/html");
// get the text nodes (avoid html document extra) and apply some transformations // get the text nodes (avoid html document extra) and apply some transformations
this.textchilds = parseTextDom(this.textdom.getElementsByTagName('body')[0].childNodes); this.textchilds = parseTextDom(this.textdom.getElementsByTagName('body')[0].childNodes);
}, },
oninit(vn){ oninit(vn){
// if(vn.attrs.nested){debugger;}
this.id = vn.attrs.id; this.id = vn.attrs.id;
this.text = vn.attrs.text || ""; this.text = vn.attrs.text || "";
this.parsetext(); // if(vn.attrs.nested){debugger;}
this.parsetext(vn);
}, },
onbeforeupdate(vn,old){ onbeforeupdate(vn,old){
// if(vn.attrs.nested){debugger;}
this.text = vn.attrs.text; this.text = vn.attrs.text;
this.parsetext(); this.parsetext(vn);
}, },
view(vn){ view(vn){
// console.log('_Text :: view : '+vn.attrs.slug, vn); // console.log('_Text :: view : '+vn.attrs.slug, vn);
return m('div', return m('div',
{'class':'text'}, {'class':'text'},
// loop through childNodes list generated by parseTextDom() in init // 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 ); // /m.div.text
} // view: } // view:
} }
@@ -181,6 +199,9 @@ var _Item = {
type:null, type:null,
nested:false, nested:false,
oninit(vn){ 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); // console.log('vn.attrs', vn.attrs);
this.id = vn.attrs.id; this.id = vn.attrs.id;
this.type = vn.attrs.type; this.type = vn.attrs.type;
@@ -214,7 +235,9 @@ var _Item = {
}, m.trust(markdown.renderInline(this.type))) }, m.trust(markdown.renderInline(this.type)))
: null, : null,
// create text node // 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) // add children (only if not nested)
// typeof vn.attrs.childs !== 'undefined' && !this.nested // typeof vn.attrs.childs !== 'undefined' && !this.nested
// ? vn.attrs.childs.map(c => { return m(_Item, c); }) // ? vn.attrs.childs.map(c => { return m(_Item, c); })
@@ -231,43 +254,49 @@ var _Item = {
// /_____/_/ /_/\____/_/ /_/\___/\___/ // /_____/_/ /_/\____/_/ /_/\___/\___/
var _Enonce = { var _Enonce = {
partid:null, partid:null,
id:null, // id:null,
title:null, title:null,
text:null, // text:null,
nested:false, // nested:false,
childs:[], // childs:[],
oninit(vn){ oninit(vn){
// if(vn.attrs.nested){debugger;}
// // console.log('Enonce on init', vn); // // console.log('Enonce on init', vn);
this.partid = vn.attrs.partid; this.partid = vn.attrs.partid;
this.id = vn.attrs.id; // this.id = vn.attrs.id;
this.title = vn.attrs.title || ""; this.title = vn.attrs.title || "";
this.text = vn.attrs.text; // this.text = vn.attrs.text;
this.childs = vn.attrs.childs || []; // this.childs = vn.attrs.childs || [];
this.nested = vn.attrs.nested || false; // this.nested = vn.attrs.nested || false;
this.dottype = vn.attrs.dottype || "no-dottype"; this.dottype = vn.attrs.dottype || "no-dottype";
}, },
onbeforeupdate(vn, old) { onbeforeupdate(vn, old) {
// console.log(vn.attrs.childs); // console.log(vn.attrs.childs);
this.title = vn.attrs.title || ""; this.title = vn.attrs.title || "";
this.text = vn.attrs.text; // this.text = vn.attrs.text;
this.childs = vn.attrs.childs || []; // this.childs = vn.attrs.childs || [];
this.nested = vn.attrs.nested || false; // this.nested = vn.attrs.nested || false;
// if(vn.attrs.id == '1d1') console.log('_Enonce UPDATE, text :', vn.attrs.text); // if(vn.attrs.id == '1d1') console.log('_Enonce UPDATE, text :', vn.attrs.text);
}, },
view(vn){ 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", { return m("section", {
'id' :this.id, 'id' :vn.attrs.id,
'class' :`enonce${this.nested ? ' nested':''} ${this.dottype}` 'class' :`enonce${vn.attrs.nested ? ' nested':''} ${this.dottype}`
}, },
[ [
// create title node (only if not nested) // 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 // 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) // add children (only if not nested)
typeof this.childs !== 'undefined' && !this.nested typeof vn.attrs.childs !== 'undefined' && !vn.attrs.nested
? this.childs.map(c => { return m(_Item, c); }) ? vn.attrs.childs.map(c => {
c.lang = vn.attrs.lang;
return m(_Item, c);
})
: null : null
]) ])
} }
@@ -315,6 +344,7 @@ var _Part = {
break; break;
default: default:
// or build structure // or build structure
e.lang = vn.attrs.lang;
return m(_Enonce, Object.assign({"partid":vn.attrs.id},e)); 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); // // i18next.changeLanguage(vn.attrs.lang);
// }, // },
view(vn){ 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) => { return m('main', {id:"content", 'class':'mode-text'}, _dbs.data[vn.attrs.lang].map((p) => {
// console.log("MAP _dbs", p); // console.log("MAP _dbs", p);
p.lang = vn.attrs.lang;
if(p.id == 'intro'){ if(p.id == 'intro'){
return m(_Intro,p); return m(_Intro,p);
}else{ }else{
+3 -3
View File
@@ -96,7 +96,7 @@ module.exports = {
xobj.addEventListener("progress", function(oEvent){ xobj.addEventListener("progress", function(oEvent){
if (oEvent.lengthComputable) { if (oEvent.lengthComputable) {
var percentComplete = oEvent.loaded / oEvent.total * 100; var percentComplete = oEvent.loaded / oEvent.total * 100;
console.log(lc+' loaded :',percentComplete); // console.log(lc+' loaded :',percentComplete);
this.loaded_by_file[lc] = percentComplete; this.loaded_by_file[lc] = percentComplete;
var totalloaded = 0; var totalloaded = 0;
for (var i = 0; i < this.langs.length; i++) { for (var i = 0; i < this.langs.length; i++) {
@@ -181,7 +181,7 @@ module.exports = {
// console.log(_db[p][e][c]); // console.log(_db[p][e][c]);
if(this.data[l][p].enonces[e].childs[c].childs[cc].id){ if(this.data[l][p].enonces[e].childs[c].childs[cc].id){
cc_id = this.data[l][p].enonces[e].childs[c].childs[cc].id; cc_id = this.data[l][p].enonces[e].childs[c].childs[cc].id;
console.log('cc_id', cc_id); // console.log('cc_id', cc_id);
// guess the type from the id // guess the type from the id
this.data[l][p].enonces[e].childs[c].childs[cc].dottype = this.setupType(cc_id); this.data[l][p].enonces[e].childs[c].childs[cc].dottype = this.setupType(cc_id);
// breadcrumb (full tree title) // breadcrumb (full tree title)
@@ -207,7 +207,7 @@ module.exports = {
if(m){ if(m){
m.shift(); m.shift();
// removing undefined // removing undefined
m_clean = []; let m_clean = [];
for (let i = 0; i < m.length; i++) { for (let i = 0; i < m.length; i++) {
if(typeof m[i] !== 'undefined'){ if(typeof m[i] !== 'undefined'){
m_clean.push(m[i]); m_clean.push(m[i]);
+7417
View File
File diff suppressed because it is too large Load Diff
+13 -8
View File
@@ -6,19 +6,24 @@
"author": "Bachir Soussi Chiadmi <bachir@g-u-i.me>", "author": "Bachir Soussi Chiadmi <bachir@g-u-i.me>",
"license": "GPL-3.0", "license": "GPL-3.0",
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^0.28.11",
"extract-text-webpack-plugin": "^3.0.2", "extract-text-webpack-plugin": "^3.0.2",
"uglifyjs-webpack-plugin": "^1.1.6", "file-loader": "^1.1.11",
"webpack": "^3.10.0" "node-sass": "^4.9.0",
"sass-loader": "^6.0.7",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^3.12.0"
}, },
"dependencies": { "dependencies": {
"css-loader": "^0.28.0",
"file-loader": "^1.1.6",
"jquery": "^3.2.1", "jquery": "^3.2.1",
"markdown-it": "^8.3.1", "markdown-it": "^8.4.1",
"markdown-it-footnote": "^3.0.1", "markdown-it-footnote": "^3.0.1",
"mithril": "^1.1.1", "mithril": "^1.1.1",
"node-sass": "^4.5.3", "normalize.css": "^8.0.0"
"normalize.css": "^8.0.0",
"sass-loader": "^6.0.3"
} }
} }
+52 -41
View File
@@ -21,6 +21,17 @@ module.exports = {
module: { module: {
rules: [ rules: [
/* your other rules for JavaScript transpiling go in here */ /* your other rules for JavaScript transpiling go in here */
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015'],
// plugins: [require('@babel/plugin-proposal-object-rest-spread')]
}
}
},
{ {
// regular css files // regular css files
test: /\.css$/, test: /\.css$/,
@@ -35,7 +46,7 @@ module.exports = {
// fonts // fonts
test: /\.(eot|svg|ttf|woff|woff2)$/, test: /\.(eot|svg|ttf|woff|woff2)$/,
use: "file-loader?name=fonts/[name].[ext]" use: "file-loader?name=fonts/[name].[ext]"
}, }
] ]
}, },
plugins: [ plugins: [
@@ -43,46 +54,46 @@ module.exports = {
// define where to save the file // define where to save the file
filename: '[name].css', allChunks: true, filename: '[name].css', allChunks: true,
}), }),
// new UglifyJsPlugin({ new UglifyJsPlugin({
// sourceMap: true, sourceMap: true,
// parallel:4, parallel:4,
// uglifyOptions: { uglifyOptions: {
// ecma: 8, ecma: 8,
// // disable most of compress to gain in compilation speed // disable most of compress to gain in compilation speed
// // https://slack.engineering/keep-webpack-fast-a-field-guide-for-better-build-performance-f56a5995e8f1 // https://slack.engineering/keep-webpack-fast-a-field-guide-for-better-build-performance-f56a5995e8f1
// compress: { compress: {
// arrows: false, arrows: false,
// booleans: false, booleans: false,
// // cascade: false, // cascade: false,
// collapse_vars: false, collapse_vars: false,
// comparisons: false, comparisons: false,
// computed_props: false, computed_props: false,
// hoist_funs: false, hoist_funs: false,
// hoist_props: false, hoist_props: false,
// hoist_vars: false, hoist_vars: false,
// if_return: false, if_return: false,
// inline: false, inline: false,
// join_vars: false, join_vars: false,
// keep_infinity: true, keep_infinity: true,
// loops: false, loops: false,
// negate_iife: false, negate_iife: false,
// properties: false, properties: false,
// reduce_funcs: false, reduce_funcs: false,
// reduce_vars: false, reduce_vars: false,
// sequences: false, sequences: false,
// side_effects: false, side_effects: false,
// switches: false, switches: false,
// top_retain: false, top_retain: false,
// toplevel: false, toplevel: false,
// typeofs: false, typeofs: false,
// unused: false, unused: false,
// conditionals: false, conditionals: false,
// dead_code: true, dead_code: true,
// evaluate: false, evaluate: false,
// warnings: false warnings: false
// }, },
// } }
// }) })
], ],
watch: true watch: true
}; };