39 lines
1.2 KiB
HTML
39 lines
1.2 KiB
HTML
<i class="fa fa-eye fa-fw me-1" {% if include.tooltip %} title="{{site.data.locales[include.lang].post.views}}"
|
|
data-bs-toggle="tooltip" data-bs-placement="bottom" {% endif %}></i>
|
|
{% include loader.html id="views-loader" %}
|
|
<em id="views-count" style="margin-right: 12px">
|
|
</em>
|
|
|
|
<script>
|
|
const viewsCount = document.getElementById("views-count");
|
|
const viewsLoader = document.getElementById("views-loader");
|
|
|
|
viewsCount.style.display = "none";
|
|
viewsLoader.style.display = "inline-block"
|
|
|
|
function ajax(url) {
|
|
return new Promise(function (resolve, reject) {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.onload = function () {
|
|
resolve(this.responseText);
|
|
};
|
|
xhr.onerror = reject;
|
|
xhr.open('GET', url);
|
|
xhr.send();
|
|
});
|
|
}
|
|
|
|
var siteId = "{{ site.id }}";
|
|
var postId = "{{ page.title }}";
|
|
|
|
ajax("{{site.custom-config.blog-services.service_url}}/GetPostViews?siteId=" + siteId + "&postId=" + postId)
|
|
.then(function (result) {
|
|
console.log(result); // Code depending on result
|
|
viewsCount.innerText = result;
|
|
viewsLoader.style.display = "none";
|
|
viewsCount.style.display = "inline-block";
|
|
})
|
|
.catch(function () {
|
|
// An error occurred
|
|
});
|
|
</script> |