mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 22:03:49 +01:00
using async await when is possible
This commit is contained in:
parent
084ea6373c
commit
9b1a445998
@ -13,16 +13,19 @@
|
|||||||
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async>
|
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async>
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
function update_file(filename) {
|
async function update_file(filename) {
|
||||||
var file=filename+'.dat';
|
var file=filename+'.dat';
|
||||||
var lnk_file=document.getElementById('lnk_file');
|
var lnk_file=document.getElementById('lnk_file');
|
||||||
lnk_file.setAttribute('href',getFullDataPath(file));
|
lnk_file.setAttribute('href',getFullDataPath(file));
|
||||||
data.load(file,onApplyData);
|
dat= await data.loadAsnyc(file);
|
||||||
|
await applyData(dat);
|
||||||
}
|
}
|
||||||
function onApplyData(dat) {
|
async function applyData(dat) {
|
||||||
const Cite = require('citation-js');
|
const Cite = require('citation-js');
|
||||||
const LatexInline=['\\(','\\)'];
|
// Start a async task to get publi
|
||||||
var par=document.getElementById("data_par");
|
let publitask = Cite.async(dat.doi.string)
|
||||||
|
const LatexInline=['\\(','\\)']
|
||||||
|
var par=document.getElementById("data_par")
|
||||||
par.innerHTML='';
|
par.innerHTML='';
|
||||||
var md=[];
|
var md=[];
|
||||||
var els=[];
|
var els=[];
|
||||||
@ -45,8 +48,9 @@
|
|||||||
par.appendChild(node);
|
par.appendChild(node);
|
||||||
|
|
||||||
});
|
});
|
||||||
var publi = new Cite(dat.doi.string)
|
|
||||||
var lnkdoi = document.createElement("a");
|
var lnkdoi = document.createElement("a");
|
||||||
|
// Wait for the value of publi when required
|
||||||
|
let publi=await publitask;
|
||||||
let output = publi.format('bibliography', {
|
let output = publi.format('bibliography', {
|
||||||
format: 'html',
|
format: 'html',
|
||||||
template: 'apa',
|
template: 'apa',
|
||||||
@ -67,7 +71,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label>Write a data file name without extension<br/>
|
<label>Write a data file name without extension<br/>
|
||||||
<input type="text" id='inp_filename' onkeydown="onKeyDown(event)"></input>
|
<input type="text" id='inp_filename' onkeydown="onKeyDown(e)"></input>
|
||||||
</label><br/>
|
</label><br/>
|
||||||
<p id=data_par></p>
|
<p id=data_par></p>
|
||||||
<a target="_blank" id='lnk_file' type='text/plain'>Go to file</a>
|
<a target="_blank" id='lnk_file' type='text/plain'>Go to file</a>
|
||||||
|
@ -70,18 +70,25 @@ class data {
|
|||||||
this.doi=null;
|
this.doi=null;
|
||||||
this.excitations=[];
|
this.excitations=[];
|
||||||
}
|
}
|
||||||
static load(file,fn) {
|
static async loadAsync(file) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.open("GET",getFullDataPath(file), true);
|
req.open("GET",getFullDataPath(file), true);
|
||||||
req.onreadystatechange = function() {
|
req.onreadystatechange = function() {
|
||||||
if (req.readyState == 4 && req.status == 200) {//when a good response is given do this
|
if (req.readyState == 4 && req.status == 200) {//when a good response is given do this
|
||||||
var text = req.responseText;
|
var text = req.responseText;
|
||||||
fn(data.loadstring(text));
|
resolve(data.loadString(text))
|
||||||
}
|
} else {
|
||||||
|
reject({
|
||||||
|
status: req.status,
|
||||||
|
statusText: req.statusText
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
req.send();
|
req.send();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
static loadstring(text) {
|
static loadString(text) {
|
||||||
// for each line with metadata
|
// for each line with metadata
|
||||||
var ismetaArea=true;
|
var ismetaArea=true;
|
||||||
//metadata RegExp (start with #; maybe somme spaces; : ; maybe somme space; datas)
|
//metadata RegExp (start with #; maybe somme spaces; : ; maybe somme space; datas)
|
||||||
|
Loading…
Reference in New Issue
Block a user