A javascript like with cookies and ajax possibility
- Require:
const likes = require('cadot-info-like')
const likes = require("cadot-info-like");
likes.init();
for default config (described after)
you can define your parameters by
likes.init(class of button, link...,text or image for like, same for not like, id for counter )
Default value:
- class of button: likes
- text: i like
- text: i don't like
- counter (optional): counter
For example, you can use with font-awesome
likes.init(
"likesButton",
"<i class='fas fa-thumbs-up'></i>",
"<i class='fas fa-thumbs-down'></i>",
"counterGlobal"
);
with default parameters
<h1>Counter likes</h1>
<p id="counter">0</p>
<ul>
<li><a class="likes" data-id="1" href="#"></a></li>
<li><a class="likes" data-id="2" href="#"></a></li>
<li><a class="likes" data-id="3" href="#"></a></li>
<li><a class="likes" data-id="4" href="#"></a></li>
</ul>
- If you want send your list of likes at your server ou can send by get
#likesSend
is the id of button or a for acces at your favorites example of result is/mes-favoris?liste=9,8
$("#likesSend").on("click", function (event) {
event.preventDefault();
if (document.cookie == undefined) return false;
let field = document.cookie
.split("; ")
.find((row) => row.startsWith("likes="));
if (field == undefined) return false;
let favoris = JSON.parse(field.split("=")[1]);
window.location.href = "/mes-favoris?liste=" + favoris;
});
- You can block the changement of text.
Add nochange ... class="likes" nochange date-id="3" id="...
please give issues or Pull Request in github ;-)
Unless stated otherwise all works are:
- Copyright © 2021+ Cadot.info ltd
and licensed under: