sokol-luajit/editor/www/partials/config_project_js.html

70 lines
1.9 KiB
HTML
Raw Normal View History

<!-- DataTables JavaScript -->
<script src="../js/dataTables/jquery.dataTables.min.js"></script>
<script src="../js/dataTables/dataTables.bootstrap.min.js"></script>
<!-- Page-Level Demo Scripts - Tables - Use for reference -->
<script>
function clickElem(elem) {
// Thx user1601638 on Stack Overflow (6/6/2018 - https://stackoverflow.com/questions/13405129/javascript-create-and-save-file )
var eventMouse = document.createEvent("MouseEvents")
eventMouse.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
elem.dispatchEvent(eventMouse)
}
function openFile(func) {
readFile = function(e) {
var file = e.target.files[0];
if (!file) {
return;
}
var fileobj = URL.createObjectURL(file);
console.log(fileobj);
var reader = new FileReader();
reader.onload = function(e) {
var jdata = { filename: file.name, filesize: file.size, data: e.target.result };
fileInput.func(jdata);
document.body.removeChild(fileInput)
}
reader.readAsBinaryString(file)
console.log(e.target.files);
}
fileInput = document.createElement("input")
fileInput.type='file'
fileInput.style.display='none'
fileInput.onchange=readFile
fileInput.func=func
document.body.appendChild(fileInput)
clickElem(fileInput)
}
function postData( url, data )
{
$.ajax({
type: 'POST',
url: url,
data: data,
success: function(data) { console.log("Posted data"); },
contentType: "application/json",
dataType: 'json'
});
}
$(document).ready(function () {
$('#openAsset').on("click", function(evt){
openFile(function( data ) {
var pdata = JSON.stringify(data);
console.log(pdata);
postData("/world/assets/loaddata", pdata );
});
});
$('#dataTables-example').DataTable({
responsive: true
});
});
</script>