39 lines
1.5 KiB
Plaintext
39 lines
1.5 KiB
Plaintext
<script>
|
|
function load_comment(){
|
|
if(!document.getElementById("waline_container"))return;
|
|
utils.css('<%- theme.comments.waline.css %>');
|
|
utils.js('<%- theme.comments.waline.js %>', {defer:true}).then(function () {
|
|
const el = document.getElementById("waline_container");
|
|
var path = el.getAttribute('comment_id');
|
|
if (!path) {
|
|
path = decodeURI(window.location.pathname);
|
|
}
|
|
Waline.init(Object.assign(<%- JSON.stringify(theme.comments.waline) %>, {
|
|
el: '#waline_container',
|
|
path: path,
|
|
<% if(!!theme.comments.waline.imageUploader?.api){ %>
|
|
imageUploader: function(file) {
|
|
let headers = new Headers();
|
|
headers.set('Accept', 'application/json');
|
|
<% if(!!theme.comments.waline.imageUploader?.token) { %>
|
|
headers.set('<%= theme.comments.waline.imageUploader?.tokenName %>', '<%= theme.comments.waline.imageUploader?.token %>')
|
|
<% } %>
|
|
let formData = new FormData();
|
|
formData.append('<%= theme.comments.waline.imageUploader?.fileName %>', file);
|
|
return fetch('<%= theme.comments.waline.imageUploader?.api %>',{
|
|
method: 'POST',
|
|
body: formData,
|
|
headers: headers
|
|
}).then((resp) => resp.json())
|
|
.then((resp) => resp.<%= theme.comments.waline.imageUploader?.resp %>)
|
|
},
|
|
<% } %>
|
|
}));
|
|
});
|
|
}
|
|
window.addEventListener('DOMContentLoaded', (event) => {
|
|
load_comment();
|
|
});
|
|
|
|
</script>
|