10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2025-01-11 21:48:30 +01:00

JQuerysation of file viewer

This commit is contained in:
Mickaël Véril 2020-01-29 10:56:50 +01:00
parent 7303e6bc98
commit 27df5105e6

View File

@ -3,67 +3,66 @@ title: "view"
date: 2019-08-29 09:00 date: 2019-08-29 09:00
draft: false draft: false
--- ---
<script src="/js/getFullDataPath.js" type="text/javascript"></script> <script src="/js/getFullDataPath.js" type="text/javascript"></script>
<script src="/js/getTextFromFile.js" type="text/javascript"></script> <script src="/js/getTextFromFile.js" type="text/javascript"></script>
<script src="/js/downloadData.js" type="text/javascript"></script> <script src="/js/downloadData.js" type="text/javascript"></script>
<script src="/js/Base64ToBlob.js" type="text/javascript"></script> <script src="/js/Base64ToBlob.js" type="text/javascript"></script>
<script> <script>
window.onload=async function(){ window.onload = async function () {
if(typeof(navigator.clipboard) == 'undefined' || typeof(navigator.clipboard.writeText) === 'undefined'){ if (typeof (navigator.clipboard) == 'undefined' || typeof (navigator.clipboard.writeText) === 'undefined') {
btn_clip=document.getElementById("btn_clip"); btn_clip = document.getElementById("btn_clip");
btn_clip.disabled = true; btn_clip.disabled = true;
var browsers= {}; var browsers = {};
browsers["Chromium"]="https://chromium.woolyss.com/download"; browsers["Chromium"] = "https://chromium.woolyss.com/download";
browsers["Firefox"]="https://www.mozilla.org/fr/firefox"; browsers["Firefox"] = "https://www.mozilla.org/fr/firefox";
var recomsting="We recomend to use Firefox or a Chromium based browser like Google Chrome"; var recomsting = "We recomend to use Firefox or a Chromium based browser like Google Chrome";
btn_clip.title='This feature is not supported in this bowser\n'+recomsting; btn_clip.title = 'This feature is not supported in this bowser\n' + recomsting;
var mystr='navigator.clipboard.writeText() not supported in this browser\n'+recomsting; var mystr = 'navigator.clipboard.writeText() not supported in this browser\n' + recomsting;
for(var key in browsers) { for (var key in browsers) {
mystr+="\n"+String.raw`Download ${key} : ${browsers[key]}`; mystr += "\n" + String.raw`Download ${key} : ${browsers[key]}`;
} }
console.warn(mystr); console.warn(mystr);
} }
var params=new URL(window.location.href).searchParams var params = new URL(window.location.href).searchParams
var key=["file","fileBase64"] var key = ["file", "fileBase64"]
if(params.has(key[0])){ if (params.has(key[0])) {
var filename=params.get(key[0]); var filename = params.get(key[0]);
var textPromise=getTextFromFileUrlAsync(filename) var textPromise = getTextFromFileUrlAsync(filename)
$("#btn_download").click(function(){ $("#btn_download").click(function () {
window.open(filename,"_self"); window.open(filename, "_self");
}) })
$('#fileTitle').text(filename); $('#fileTitle').text(filename);
$('#fileContent').text(await textPromise) $('#fileContent').text(await textPromise)
$('#file').show(); $('#file').show();
$("#div_btn").show(); $("#div_btn").show();
} else if(params.has(key[1])){ } else if (params.has(key[1])) {
var base64=params.get(key[1]); var base64 = params.get(key[1]);
$("#btn_download").click(function(){ $("#btn_download").click(function () {
const blob=base64ToBlob(base64,"text/plain") const blob = base64ToBlob(base64, "text/plain")
downloadData(blob,"file.dat") downloadData(blob, "file.dat")
}) })
document.getElementById('fileTitle').hudden=true $('#fileTitle').hide()
document.getElementById('fileContent').innerText=atob(base64) $('#fileContent').text(atob(base64))
document.getElementById('file').hidden=false; $('file').show();
document.getElementById("div_btn").hidden=false; $("div_btn").show()
} }
else{ else {
document.getElementById('error_P').hidden=false; $('#error_P').show()
errNode; errNode;
} }
} }
</script> </script>
<script> <script>
function Copy() function Copy() {
{ navigator.clipboard.writeText($('#fileContent').text());
navigator.clipboard.writeText(document.getElementById('fileContent').innerText); };
};
</script> </script>
</script> </script>
</script> </script>
<div> <div>
<p id="error_P" style="color: red; font-weight: bold" hidden=true> <p id="error_P" style="color: red; font-weight: bold" hidden=true>
Error Error
</p> </p>
@ -71,8 +70,8 @@ draft: false
<h2 id="fileTitle"></h2> <h2 id="fileTitle"></h2>
<pre id="fileContent"></pre> <pre id="fileContent"></pre>
</div> </div>
</div> </div>
<div id="div_btn" hidden=true> <div id="div_btn" hidden=true>
<button id="btn_clip" onclick="Copy()">Copy content</button> <button id="btn_clip" onclick="Copy()">Copy content</button>
<button id='btn_download'>Download</button> <button id='btn_download'>Download</button>
</div> </div>