kk Star Ratings - Version 5.2.6

Version Description

Download this release

Release Info

Developer bhittani
Plugin Icon 128x128 kk Star Ratings
Version 5.2.6
Comparing to
See all releases

Code changes from version 5.2.5 to 5.2.6

CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
 
 
 
 
 
 
8
  ## [5.2.5] - 2022-01-22
9
 
10
  ### Added
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
 
8
+ ## [5.2.6] - 2022-01-27
9
+
10
+ ### Updated
11
+ - jQuery is no more required.
12
+
13
  ## [5.2.5] - 2022-01-22
14
 
15
  ### Added
LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
  kk Star Ratings - WordPress Plugin
2
 
3
- Copyright (C) 2011-2021 Kamal Khan
4
 
5
  This program is free software; you can redistribute it and/or
6
  modify it under the terms of the GNU General Public License
1
  kk Star Ratings - WordPress Plugin
2
 
3
+ Copyright (C) 2011-2022 Kamal Khan
4
 
5
  This program is free software; you can redistribute it and/or
6
  modify it under the terms of the GNU General Public License
index.php CHANGED
@@ -10,7 +10,7 @@
10
  * Author URI: http://bhittani.com
11
  * Text Domain: kk-star-ratings
12
  * Domain Path: /languages
13
- * Version: 5.2.5
14
  * License: GPLv2 or later
15
  */
16
 
10
  * Author URI: http://bhittani.com
11
  * Text Domain: kk-star-ratings
12
  * Domain Path: /languages
13
+ * Version: 5.2.6
14
  * License: GPLv2 or later
15
  */
16
 
languages/kk-star-ratings.pot CHANGED
@@ -2,14 +2,14 @@
2
  # This file is distributed under the same license as the kk Star Ratings plugin.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: kk Star Ratings 5.2.5\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/kk-star-ratings\n"
7
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
8
  "Language-Team: LANGUAGE <LL@li.org>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
- "POT-Creation-Date: 2022-01-22T10:15:19+00:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.4.0\n"
15
  "X-Domain: kk-star-ratings\n"
2
  # This file is distributed under the same license as the kk Star Ratings plugin.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: kk Star Ratings 5.2.6\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/kk-star-ratings\n"
7
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
8
  "Language-Team: LANGUAGE <LL@li.org>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "POT-Creation-Date: 2022-01-27T07:37:08+00:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.4.0\n"
15
  "X-Domain: kk-star-ratings\n"
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: star ratings, votings, rate posts, ajax ratings, infinite stars, unlimited
6
  Requires at least: 5.0
7
  Requires PHP: 7.2
8
  Tested up to: 5.8.1
9
- Stable tag: 5.2.5
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
6
  Requires at least: 5.0
7
  Requires PHP: 7.2
8
  Tested up to: 5.8.1
9
+ Stable tag: 5.2.6
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
src/core/functions/scripts/main.php CHANGED
@@ -22,7 +22,7 @@ function main(bool $isDebugMode = false): void
22
  kksr('slug'),
23
  kksr('core.url').'public/js/kk-star-ratings'
24
  .($isDebugMode ? '' : '.min').'.js',
25
- ['jquery'],
26
  kksr('version'),
27
  true
28
  );
22
  kksr('slug'),
23
  kksr('core.url').'public/js/kk-star-ratings'
24
  .($isDebugMode ? '' : '.min').'.js',
25
+ [],
26
  kksr('version'),
27
  true
28
  );
src/core/public/js/kk-star-ratings.js CHANGED
@@ -5,108 +5,115 @@
5
 
6
  "use strict";
7
 
8
- // (function (fn) {
9
- // if (document.readyState != 'loading'){
10
- // return fn();
11
- // }
12
-
13
- // document.addEventListener('DOMContentLoaded', fn);
14
- // })(function kkStarRatings() {
15
- // console.log('ready!');
16
-
17
- // function onClick(e) {
18
- // e.preventDefault();
19
- // var $el = e.currentTarget;
20
- // console.log($el);
21
- // //
22
- // }
23
-
24
- // var $els = document.querySelectorAll('.kk-star-ratings');
25
- // for (var i = 0; i < $els.length; i++) {
26
- // var $el = $els[i];
27
- // console.log($el);
28
- // var $stars = document.querySelectorAll('[data-star]', $el);
29
- // for (var j = 0; j < $stars.length; j++) {
30
- // var $star = $stars[j];
31
- // console.log($star);
32
- // $star.addEventListener('click', onClick);
33
- // }
34
- // }
35
- // });
36
-
37
- jQuery(document).ready(function ($) {
38
- function apply($el, options) {
39
- var options = options || { isBusy: false };
40
-
41
- function ajax(data, successCallback, errorCallback) {
42
- if (options.isBusy || $el.hasClass("kksr-disabled")) {
43
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
 
46
- options.isBusy = true;
47
-
48
- $.ajax({
49
- type: "POST",
50
- url: kk_star_ratings.endpoint,
51
- data: Object.assign(
52
- {
53
- nonce: kk_star_ratings.nonce,
54
- action: kk_star_ratings.action,
55
- },
56
- data
57
- ),
58
- error: errorCallback,
59
- success: successCallback,
60
- complete: function () {
61
- options.isBusy = false;
62
  },
63
- });
 
64
  }
65
 
66
  function onClick(e) {
67
- var $star = $(this);
68
-
69
- // var payload = {
70
- // id: $el.data('id'),
71
- // slug: $el.data('slug'),
72
- // score: $star.data('star'),
73
- // best: $('[data-star]', $el).length
74
- // };
75
-
76
- ajax(
77
- {
78
- rating: $star.data("star"),
79
- payload: $el.data("payload"),
80
- },
81
- function (response, status, xhr) {
82
- var $newEl = $(response.trim());
83
- $newEl.addClass($el.attr("class"));
84
- $el.replaceWith($newEl);
85
- destroy();
86
- apply($newEl, options);
87
- },
88
- function (xhr, status, err) {
89
- if (xhr.responseJSON && xhr.responseJSON.error) {
90
- console.error(xhr.responseJSON.error);
91
- }
92
- }
93
- );
94
  }
95
 
96
- function destroy() {
97
- $("[data-star]", $el).each(function () {
98
- $(this).off("click", onClick);
 
 
99
  });
 
100
 
101
- $el.remove();
 
 
 
102
  }
103
 
104
- $("[data-star]", $el).each(function () {
105
- $(this).on("click", onClick);
106
- });
107
  }
108
 
109
- $(".kk-star-ratings").each(function () {
110
- apply($(this));
111
- });
 
112
  });
5
 
6
  "use strict";
7
 
8
+ (function (fn) {
9
+ if (document.readyState != "loading") {
10
+ return fn();
11
+ }
12
+
13
+ document.addEventListener("DOMContentLoaded", fn);
14
+ })(function kkStarRatings() {
15
+ var isBusy = false;
16
+
17
+ function post(data, successCallback, errorCallback) {
18
+ if (isBusy) {
19
+ return;
20
+ }
21
+
22
+ isBusy = true;
23
+
24
+ data = Object.assign(
25
+ {
26
+ nonce: kk_star_ratings.nonce,
27
+ action: kk_star_ratings.action,
28
+ },
29
+ data
30
+ );
31
+
32
+ var query = [];
33
+ for (var key in data) {
34
+ query.push(encodeURIComponent(key) + "=" + encodeURIComponent(data[key]));
35
+ }
36
+
37
+ var request = new XMLHttpRequest();
38
+
39
+ request.open("POST", kk_star_ratings.endpoint, true);
40
+
41
+ request.onload = function () {
42
+ if (request.status >= 200 && request.status < 400) {
43
+ successCallback(request.responseText, request);
44
+ } else {
45
+ errorCallback(request.responseText, request);
46
+ }
47
+ };
48
+
49
+ request.onloadend = function () {
50
+ isBusy = false;
51
+ };
52
+
53
+ request.setRequestHeader(
54
+ "Content-type",
55
+ "application/x-www-form-urlencoded; charset=UTF-8"
56
+ );
57
+
58
+ request.send(query.join("&"));
59
+ }
60
+
61
+ function htmlToEl(html) {
62
+ var div = document.createElement("div");
63
+ div.innerHTML = html.trim();
64
+
65
+ return div.firstChild;
66
+ }
67
+
68
+ function apply($el) {
69
+ function vote($star) {
70
+ var data = {
71
+ rating: $star.getAttribute("data-star"),
72
+ };
73
+
74
+ var payload = JSON.parse($el.getAttribute("data-payload"));
75
+
76
+ for (var key in payload) {
77
+ data["payload[" + key + "]"] = payload[key];
78
  }
79
 
80
+ post(
81
+ data,
82
+ function (html) {
83
+ var $newEl = htmlToEl(html);
84
+ $el.parentNode.replaceChild($newEl, $el);
85
+ unmount();
86
+ $el = null;
87
+ apply($newEl);
 
 
 
 
 
 
 
 
88
  },
89
+ console.error
90
+ );
91
  }
92
 
93
  function onClick(e) {
94
+ e.preventDefault();
95
+ vote(e.currentTarget);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
 
98
+ var $stars = $el.querySelectorAll("[data-star]");
99
+
100
+ function unmount() {
101
+ Array.prototype.forEach.call($stars, function ($star) {
102
+ $star.removeEventListener("click", onClick);
103
  });
104
+ }
105
 
106
+ function mount() {
107
+ Array.prototype.forEach.call($stars, function ($star) {
108
+ $star.addEventListener("click", onClick);
109
+ });
110
  }
111
 
112
+ mount();
 
 
113
  }
114
 
115
+ Array.prototype.forEach.call(
116
+ document.querySelectorAll(".kk-star-ratings"),
117
+ apply
118
+ );
119
  });
src/core/public/js/kk-star-ratings.min.js CHANGED
@@ -2,4 +2,4 @@
2
  * kk Star Ratings
3
  * @see https://github.com/kamalkhan/kk-star-ratings
4
  */
5
- "use strict";jQuery(document).ready(function(s){function a(t,n){n=n||{isBusy:!1};function r(e){var i,o,c,u=s(this);i={rating:u.data("star"),payload:t.data("payload")},o=function(e,i,o){var c=s(e.trim());c.addClass(t.attr("class")),t.replaceWith(c),s("[data-star]",t).each(function(){s(this).off("click",r)}),t.remove(),a(c,n)},c=function(s,a,t){s.responseJSON&&s.responseJSON.error&&console.error(s.responseJSON.error)},n.isBusy||t.hasClass("kksr-disabled")||(n.isBusy=!0,s.ajax({type:"POST",url:kk_star_ratings.endpoint,data:Object.assign({nonce:kk_star_ratings.nonce,action:kk_star_ratings.action},i),error:c,success:o,complete:function(){n.isBusy=!1}}))}s("[data-star]",t).each(function(){s(this).on("click",r)})}s(".kk-star-ratings").each(function(){a(s(this))})});
2
  * kk Star Ratings
3
  * @see https://github.com/kamalkhan/kk-star-ratings
4
  */
5
+ "use strict";!function(t){if("loading"!=document.readyState)return t();document.addEventListener("DOMContentLoaded",t)}(function(){var t=!1;Array.prototype.forEach.call(document.querySelectorAll(".kk-star-ratings"),function e(n){function r(r){var c={rating:r.getAttribute("data-star")},i=JSON.parse(n.getAttribute("data-payload"));for(var s in i)c["payload["+s+"]"]=i[s];!function(e,n,r){if(!t){t=!0,e=Object.assign({nonce:kk_star_ratings.nonce,action:kk_star_ratings.action},e);var a=[];for(var o in e)a.push(encodeURIComponent(o)+"="+encodeURIComponent(e[o]));var c=new XMLHttpRequest;c.open("POST",kk_star_ratings.endpoint,!0),c.onload=function(){c.status>=200&&c.status<400?n(c.responseText,c):r(c.responseText,c)},c.onloadend=function(){t=!1},c.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8"),c.send(a.join("&"))}}(c,function(t){var r=function(t){var e=document.createElement("div");return e.innerHTML=t.trim(),e.firstChild}(t);n.parentNode.replaceChild(r,n),Array.prototype.forEach.call(o,function(t){t.removeEventListener("click",a)}),n=null,e(r)},console.error)}function a(t){t.preventDefault(),r(t.currentTarget)}var o=n.querySelectorAll("[data-star]");Array.prototype.forEach.call(o,function(t){t.addEventListener("click",a)})})});