Today we will see how to add custom like and comment functionality in SharePoint custom pages. For that I have developed one common web part/txt file using JQuery and REST api. Currently SharePoint is providing likes and rating functionality for the list items. I tried to use this but this was not required so I tried to develop this custom functionality for SharePoint online pages.
You need to just add one content editor web part and add the below code into that web part. Below are the overall steps.
Step 1
Create custom list in SharePoint having name "LikesList" to store all the likes given by the user. Add the below columns into it,
- column name : LikeBy type : Person or Group
- column name : CommentID type : Number
- column name : PageURL type : Single line of text
Step 2
Create custom list in SharePoint having the name "CommentsList" to store all the comments added by user. Add the below columns into it,
- column name : ParentCommentID type : Number
- column name : CommentText type : Multiple lines of text
- column name : PageURL type : Single line of text
- column name : CommentBy type : Person or Group
Step 3
Now create one text file and add the below code into it and save that file.
- <div style="width: 70%;background-color: white;color: black; border-radius: 5px; padding:10px;">
- <table style="width:100%">
- <tbody>
- <tr>
- <td style="text-align: right;">
- <span id="lblPageComments">0 Comments | </span>
- <span id="spLikes" title="" class="LikeClass">
- <img id="imgLike" src="../_layouts/15/images/LikeFull.11x11x32.png?rev=23">
- <span id="lblPageLikes">0</span>
- </span>
- <a id="lnkBtnPageLike" class="links">Like</a>
- <span id="LikeID" style="display:none;"></span> </td>
- </tr>
- <tr>
- <td style="padding-left: 5px;">
- <h3>Comment : </h3>
- </td>
- </tr>
- <tr>
- <td style="padding: 25px;">
- <textarea name="txtComments" rows="3" cols="20" id="txtComments" placeholder="Comment..." style="width:95%;"></textarea><br><br>
- <input type="button" name="btnPost" value="Post" id="btnPost">
- <input type="button" name="btnReset" value="Reset" id="btnReset">
- </td>
- </tr>
- </tbody>
- </table>
- <br> Comments... <table id="tblComments" style="width:100%">
- </table>
- </div>
- <style type="text/css">
- a {
- cursor: pointer;
- }
- </style>
- <script src="/JS/jquery.min.js"></script>
- <script src="/JS/jquery-ui.js"></script>
- <link rel="stylesheet" href="/CSS/jquery-ui.css">
- <script src="JS/jquery-dateFormat.min.js"></script>
- <script type="text/javascript">
- var PageURL = window.location.href;
- var UserID = _spPageContextInfo.userId;
- $(document).ready(function() {
- getSetPageDet();
- getAllComments();
- $("#btnPost").click(function() {
- AddComment();
- });
- $("#btnReset").click(function() {
- $("#txtComments").val("");
- });
- $("#lnkBtnPageLike").click(function() {
- if ($("#lnkBtnPageLike")[0].innerText == "Like") {
- LikePage();
- } else {
- UnLikePage();
- }
- });
- });
-
- function reset(textbox) {
- $("#txtReply_" + textbox).val("");
- }
-
- function getAllComments() {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items?$expand=CommentBy&$select=*,CommentBy/Title&$filter=PageURL eq '" + PageURL + "' and Title eq 'Comment'&$orderby=ID desc",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- var commentsHTML = "";
- if (data.d.results.length > 0) {
- $.each(data.d.results, function(index, value) {
- var CreatedDate = jQuery.format.date(value.Created, "ddd, MMM d, yyyy h:mm a");
- commentsHTML += "<tr><td><span id='CommentsID_" + value.Id + "' style='display:none;'>" + value.Id + "</span><br><span>" + value.CommentText + "</span><br><a class='linksAuthor' href='/../../_layouts/15/userdisp.aspx?ID=" + value.CommentById + "' target='_blank'>" + value.CommentBy.Title + "</a><br><span>" + CreatedDate + "</spam> <span id='lblCommentReplies_" + value.Id + "'>0 Replies | </span><span id='spLikes_" + value.Id + "' title='' class='LikeClass'> <img src='../_layouts/15/images/LikeFull.11x11x32.png?rev=23'> <span id='lblLikes_" + value.Id + "' class='LikeClass'>0</span></span> <a id='lnkBtnLike_" + value.Id + "' class='links' onClick='LikeComment(" + value.Id + ")'>Like</a><span id='LikeID_" + value.Id + "' style='display:none;'></span>";
- if (UserID == value.CommentById) {
- commentsHTML += " <a id='lnkBtnDelete_" + value.Id + "' class='links' onClick='DeleteComment(" + value.Id + ")'>Delete</a><br><br>Replies...<br><div style='margin-left: 10%;'><table style='width: 90%'><tbody><tr><td colspan='2'><textarea name='txtReply_" + value.Id + "' rows='1' cols='20' id='txtReply_" + value.Id + "' placeholder='Reply...' style='width:100%;'></textarea><br><br><input type='button' name='btnPostReply_" + value.Id + "' value='Post' id='btnPostReply_" + value.Id + "' onClick='AddReply(" + value.Id + ")'><input type='button' name='btnResetReply_" + value.Id + "' value='Reset' id='btnResetReply_" + value.Id + "' onClick='reset(" + value.Id + ")'></td></tr></tbody></table><div><table cellspacing='0' id='tblReply_" + value.Id + "' style='border-collapse:collapse;'></table></div></div><br><hr></td></tr>";
- } else {
- commentsHTML += "<br><br>Replies...<br><div style='margin-left: 10%;'><table style='width: 90%'><tbody><tr><td colspan='2'><textarea name='txtReply_" + value.Id + "' rows='1' cols='20' id='txtReply_" + value.Id + "' placeholder='Reply...' style='width:100%;'></textarea><br><br><input type='button' name='btnPostReply_" + value.Id + "' value='Post' id='btnPostReply_" + value.Id + "' onClick='AddReply(" + value.Id + ")'><input type='button' name='btnResetReply_" + value.Id + "' value='Reset' id='btnResetReply_" + value.Id + "' onClick='reset(" + value.Id + ")'></td></tr></tbody></table><div><table cellspacing='0' id='tblReply_" + value.Id + "' style='border-collapse:collapse;'></table></div></div><br><hr></td></tr>";
- }
- });
- $("#tblComments")[0].innerHTML = commentsHTML;
- getSetCommentDet();
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- }
-
- function LikeReply(CommentID) {
- var title = "Reply";
- if ($("#lnkBtnReplyLike_" + CommentID)[0].innerText == "Like") {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items",
- type: "POST",
- data: JSON.stringify({
- '__metadata': {
- 'type': 'SP.Data.LikesListListItem'
- },
- 'LikeById': UserID,
- 'Title': title,
- 'CommentID': CommentID
- }),
- headers: {
- "accept": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- $("#lnkBtnReplyLike_" + CommentID)[0].innerText = "Unlike";
- },
- error: function(error) {
- console.log(JSON.stringify(error));
- }
- });
- } else {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items(" + $("#ReplyLikeID_" + CommentID)[0].innerText + ")",
- type: "POST",
- async: false,
- headers: {
- "Accept": "application/json;odata=verbose",
- "X-Http-Method": "DELETE",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "If-Match": "*"
- },
- success: function(data) {
- $("#lnkBtnReplyLike_" + CommentID)[0].innerText = "Like";
- getSetPageDet();
- getAllComments();
- },
- error: function(data) {
- console.log(JSON.stringify(error));
- }
- });
- }
- }
-
- function LikeComment(CommentID) {
- var title = "Comment";
- if ($("#lnkBtnLike_" + CommentID)[0].innerText == "Like") {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items",
- type: "POST",
- data: JSON.stringify({
- '__metadata': {
- 'type': 'SP.Data.LikesListListItem'
- },
- 'LikeById': UserID,
- 'Title': title,
- 'CommentID': CommentID
- }),
- headers: {
- "accept": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- $("#lnkBtnLike_" + CommentID)[0].innerText = "Unlike";
- },
- error: function(error) {
- console.log(JSON.stringify(error));
- }
- });
- } else {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items(" + $("#LikeID_" + CommentID)[0].innerText + ")",
- type: "POST",
- async: false,
- headers: {
- "Accept": "application/json;odata=verbose",
- "X-Http-Method": "DELETE",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "If-Match": "*"
- },
- success: function(data) {
- $("#lnkBtnLike_" + CommentID)[0].innerText = "Like";
- getSetPageDet();
- getAllComments();
- },
- error: function(data) {
- console.log(JSON.stringify(error));
- }
- });
- }
- }
-
- function getSetCommentDet() {
- var commentIDColl = $('span[id^="CommentsID_"]');
- $.each(commentIDColl, function(index, e) {
- var commentID = e.innerText;
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$filter=LikeById eq " + UserID + " and CommentID eq '" + commentID + "'",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- $("#lnkBtnLike_" + commentID)[0].innerText = "Unlike";
- $("#LikeID_" + commentID)[0].innerText = data.d.results[0].Id;
- } else {
- $("#lnkBtnLike_" + commentID)[0].innerText = "Like";
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$expand=LikeBy&$select=*,LikeBy/Title&$filter=CommentID eq '" + commentID + "' and Title eq 'Comment'&$orderby=ID desc",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- var likeToolTip = "";
- var me = false;
- $("#lblLikes_" + commentID)[0].innerText = data.d.results.length;
- $.each(data.d.results, function(index, value) {
- if (value.LikeById == UserID) {
- me = true;
- } else {
- likeToolTip += value.LikeBy.Title + "; ";
- }
- });
- if (me == true) {
- likeToolTip = "You; " + likeToolTip;
- }
- $("span#spLikes_" + commentID).attr("title", likeToolTip);
- } else {
- $("#lblLikes_" + commentID)[0].innerText = "0";
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items?$expand=CommentBy&$select=*,CommentBy/Title&$filter=ParentCommentID eq '" + commentID + "' and Title eq 'Reply'&$orderby=ID desc",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- $("#lblCommentReplies_" + commentID)[0].innerText = data.d.results.length + " Replies |";
- var replyHTML = "";
- if (data.d.results.length > 0) {
- $.each(data.d.results, function(index, value) {
- var CreatedDate = jQuery.format.date(value.Created, "ddd, MMM d, yyyy h:mm a");
- replyHTML += "<tr><td><br><span id='ReplyID_" + value.Id + "' style='display:none;'>" + value.Id + "</span><br><span id='lblReply_" + value.Id + "' class='comments'>" + value.CommentText + "</span><br><a id='hrfReplyAuthor_" + value.Id + "' class='linksAuthor' href='/../../_layouts/15/userdisp.aspx?ID=" + value.CommentById + "' target='_blank'>" + value.CommentBy.Title + "</a><br><span id='lblReplydate_" + value.Id + "'>" + CreatedDate + "</span> <span id='spReplyLikes_" + value.Id + "' title='' class='LikeClass'> <img id='imgLike_" + value.Id + "' src='../_layouts/15/images/LikeFull.11x11x32.png?rev=23'> <span id='lblReplyLikes_" + value.Id + "' title='' class='LikeClass' ></span></span> <a id='lnkBtnReplyLike_" + value.Id + "' class='links' onClick='LikeReply(" + value.Id + ")'>Like</a><span id='ReplyLikeID_" + value.Id + "' style='display:none;'></span>";
- if (UserID == value.CommentById) {
- replyHTML += " <a id='lnkBtnDelete_" + value.Id + "' class='links' onClick='DeleteReply(" + value.Id + ")'>Delete</a></td></tr>";
- } else {
- replyHTML += "</td></tr>";
- }
- });
- $("#tblReply_" + commentID)[0].innerHTML = replyHTML;
- getSetReplyDet();
- }
- } else {
- $("#lblCommentReplies_" + commentID)[0].innerText = "0 Replies |";
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- })
- }
-
- function getSetPageDet() {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$filter=LikeById eq " + UserID + " and PageURL eq '" + PageURL + "'",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- $("#lnkBtnPageLike")[0].innerText = "Unlike";
- $("#LikeID")[0].innerText = data.d.results[0].Id;
- } else {
- $("#lnkBtnPageLike")[0].innerText = "Like";
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$expand=LikeBy&$select=*,LikeBy/Title&$filter=PageURL eq '" + PageURL + "' and Title eq 'Page'",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- var likeToolTip = "";
- var me = false;
- $("#lblPageLikes")[0].innerText = data.d.results.length;
- $.each(data.d.results, function(index, value) {
- if (value.LikeById == UserID) {
- me = true;
- } else {
- likeToolTip += value.LikeBy.Title + "; ";
- }
- });
- if (me == true) {
- likeToolTip = "You; " + likeToolTip;
- }
- $("span#spLikes").attr("title", likeToolTip);
- } else {
- $("#lblPageLikes")[0].innerText = "0";
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items?$filter=PageURL eq '" + PageURL + "' and Title eq 'Comment'",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- $("#lblPageComments")[0].innerText = data.d.results.length + " Comments |";
- } else {
- $("#lblPageComments")[0].innerText = "0 Comments |";
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- }
-
- function AddComment() {
- var title = "Comment";
- var ParentCommentID = 0;
- var CommentText = $("#txtComments").val();
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items",
- type: "POST",
- data: JSON.stringify({
- '__metadata': {
- 'type': 'SP.Data.CommentsListListItem'
- },
- 'PageURL': PageURL,
- 'CommentById': UserID,
- 'Title': title,
- 'ParentCommentID': ParentCommentID,
- 'CommentText': CommentText
- }),
- headers: {
- "accept": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- $("#txtComments").val("");
- getSetPageDet();
- getAllComments();
- },
- error: function(error) {
- console.log(JSON.stringify(error));
- }
- });
- }
-
- function AddReply(CommentID) {
- var title = "Reply";
- var CommentText = $("#txtReply_" + CommentID).val();
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items",
- type: "POST",
- data: JSON.stringify({
- '__metadata': {
- 'type': 'SP.Data.CommentsListListItem'
- },
- 'CommentById': UserID,
- 'Title': title,
- 'ParentCommentID': CommentID,
- 'CommentText': CommentText
- }),
- headers: {
- "accept": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- getSetPageDet();
- getAllComments();
- },
- error: function(error) {
- console.log(JSON.stringify(error));
- }
- });
- }
-
- function LikePage() {
- var title = "Page";
- var CommentID = 0;
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items",
- type: "POST",
- data: JSON.stringify({
- '__metadata': {
- 'type': 'SP.Data.LikesListListItem'
- },
- 'PageURL': PageURL,
- 'LikeById': UserID,
- 'Title': title,
- 'CommentID': CommentID
- }),
- headers: {
- "accept": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- $("#lnkBtnPageLike")[0].innerText = "Unlike";
- getSetPageDet();
- getAllComments();
- },
- error: function(error) {
- console.log(JSON.stringify(error));
- }
- });
- }
-
- function UnLikePage() {
- var title = "Page";
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items(" + $("#LikeID")[0].innerText + ")",
- type: "POST",
- async: false,
- headers: {
- "Accept": "application/json;odata=verbose",
- "X-Http-Method": "DELETE",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "If-Match": "*"
- },
- success: function(data) {
- $("#lnkBtnPageLike")[0].innerText = "Like";
- },
- error: function(data) {
- console.log(JSON.stringify(error));
- getSetPageDet();
- getAllComments();
- }
- });
- }
-
- function DeleteReply(CommentID) {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items(" + CommentID + ")",
- type: "POST",
- async: false,
- headers: {
- "Accept": "application/json;odata=verbose",
- "X-Http-Method": "DELETE",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "If-Match": "*"
- },
- success: function(data) {
- DeleteChildItems(CommentID);
- console.log("Comment deleted successfully!");
- getSetPageDet();
- getAllComments();
- },
- error: function(data) {
- console.log(JSON.stringify(error));
- }
- });
- }
-
- function DeleteComment(CommentID) {
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('CommentsList')/items(" + CommentID + ")",
- type: "POST",
- async: false,
- headers: {
- "Accept": "application/json;odata=verbose",
- "X-Http-Method": "DELETE",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "If-Match": "*"
- },
- success: function(data) {
- DeleteChildItems(CommentID);
- console.log("Comment deleted successfully!");
- getSetPageDet();
- getAllComments();
- },
- error: function(data) {
- console.log(JSON.stringify(error));
- }
- });
- }
-
- function DeleteChildItems(parentId) {
- getItemsfromURL("/_api/web/lists/GetByTitle('LikesList')/items?$filter=CommentID eq " + parentId).done(function(data) {
- data.d.results.forEach(function(item) {
- var childId = item.ID;
- deleteItem("/_api/web/lists/GetByTitle('LikesList')/getItemById(" + childId + ")", item).done(function(d_data) {
-
- });
- });
- });
- getItemsfromURL("/_api/web/lists/GetByTitle('CommentsList')/items?$filter=ParentCommentID eq " + parentId).done(function(data) {
- data.d.results.forEach(function(item) {
- var childReplyId = item.ID;
- deleteItem("/_api/web/lists/GetByTitle('CommentsList')/getItemById(" + childReplyId + ")", item).done(function(d_data) {
-
- });
- getItemsfromURL("/_api/web/lists/GetByTitle('LikesList')/items?$filter=CommentID eq " + childReplyId).done(function(data) {
- data.d.results.forEach(function(item) {
- var childLikeId = item.ID;
- deleteItem("/_api/web/lists/GetByTitle('LikesList')/getItemById(" + childLikeId + ")", item).done(function(d_data) {
-
- });
- });
- });
- });
- });
- }
-
- function getItemsfromURL(url) {
- return $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + url,
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- }
- });
- }
-
- function deleteItem(url, oldItem) {
- return $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + url,
- type: "DELETE",
- headers: {
- "accept": "application/json;odata=verbose",
- "X-RequestDigest": $("#__REQUESTDIGEST").val(),
- "If-Match": oldItem.__metadata.etag
- }
- });
- }
-
- function getSetReplyDet() {
- var commentIDColl = $('span[id^="ReplyID_"]');
- $.each(commentIDColl, function(index, e) {
- var commentID = e.innerText;
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$filter=LikeById eq " + UserID + " and CommentID eq '" + commentID + "'",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- $("#lnkBtnReplyLike_" + commentID)[0].innerText = "Unlike";
- $("#ReplyLikeID_" + commentID)[0].innerText = data.d.results[0].Id;
- } else {
- $("#lnkBtnReplyLike_" + commentID)[0].innerText = "Like";
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- $.ajax({
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('LikesList')/items?$expand=LikeBy&$select=*,LikeBy/Title&$filter=CommentID eq '" + commentID + "' and Title eq 'Reply'",
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose",
- "content-Type": "application/json;odata=verbose"
- },
- success: function(data) {
- if (data.d.results.length > 0) {
- var likeToolTip = "";
- var me = false;
- $("#lblReplyLikes_" + commentID)[0].innerText = data.d.results.length;
- $.each(data.d.results, function(index, value) {
- if (value.LikeById == UserID) {
- me = true;
- } else {
- likeToolTip += value.LikeBy.Title + "; ";
- }
- });
- if (me == true) {
- likeToolTip = "You; " + likeToolTip;
- }
- $("span#spReplyLikes_" + commentID).attr("title", likeToolTip);
- } else {
- $("#lblReplyLikes_" + commentID)[0].innerText = "0";
- }
- },
- error: function(error) {
- alert(JSON.stringify(error));
- }
- });
- })
- }
- </script>
Step 4
Create one web part page add your contents in to it. Add one more content editor web part -> edit web part -> give path of the txt file-> click on apply -> click on ok-> save the page -> publish it.
Step 5
After publishing the page you will see a comment box to add the comments and a like button to like the particular page.
Step 6
You can add the above code into any web part page using content editor and you will see the above functionality is working.