Merge branch 'dev-view-likes-single-component' of rajukottedi/chirpy-blogging into dev
This commit is contained in:
commit
7059a5bee4
44
_includes/likes-views.html
Normal file
44
_includes/likes-views.html
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<style>
|
||||||
|
.heart-icon {
|
||||||
|
margin-bottom: -41px;
|
||||||
|
margin-right: -39.5px;
|
||||||
|
display: inline-flex;
|
||||||
|
width: 46px;
|
||||||
|
height: 46px;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
background: url("{{ '/assets/img/custom/heart.png' | relative_url }}") no-repeat;
|
||||||
|
background-position: 0 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heart-icon.liked {
|
||||||
|
animation: like-anim 0.7s steps(28) forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes like-anim {
|
||||||
|
to {
|
||||||
|
background-position: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
{% include views.html tooltip=true onload=false lang=lang %}
|
||||||
|
{% include likes.html tooltip=true onload=false lang=lang %}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const views = document.getElementById("views-count");
|
||||||
|
const likes = document.getElementById("likes-count");
|
||||||
|
const postLikesAndViews = document.getElementById("likes-views");
|
||||||
|
|
||||||
|
postLikesAndViews.style.display = "none";
|
||||||
|
|
||||||
|
ajax(serviceUrl + "/GetPostLikesAndViews?siteId=" + siteId + "&postId=" + postId)
|
||||||
|
.then(function (result) {
|
||||||
|
if (result != "N/A") {
|
||||||
|
var response = JSON.parse(result);
|
||||||
|
views.innerText = response.postViews;
|
||||||
|
likes.innerText = response.postLikes;
|
||||||
|
postLikesAndViews.style.display = "inline";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@ -1,5 +1,3 @@
|
|||||||
<!-- <link rel="stylesheet" href="{{ '/assets/css/heart.css' | relative_url }}"> -->
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.heart-icon {
|
.heart-icon {
|
||||||
margin-bottom: -41px;
|
margin-bottom: -41px;
|
||||||
@ -26,21 +24,14 @@
|
|||||||
|
|
||||||
<i class="heart-icon" {% if include.tooltip %} title="{{site.data.locales[include.lang].post.likes}}"
|
<i class="heart-icon" {% if include.tooltip %} title="{{site.data.locales[include.lang].post.likes}}"
|
||||||
data-bs-toggle="tooltip" data-bs-placement="bottom" {% endif %}></i>
|
data-bs-toggle="tooltip" data-bs-placement="bottom" {% endif %}></i>
|
||||||
{% include loader.html id="likes-loader" %}
|
|
||||||
<em id="likes-count"></em>
|
<em id="likes-count"></em>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const heartIcon = document.querySelector(".heart-icon");
|
const heartIcon = document.querySelector(".heart-icon");
|
||||||
const likesCount = document.getElementById("likes-count");
|
const likesCount = document.getElementById("likes-count");
|
||||||
const likesLoader = document.getElementById("likes-loader");
|
const likesOnLoad = "true";
|
||||||
|
|
||||||
likesLoader.style.display = "none";
|
|
||||||
|
|
||||||
let likesAmount = likesCount.innerHTML;
|
|
||||||
|
|
||||||
function onLoadAndClick() {
|
function onLoadAndClick() {
|
||||||
likesLoader.style.display = "inline-flex";
|
|
||||||
likesCount.style.display = "none";
|
|
||||||
heartIcon.style.pointerEvents = 'none';
|
heartIcon.style.pointerEvents = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,19 +44,15 @@
|
|||||||
heartIcon.classList.toggle("liked");
|
heartIcon.classList.toggle("liked");
|
||||||
}
|
}
|
||||||
likesCount.innerHTML = result;
|
likesCount.innerHTML = result;
|
||||||
likesLoader.style.display = "none";
|
|
||||||
likesCount.style.display = "inline-flex";
|
|
||||||
heartIcon.style.pointerEvents = 'auto';
|
heartIcon.style.pointerEvents = 'auto';
|
||||||
})
|
})
|
||||||
.catch(function () {
|
|
||||||
likesLoader.style.display = "none";
|
|
||||||
likesCount.style.display = "inline-flex";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var apiUrl = serviceUrl + "/GetPostLikes?siteId=" + siteId + "&postId=" + postId;
|
var apiUrl = serviceUrl + "/GetPostLikes?siteId=" + siteId + "&postId=" + postId;
|
||||||
|
|
||||||
|
if(likesOnLoad == "{{include.onload}}"){
|
||||||
apiCall(apiUrl);
|
apiCall(apiUrl);
|
||||||
|
}
|
||||||
|
|
||||||
heartIcon.addEventListener("click", () => {
|
heartIcon.addEventListener("click", () => {
|
||||||
if (!heartIcon.classList.contains("liked")) {
|
if (!heartIcon.classList.contains("liked")) {
|
||||||
@ -76,6 +63,4 @@
|
|||||||
|
|
||||||
apiCall(apiUrl, "click");
|
apiCall(apiUrl, "click");
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- <script src="{{ '/assets/js/likes.js' | relative_url }}"></script> -->
|
|
||||||
@ -1,27 +1,19 @@
|
|||||||
<i class="fa fa-eye fa-fw" {% if include.tooltip %} title="{{site.data.locales[include.lang].post.views}}"
|
<i class="fa fa-eye fa-fw" {% if include.tooltip %} title="{{site.data.locales[include.lang].post.views}}"
|
||||||
data-bs-toggle="tooltip" data-bs-placement="bottom" {% endif %}></i>
|
data-bs-toggle="tooltip" data-bs-placement="bottom" {% endif %}></i>
|
||||||
{% include loader.html id="views-loader" style="margin-right: 12px" %}
|
|
||||||
<em id="views-count" style="margin-right: 12px">
|
<em id="views-count" style="margin-right: 12px">
|
||||||
</em>
|
</em>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
const viewsOnLoad = "true";
|
||||||
|
if(viewsOnLoad == "{{include.onload}}"){
|
||||||
const viewsCount = document.getElementById("views-count");
|
const viewsCount = document.getElementById("views-count");
|
||||||
const viewsLoader = document.getElementById("views-loader");
|
const viewsLoader = document.getElementById("views-loader");
|
||||||
|
|
||||||
viewsCount.style.display = "none";
|
|
||||||
viewsLoader.style.display = "inline-block";
|
|
||||||
|
|
||||||
ajax(serviceUrl + "/GetPostViews?siteId=" + siteId + "&postId=" + postId)
|
ajax(serviceUrl + "/GetPostViews?siteId=" + siteId + "&postId=" + postId)
|
||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
viewsCount.innerText = result;
|
viewsCount.innerText = result;
|
||||||
viewsLoader.style.display = "none";
|
|
||||||
viewsCount.style.display = "inline-block";
|
|
||||||
})
|
})
|
||||||
.catch(function () {
|
.catch(function () {
|
||||||
viewsLoader.style.display = "none";
|
|
||||||
viewsCount.style.display = "inline-block";
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- <script src="{{ '/assets/js/views.js' | relative_url }}">
|
|
||||||
</script> -->
|
|
||||||
@ -33,9 +33,8 @@ tail_includes:
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- post counter -->
|
<!-- post counter -->
|
||||||
<div>
|
<div id="likes-views">
|
||||||
{% include views.html tooltip=true lang=lang %}
|
{% include likes-views.html tooltip=true lang=lang %}
|
||||||
{% include likes.html tooltip=true lang=lang %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user