84 lines
No EOL
2.5 KiB
JavaScript
84 lines
No EOL
2.5 KiB
JavaScript
function autoExpand (field) {
|
|
xpos=window.scrollX;
|
|
ypos=window.scrollY;
|
|
|
|
field.style.height = 'inherit';
|
|
|
|
var computed = window.getComputedStyle(field);
|
|
|
|
var height = parseInt(computed.getPropertyValue('border-top-width'), 10)
|
|
+ parseInt(computed.getPropertyValue('padding-top'), 10)
|
|
+ field.scrollHeight
|
|
+ parseInt(computed.getPropertyValue('padding-bottom'), 10)
|
|
+ parseInt(computed.getPropertyValue('border-bottom-width'), 10)
|
|
+ 32;
|
|
|
|
field.style.height = height + 'px';
|
|
|
|
window.scrollTo(xpos,ypos);
|
|
};
|
|
|
|
document.addEventListener('input', function (event) {
|
|
if (event.target.tagName.toLowerCase() !== 'textarea') return;
|
|
autoExpand(event.target);
|
|
}, false);
|
|
|
|
function formkey() {
|
|
let formkey = document.getElementById("formkey")
|
|
if (formkey) return formkey.innerHTML;
|
|
else return null;
|
|
}
|
|
|
|
if (typeof bs_trigger === 'undefined') {
|
|
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
|
tooltipTriggerList.map(function(element){
|
|
return bootstrap.Tooltip.getOrCreateInstance(element);
|
|
});
|
|
}
|
|
|
|
function post_toast(t, url, reload, data) {
|
|
t.disabled = true;
|
|
t.classList.add("disabled");
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open("POST", url);
|
|
xhr.setRequestHeader('xhr', 'xhr');
|
|
var form = new FormData()
|
|
form.append("formkey", formkey());
|
|
|
|
if(typeof data === 'object' && data !== null) {
|
|
for(let k of Object.keys(data)) {
|
|
form.append(k, data[k]);
|
|
}
|
|
}
|
|
|
|
xhr.onload = function() {
|
|
let data
|
|
try {data = JSON.parse(xhr.response)}
|
|
catch(e) {console.log(e)}
|
|
if (xhr.status >= 200 && xhr.status < 300 && data && data['message']) {
|
|
document.getElementById('toast-post-success-text').innerText = data["message"];
|
|
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show();
|
|
if (reload == 1) {location.reload()}
|
|
} else {
|
|
document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
|
|
if (data && data["error"]) document.getElementById('toast-post-error-text').innerText = data["error"];
|
|
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error')).show();
|
|
}
|
|
setTimeout(() => {
|
|
t.disabled = false;
|
|
t.classList.remove("disabled");
|
|
}, 2000);
|
|
};
|
|
|
|
xhr.send(form);
|
|
|
|
}
|
|
|
|
function changename(s1,s2) {
|
|
let files = document.getElementById(s2).files;
|
|
let filename = '';
|
|
for (const e of files) {
|
|
filename += e.name.substr(0, 20) + ', ';
|
|
}
|
|
document.getElementById(s1).innerHTML = filename.slice(0, -2);
|
|
} |