PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.9
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.9
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / assets / js / theme-builder-comments.js

theme-builder-comments.js in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.9, at assets/js/theme-builder-comments.js

233 lines 11.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(){
2 (function($) {
3 "use strict";
4 jQuery(document).ready(function($) {
5 "use strict";
6 function jltma_setCookie(cname, cvalue, exdays) {
7 var d = /* @__PURE__ */ new Date();
8 d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3);
9 var expires = "expires=" + d.toUTCString();
10 document.cookie = cname + "=" + cvalue + "; " + expires;
11 }
12 function jltma_get_Cookies(cname) {
13 var name = cname + "=";
14 var ca = document.cookie.split(";");
15 for (var i = 0; i < ca.length; i++) {
16 var c = ca[i];
17 while (c.charAt(0) == " ") c = c.substring(1);
18 if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
19 }
20 return "";
21 }
22 function jltma_deleteCookie(name) {
23 document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT;";
24 }
25 function like_dislike_Cookies(trigger_type, comment_id, $this, not_trigger_type) {
26 var jltma_like_cookie = jltma_get_Cookies("jltma_like_" + comment_id);
27 var jltma_dislike_cookie = jltma_get_Cookies("jltma_dislike_" + comment_id);
28 if ($this.hasClass("jltma-like-trigger")) {
29 $(".jltma-dislike-trigger", $this.closest(".jltma-like-dislike-wrapper")).removeClass("jltma-already-disliked");
30 $this.addClass("jltma-already-liked");
31 }
32 if ($this.hasClass("jltma-dislike-trigger")) {
33 $(".jltma-like-trigger", $this.closest(".jltma-like-dislike-wrapper")).removeClass("jltma-already-liked");
34 $this.addClass("jltma-already-disliked");
35 }
36 $.ajax({
37 type: "post",
38 url: jltma_localize_comments_data.ajax_url,
39 data: {
40 comment_id,
41 jltma_like_cookie,
42 jltma_dislike_cookie,
43 action: "jltma_like_dislike",
44 type: trigger_type,
45 _wpnonce: jltma_localize_comments_data.ajax_nonce
46 },
47 beforeSend: function(xhr) {},
48 success: function(res) {
49 res = $.parseJSON(res);
50 var cookie_name = "jltma_" + trigger_type + "_" + comment_id;
51 jltma_deleteCookie("jltma_" + not_trigger_type + "_" + comment_id);
52 jltma_setCookie(cookie_name, 1, 365);
53 var latest_like_count = res.latest_like_count;
54 var latest_dislike_count = res.latest_dislike_count;
55 $("#jltma-like-count-" + comment_id).html(latest_like_count);
56 $("#jltma-dislike-count-" + comment_id).html(latest_dislike_count);
57 }
58 });
59 }
60 $("body").on("click", ".jltma-like-dislike-trigger", function(e) {
61 e.preventDefault();
62 var $this = $(this), comment_id = $(this).data("comment-id"), trigger_type = $(this).data("trigger-type"), jltma_like_cookie = jltma_get_Cookies("jltma_like_" + comment_id), jltma_dislike_cookie = jltma_get_Cookies("jltma_dislike_" + comment_id), current_like_count = $this.closest(".jltma-like-dislike-wrapper").find(".jltma-like-count-wrap").html(), current_dislike_count = $this.closest(".jltma-like-dislike-wrapper").find(".jltma-dislike-count-wrap").html();
63 if (trigger_type == "like" && jltma_like_cookie == "") {
64 if (!$this.hasClass("jltma-dislike-trigger")) {
65 var cookie_name = "jltma_" + trigger_type + "_" + comment_id;
66 jltma_setCookie(cookie_name, 1, 365);
67 if (jltma_dislike_cookie == "") {
68 var end_character = current_like_count.slice(-1);
69 if (end_character == "K" || end_character == "M" || end_character == "B" || end_character == "T") {
70 var new_like_count = parseInt(current_like_count);
71 var new_dislike_count = parseInt(current_dislike_count);
72 } else {
73 var new_like_count = parseInt(current_like_count) + 1;
74 var new_dislike_count = parseInt(current_dislike_count);
75 }
76 }
77 if (jltma_dislike_cookie != "") {
78 var end_character = current_like_count.slice(-1);
79 if (end_character == "K" || end_character == "M" || end_character == "B" || end_character == "T") {
80 var new_like_count = parseInt(current_like_count);
81 var new_dislike_count = parseInt(current_dislike_count);
82 } else {
83 var new_dislike_count = parseInt(current_dislike_count) - 1;
84 if (new_dislike_count < 0) new_dislike_count = 0;
85 var new_like_count = parseInt(current_like_count) + 1;
86 }
87 }
88 $("#jltma-like-count-" + comment_id).html(new_like_count);
89 $("#jltma-dislike-count-" + comment_id).html(new_dislike_count);
90 var not_trigger_type = "dislike";
91 like_dislike_Cookies(trigger_type, comment_id, $this, not_trigger_type);
92 }
93 }
94 if (jltma_dislike_cookie == "" && trigger_type == "dislike") {
95 var cookie_name = "jltma_" + trigger_type + "_" + comment_id;
96 jltma_setCookie(cookie_name, 1, 365);
97 if (!$this.hasClass("jltma-like-trigger")) {
98 if (jltma_like_cookie == "") {
99 var end_character = current_dislike_count.slice(-1);
100 if (end_character == "K" || end_character == "M" || end_character == "B" || end_character == "T") {
101 var new_like_count = parseInt(current_like_count);
102 var new_dislike_count = parseInt(current_dislike_count);
103 } else {
104 var new_dislike_count = parseInt(current_dislike_count) + 1;
105 var new_like_count = parseInt(current_like_count);
106 }
107 }
108 if (jltma_like_cookie != "") {
109 var end_character = current_dislike_count.slice(-1);
110 if (end_character == "K" || end_character == "M" || end_character == "B" || end_character == "T") {
111 var new_like_count = parseInt(current_like_count);
112 var new_dislike_count = parseInt(current_dislike_count);
113 } else {
114 var new_like_count = parseInt(current_like_count) - 1;
115 if (new_like_count < 0) new_like_count = 0;
116 var new_dislike_count = parseInt(current_dislike_count) + 1;
117 }
118 }
119 $("#jltma-like-count-" + comment_id).html(new_like_count);
120 $("#jltma-dislike-count-" + comment_id).html(new_dislike_count);
121 var not_trigger_type = "like";
122 like_dislike_Cookies(trigger_type, comment_id, $this, not_trigger_type);
123 }
124 }
125 });
126 $(".jltma-comments-wrap").on("click", ".jltma-page-link", function(e) {
127 $(this).closest(".jltma-comment-pagination-wrapper").find(".jltma-page-link").removeClass("jltma-current-page");
128 $(this).addClass("jltma-current-page");
129 var post_id = $("#jltma-current-post-id").val(), page_number = $(this).data("page-number"), total_page = $(this).data("total-page"), pagination_type = $(this).data("pagination-type"), template = $(this).closest(".jltma-comments-wrap").data("jltma-comment-settings").template;
130 $.ajax({
131 type: "post",
132 url: jltma_localize_comments_data.ajax_url,
133 data: {
134 page_number,
135 template,
136 post_id,
137 action: "jltma_comment_pagination",
138 _wpnonce: jltma_localize_comments_data.ajax_nonce
139 },
140 cache: false,
141 beforeSend: function(xhr) {
142 $(".jltma-page-number-loader").show();
143 },
144 success: function(res) {
145 $(".jltma-page-number-loader").hide();
146 var pagination_html = pagination_html_function(page_number, total_page, pagination_type);
147 $(".jltma-comment-list-inner").replaceWith(res);
148 $(".jltma-comment-pagination-wrapper").replaceWith(pagination_html);
149 $("html, body").animate({ scrollTop: $(".jltma-comment-listing-wrap").offset().top }, 1e3);
150 }
151 });
152 });
153 $("body").on("click", ".jltma-next-page,.jltma-previous-page", function() {
154 var post_id = $("#jltma-current-post-id").val(), total_page = $(this).data("total-page"), pagination_type = $(this).data("pagination-type"), current_page = $(this).closest(".jltma-comment-pagination-wrapper").find(".jltma-current-page").data("page-number"), next_page = parseInt(current_page) + 1, previous_page = parseInt(current_page) - 1, template = $(this).closest(".jltma-comments-wrap").data("jltma-comment-settings").template;
155 if ($(this).hasClass("jltma-previous-page")) current_page = previous_page;
156 else current_page = next_page;
157 $.ajax({
158 type: "post",
159 url: jltma_localize_comments_data.ajax_url,
160 data: {
161 page_number: current_page,
162 template,
163 post_id,
164 action: "jltma_comment_pagination",
165 _wpnonce: jltma_localize_comments_data.ajax_nonce
166 },
167 beforeSend: function(xhr) {
168 $(".jltma-page-number-loader").show();
169 },
170 success: function(res) {
171 $(".jltma-page-number-loader").hide();
172 var pagination_html = pagination_html_function(current_page, total_page, pagination_type);
173 $(".jltma-comment-list-inner").replaceWith(res);
174 $(".jltma-comment-pagination-wrapper").replaceWith(pagination_html);
175 $("html, body").animate({ scrollTop: $(".jltma-comment-listing-wrap").offset().top }, 1e3);
176 }
177 });
178 });
179 function pagination_html_function(page_number, total_page, pagination_type) {
180 var pagination_html = "", current_page = page_number, page_number_loader = jltma_localize_comments_data.page_number_loader;
181 pagination_html += "<div class=\"jltma-comment-pagination-wrapper jltma-" + pagination_type + "\"> <ul>";
182 if (current_page > 1) pagination_html += "<li class=\"jltma-previous-page-wrap\"><a href=\"javascript:void(0);\" class=\"jltma-previous-page\" data-total-page=\"" + total_page + "\" data-pagination-type=\"page-number\"><i class=\"fa fa-angle-left\"></i></a></li>";
183 var lower_limit = current_page;
184 var upper_limit = total_page;
185 for (var page_count = lower_limit; page_count <= upper_limit; page_count++) {
186 var page_class = current_page == page_count ? "jltma-current-page jltma-page-link" : "jltma-page-link";
187 pagination_html += "<li class=\"jltma-fa\"><a href=\"javascript:void(0);\" data-total-page=\"" + total_page + "\" data-page-number=\"" + page_count + "\" class=\"" + page_class + "\" data-pagination-type=\"page-number\" >" + page_count;
188 }
189 if (current_page < total_page) pagination_html += "<li class=\"jltma-next-page-wrap\"><a href=\"javascript:void(0);\" data-total-page=\"" + total_page + "\" class=\"jltma-next-page\"\" data-pagination-type=\"" + pagination_type + "\"><i class=\"fa fa-angle-right\"></i></a></li>";
190 pagination_html += "</ul> <img src=\"" + page_number_loader + "\" class=\"jltma-page-number-loader\" style=\"display:none;\"></div>";
191 return pagination_html;
192 }
193 $("body").on("click", ".jltma-show-replies-trigger", function() {
194 var comment_id = $(this).data("comment-id");
195 $(this).closest(".jltma-comment-template").siblings("ul").slideDown(400, function() {});
196 $(".jltma-hide-reply-trigger-" + comment_id).show();
197 $(".jltma-show-reply-trigger-" + comment_id).hide();
198 });
199 $("body").on("click", ".jltma-hide-replies-trigger", function() {
200 var comment_id = $(this).data("comment-id");
201 $(this).closest(".jltma-comment-template").siblings("ul").slideUp(400, function() {});
202 $(".jltma-hide-reply-trigger-" + comment_id).hide();
203 $(".jltma-show-reply-trigger-" + comment_id).show();
204 });
205 $(".jltma_comment_loadmore").click(function() {
206 var button = $(this);
207 jltma_localize_comments_data.jc_page--;
208 $.ajax({
209 url: jltma_localize_comments_data.ajax_url,
210 data: {
211 "action": "jltma_loadmore_comments",
212 "post_id": jltma_localize_comments_data.parent_post_id,
213 "jc_page": jltma_localize_comments_data.jc_page
214 },
215 type: "POST",
216 beforeSend: function(xhr) {
217 button.text("Loading...");
218 },
219 success: function(data) {
220 if (data) {
221 $(".jltma-comment-list").append(data);
222 button.text("More comments");
223 if (jltma_localize_comments_data.jc_page == 1) button.remove();
224 } else button.remove();
225 }
226 });
227 return false;
228 });
229 });
230 })(jQuery);
231 //#endregion
232 })();
233