Yasr – Yet Another Stars Rating - Version 1.9.2

Version Description

  • FIXED: Javascript error on some mobile device
Download this release

Release Info

Developer Dudo
Plugin Icon 128x128 Yasr – Yet Another Stars Rating
Version 1.9.2
Comparing to
See all releases

Code changes from version 1.9.1 to 1.9.2

js/rater-js-rtl.js ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.raterJs = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
2
+ "use strict";
3
+
4
+ /*! rater-js. [c] 2018 Fredrik Olsson. MIT License */
5
+ // var css = require('./style.css');
6
+
7
+ module.exports = function rater(options) {
8
+ //private fields
9
+ var showToolTip = true;
10
+
11
+ if (typeof options.element === "undefined" || options.element === null) {
12
+ throw new Error("element required");
13
+ }
14
+
15
+ if (typeof options.showToolTip !== "undefined") {
16
+ showToolTip = !!options.showToolTip;
17
+ }
18
+
19
+ if (typeof options.step !== "undefined") {
20
+ if (options.step <= 0 || options.step > 1) {
21
+ throw new Error("step must be a number between 0 and 1");
22
+ }
23
+ }
24
+
25
+ var stars = options.max || 5;
26
+ var starSize = options.starSize || 16;
27
+ var step = options.step || 1;
28
+ var onHover = options.onHover;
29
+ var onLeave = options.onLeave;
30
+ var rating;
31
+ var myRating;
32
+ var elem = options.element;
33
+ elem.classList.add("star-rating");
34
+ var div = document.createElement("div");
35
+ div.classList.add("star-value");
36
+ div.style.backgroundSize = starSize + "px";
37
+ elem.appendChild(div);
38
+ elem.style.width = starSize * stars + "px";
39
+ elem.style.height = starSize + "px";
40
+ elem.style.backgroundSize = starSize + "px";
41
+ var callback = options.rateCallback;
42
+ var disabled = !!options.readOnly;
43
+ var disableText;
44
+ var isRating = false;
45
+ var isBusyText = options.isBusyText;
46
+ var currentRating;
47
+ var ratingText;
48
+
49
+ if (typeof options.disableText !== "undefined") {
50
+ disableText = options.disableText;
51
+ } else {
52
+ disableText = "{rating}/{maxRating}";
53
+ }
54
+
55
+ if (typeof options.ratingText !== "undefined") {
56
+ ratingText = options.ratingText;
57
+ } else {
58
+ ratingText = "{rating}/{maxRating}";
59
+ }
60
+
61
+ if (options.rating) {
62
+ setRating(options.rating);
63
+ } else {
64
+ var dataRating = elem.dataset.rating;
65
+
66
+ if (dataRating) {
67
+ setRating(+dataRating);
68
+ }
69
+ }
70
+
71
+ if (typeof rating === "undefined") {
72
+ elem.querySelector(".star-value").style.width = "0px";
73
+ }
74
+
75
+ if (disabled) {
76
+ disable();
77
+ } //private methods
78
+
79
+
80
+ function onMouseMove(e) {
81
+ if (disabled === true || isRating === true) {
82
+ return;
83
+ }
84
+
85
+ var parentOffset = this.getBoundingClientRect();
86
+ var relX = e.pageX - parentOffset.left;
87
+
88
+ var width = elem.offsetWidth;
89
+
90
+ var relXRtl= width - relX;
91
+ var valueForDivision = width/100;
92
+
93
+ var percent = relXRtl/valueForDivision;
94
+
95
+ if (percent < 101) {
96
+ if (step === 1) {
97
+ currentRating = Math.ceil(percent / 100 * stars);
98
+ } else {
99
+ var rat = percent / 100 * stars;
100
+
101
+ for (var i = 0;; i += step) {
102
+ if (i >= rat) {
103
+ currentRating = i;
104
+ break;
105
+ }
106
+ }
107
+ }
108
+
109
+ if (currentRating > 5) {
110
+ currentRating = 5;
111
+ }
112
+
113
+ elem.querySelector(".star-value").style.width = currentRating / stars * 100 + "%";
114
+
115
+ if (showToolTip) {
116
+ var toolTip = ratingText.replace("{rating}", currentRating);
117
+ toolTip = toolTip.replace("{maxRating}", stars);
118
+ elem.setAttribute("data-title", toolTip);
119
+ }
120
+
121
+ if (typeof onHover === "function") {
122
+ onHover(currentRating, rating);
123
+ }
124
+ }
125
+ }
126
+
127
+
128
+ function onStarOut(e) {
129
+ if (typeof rating !== "undefined") {
130
+ elem.querySelector(".star-value").style.width = rating / stars * 100 + "%";
131
+ elem.setAttribute("data-rating", rating);
132
+ } else {
133
+ elem.querySelector(".star-value").style.width = "0%";
134
+ elem.removeAttribute("data-rating");
135
+ }
136
+
137
+ if (typeof onLeave === "function") {
138
+ onLeave(currentRating, rating);
139
+ }
140
+ }
141
+
142
+ function onStarClick(e) {
143
+ if (disabled === true) {
144
+ return;
145
+ }
146
+
147
+ if (isRating === true) {
148
+ return;
149
+ }
150
+
151
+ if (typeof callback !== "undefined") {
152
+ isRating = true;
153
+ myRating = currentRating;
154
+
155
+ if (typeof isBusyText === "undefined") {
156
+ elem.removeAttribute("data-title");
157
+ } else {
158
+ elem.setAttribute("data-title", isBusyText);
159
+ }
160
+
161
+ callback.call(this, myRating, function () {
162
+ if (disabled === false) {
163
+ elem.removeAttribute("data-title");
164
+ }
165
+
166
+ isRating = false;
167
+ });
168
+ }
169
+ } //public methods
170
+
171
+
172
+ function disable() {
173
+ disabled = true;
174
+
175
+ if (showToolTip && !!disableText) {
176
+ var toolTip = disableText.replace("{rating}", rating);
177
+ toolTip = toolTip.replace("{maxRating}", stars);
178
+ elem.setAttribute("data-title", toolTip);
179
+ } else {
180
+ elem.removeAttribute("data-title");
181
+ }
182
+ }
183
+
184
+ function enable() {
185
+ disabled = false;
186
+ elem.removeAttribute("data-title");
187
+ }
188
+
189
+ function setRating(value) {
190
+ //Added for Yasr
191
+ if (value === -1) {
192
+ value = undefined;
193
+ }
194
+
195
+ if (typeof value !== "number" && typeof value !== "undefined") {
196
+ throw new Error("Value must be a number or undefined.");
197
+ }
198
+
199
+ if (value < 0 || value > stars) {
200
+ var ratingError = new Error("Value too high. Please set a rating of " + stars + " or below.");
201
+ ratingError.name = "ratingError";
202
+ throw ratingError;
203
+ }
204
+
205
+ rating = value;
206
+ elem.querySelector(".star-value").style.width = value / stars * 100 + "%";
207
+ elem.setAttribute("data-rating", value);
208
+ }
209
+
210
+ function getRating() {
211
+ return rating;
212
+ }
213
+
214
+ function dispose() {
215
+ elem.removeEventListener("mousemove", onMouseMove);
216
+ elem.removeEventListener("mouseleave", onStarOut);
217
+ elem.removeEventListener("click", onStarClick);
218
+ }
219
+
220
+ elem.addEventListener("mousemove", onMouseMove);
221
+ elem.addEventListener("mouseleave", onStarOut);
222
+ var module = {
223
+ setRating: setRating,
224
+ getRating: getRating,
225
+ disable: disable,
226
+ enable: enable,
227
+ dispose: dispose
228
+ };
229
+
230
+ elem.addEventListener("click", onStarClick.bind(module));
231
+ return module;
232
+ };
233
+
234
+ },{"./style.css":2}],2:[function(require,module,exports){
235
+ var css = ".star-rating {\n width: 0;\n position: relative;\n display: inline-block;\n background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDguOSIgaGVpZ2h0PSIxMDMuNiIgdmlld0JveD0iMCAwIDEwOC45IDEwMy42Ij48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6I2UzZTZlNjt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPnN0YXJfMDwvdGl0bGU+PGcgaWQ9IkxheWVyXzIiIGRhdGEtbmFtZT0iTGF5ZXIgMiI+PGcgaWQ9IkxheWVyXzEtMiIgZGF0YS1uYW1lPSJMYXllciAxIj48cG9seWdvbiBjbGFzcz0iY2xzLTEiIHBvaW50cz0iMTA4LjkgMzkuNiA3MS4zIDM0LjEgNTQuNCAwIDM3LjYgMzQuMSAwIDM5LjYgMjcuMiA2Ni4xIDIwLjggMTAzLjYgNTQuNCA4NS45IDg4LjEgMTAzLjYgODEuNyA2Ni4xIDEwOC45IDM5LjYiLz48L2c+PC9nPjwvc3ZnPgo=);\n background-position: 0 0;\n background-repeat: repeat-x;\n cursor: pointer;\n}\n.star-rating[data-title]:hover:after {\n content: attr(data-title);\n padding: 4px 8px;\n color: #333;\n position: absolute;\n left: 0;\n top: 100%;\n z-index: 20;\n white-space: nowrap;\n -moz-border-radius: 5px;\n -webkit-border-radius: 5px;\n border-radius: 5px;\n -moz-box-shadow: 0px 0px 4px #222;\n -webkit-box-shadow: 0px 0px 4px #222;\n box-shadow: 0px 0px 4px #222;\n background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);\n background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #eeeeee),color-stop(1, #cccccc));\n background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);\n background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);\n background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);\n background-image: -o-linear-gradient(top, #eeeeee, #cccccc);\n}\n.star-rating .star-value {\n height: 100%;\n position: absolute;\n}\n.star-rating .star-value {\n position: absolute;\n height: 100%;\n width: 100%;\n background: url('data:image/svg+xml;base64,PHN2ZwoJeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTA4LjkiIGhlaWdodD0iMTAzLjYiIHZpZXdCb3g9IjAgMCAxMDguOSAxMDMuNiI+Cgk8ZGVmcz4KCQk8c3R5bGU+LmNscy0xe2ZpbGw6I2YxYzk0Nzt9PC9zdHlsZT4KCTwvZGVmcz4KCTx0aXRsZT5zdGFyMTwvdGl0bGU+Cgk8ZyBpZD0iTGF5ZXJfMiIgZGF0YS1uYW1lPSJMYXllciAyIj4KCQk8ZyBpZD0iTGF5ZXJfMS0yIiBkYXRhLW5hbWU9IkxheWVyIDEiPgoJCQk8cG9seWdvbiBjbGFzcz0iY2xzLTEiIHBvaW50cz0iNTQuNCAwIDcxLjMgMzQuMSAxMDguOSAzOS42IDgxLjcgNjYuMSA4OC4xIDEwMy42IDU0LjQgODUuOSAyMC44IDEwMy42IDI3LjIgNjYuMSAwIDM5LjYgMzcuNiAzNC4xIDU0LjQgMCIvPgoJCTwvZz4KCTwvZz4KPC9zdmc+Cg==');\n background-repeat: repeat-x;\n}\n"; (require("browserify-css").createStyle(css, { "href": "lib\\style.css" }, { "insertAt": "bottom" })); module.exports = css;
236
+ },{"browserify-css":3}],3:[function(require,module,exports){
237
+ 'use strict';
238
+ // For more information about browser field, check out the browser field at https://github.com/substack/browserify-handbook#browser-field.
239
+
240
+ var styleElementsInsertedAtTop = [];
241
+
242
+ var insertStyleElement = function(styleElement, options) {
243
+ var head = document.head || document.getElementsByTagName('head')[0];
244
+ var lastStyleElementInsertedAtTop = styleElementsInsertedAtTop[styleElementsInsertedAtTop.length - 1];
245
+
246
+ options = options || {};
247
+ options.insertAt = options.insertAt || 'bottom';
248
+
249
+ if (options.insertAt === 'top') {
250
+ if (!lastStyleElementInsertedAtTop) {
251
+ head.insertBefore(styleElement, head.firstChild);
252
+ } else if (lastStyleElementInsertedAtTop.nextSibling) {
253
+ head.insertBefore(styleElement, lastStyleElementInsertedAtTop.nextSibling);
254
+ } else {
255
+ head.appendChild(styleElement);
256
+ }
257
+ styleElementsInsertedAtTop.push(styleElement);
258
+ } else if (options.insertAt === 'bottom') {
259
+ head.appendChild(styleElement);
260
+ } else {
261
+ throw new Error('Invalid value for parameter \'insertAt\'. Must be \'top\' or \'bottom\'.');
262
+ }
263
+ };
264
+
265
+ module.exports = {
266
+ // Create a <link> tag with optional data attributes
267
+ createLink: function(href, attributes) {
268
+ var head = document.head || document.getElementsByTagName('head')[0];
269
+ var link = document.createElement('link');
270
+
271
+ link.href = href;
272
+ link.rel = 'stylesheet';
273
+
274
+ for (var key in attributes) {
275
+ if ( ! attributes.hasOwnProperty(key)) {
276
+ continue;
277
+ }
278
+ var value = attributes[key];
279
+ link.setAttribute('data-' + key, value);
280
+ }
281
+
282
+ head.appendChild(link);
283
+ },
284
+ // Create a <style> tag with optional data attributes
285
+ createStyle: function(cssText, attributes, extraOptions) {
286
+ extraOptions = extraOptions || {};
287
+
288
+ var style = document.createElement('style');
289
+ style.type = 'text/css';
290
+
291
+ for (var key in attributes) {
292
+ if ( ! attributes.hasOwnProperty(key)) {
293
+ continue;
294
+ }
295
+ var value = attributes[key];
296
+ style.setAttribute('data-' + key, value);
297
+ }
298
+
299
+ if (style.sheet) { // for jsdom and IE9+
300
+ style.innerHTML = cssText;
301
+ style.sheet.cssText = cssText;
302
+ insertStyleElement(style, { insertAt: extraOptions.insertAt });
303
+ } else if (style.styleSheet) { // for IE8 and below
304
+ insertStyleElement(style, { insertAt: extraOptions.insertAt });
305
+ style.styleSheet.cssText = cssText;
306
+ } else { // for Chrome, Firefox, and Safari
307
+ style.appendChild(document.createTextNode(cssText));
308
+ insertStyleElement(style, { insertAt: extraOptions.insertAt });
309
+ }
310
+ }
311
+ };
312
+
313
+ },{}]},{},[1])(1)
314
+ });
js/rater-js.js CHANGED
@@ -2,9 +2,9 @@
2
  "use strict";
3
 
4
  /*! rater-js. [c] 2018 Fredrik Olsson. MIT License */
5
- //var css = require('./style.css');
6
 
7
- module.exports = function (options) {
8
  //private fields
9
  var showToolTip = true;
10
 
@@ -22,30 +22,17 @@
22
  }
23
  }
24
 
25
- //Added for Yasr
26
- var reverse = false;
27
-
28
- if(document.dir === 'rtl') {
29
- reverse = true;
30
- }
31
- //////////
32
-
33
- var elem = options.element;
34
  var stars = options.max || 5;
35
  var starSize = options.starSize || 16;
36
  var step = options.step || 1;
37
  var onHover = options.onHover;
38
  var onLeave = options.onLeave;
39
- var rating = null;
40
  var myRating;
 
41
  elem.classList.add("star-rating");
42
  var div = document.createElement("div");
43
  div.classList.add("star-value");
44
-
45
- if (reverse) {
46
- div.classList.add("rtl");
47
- }
48
-
49
  div.style.backgroundSize = starSize + "px";
50
  elem.appendChild(div);
51
  elem.style.width = starSize * stars + "px";
@@ -81,7 +68,7 @@
81
  }
82
  }
83
 
84
- if (!rating) {
85
  elem.querySelector(".star-value").style.width = "0px";
86
  }
87
 
@@ -91,43 +78,13 @@
91
 
92
 
93
  function onMouseMove(e) {
94
- onMove(e, false);
95
- }
96
- /**
97
- * Called by eventhandlers when mouse or touch events are triggered
98
- * @param {MouseEvent} e
99
- */
100
-
101
- function onMove(e, isTouch) {
102
  if (disabled === true || isRating === true) {
103
  return;
104
  }
105
 
106
- var xCoor = null;
107
- var percent;
108
  var width = elem.offsetWidth;
109
-
110
- if (reverse) {
111
- var parentOffset = elem.getBoundingClientRect();
112
-
113
- if (isTouch) {
114
- xCoor = e.changedTouches[0].pageX - parentOffset.left;
115
- } else {
116
- xCoor = e.pageX - parentOffset.left;
117
- }
118
-
119
- var relXRtl = width - xCoor;
120
- var valueForDivision = width / 100;
121
- percent = relXRtl / valueForDivision;
122
- } else {
123
- if (isTouch) {
124
- xCoor = e.changedTouches[0].pageX - e.changedTouches[0].target.offsetLeft;
125
- } else {
126
- xCoor = e.offsetX;
127
- }
128
-
129
- percent = xCoor / width * 100;
130
- }
131
 
132
  if (percent < 101) {
133
  if (step === 1) {
@@ -148,7 +105,7 @@
148
  if (showToolTip) {
149
  var toolTip = ratingText.replace("{rating}", currentRating);
150
  toolTip = toolTip.replace("{maxRating}", stars);
151
- elem.setAttribute("title", toolTip);
152
  }
153
 
154
  if (typeof onHover === "function") {
@@ -156,30 +113,20 @@
156
  }
157
  }
158
  }
159
- /**
160
- * Called when mouse is released. This function will update the view with the rating.
161
- * @param {MouseEvent} e
162
- */
163
-
164
 
165
  function onStarOut(e) {
166
- if (!rating) {
167
- elem.querySelector(".star-value").style.width = "0%";
168
- elem.removeAttribute("data-rating");
169
- } else {
170
  elem.querySelector(".star-value").style.width = rating / stars * 100 + "%";
171
  elem.setAttribute("data-rating", rating);
 
 
 
172
  }
173
 
174
  if (typeof onLeave === "function") {
175
  onLeave(currentRating, rating);
176
  }
177
  }
178
- /**
179
- * Called when star is clicked.
180
- * @param {MouseEvent} e
181
- */
182
-
183
 
184
  function onStarClick(e) {
185
  if (disabled === true) {
@@ -195,111 +142,68 @@
195
  myRating = currentRating;
196
 
197
  if (typeof isBusyText === "undefined") {
198
- elem.removeAttribute("title");
199
  } else {
200
- elem.setAttribute("title", isBusyText);
201
  }
202
 
203
- elem.classList.add("is-busy");
204
  callback.call(this, myRating, function () {
205
  if (disabled === false) {
206
- elem.removeAttribute("title");
207
  }
208
 
209
  isRating = false;
210
- elem.classList.remove("is-busy");
211
  });
212
  }
213
- }
214
- /**
215
- * Disables the rater so that it's not possible to click the stars.
216
- */
217
 
218
 
219
  function disable() {
220
  disabled = true;
221
- elem.classList.add("disabled");
222
 
223
  if (showToolTip && !!disableText) {
224
- var toolTip = disableText.replace("{rating}", !!rating ? rating : 0);
225
  toolTip = toolTip.replace("{maxRating}", stars);
226
- elem.setAttribute("title", toolTip);
227
  } else {
228
- elem.removeAttribute("title");
229
  }
230
  }
231
- /**
232
- * Enabled the rater so that it's possible to click the stars.
233
- */
234
-
235
 
236
  function enable() {
237
  disabled = false;
238
- elem.removeAttribute("title");
239
- elem.classList.remove("disabled");
240
  }
241
- /**
242
- * Sets the rating
243
- */
244
-
245
 
246
  function setRating(value) {
247
- if (typeof value === "undefined") {
248
- throw new Error("Value not set.");
249
- }
250
-
251
- if (value === null) {
252
- throw new Error("Value cannot be null.");
253
- }
254
-
255
- if (typeof value !== "number") {
256
- throw new Error("Value must be a number.");
257
- }
258
-
259
  //Added for Yasr
260
  if (value === -1) {
261
  value = undefined;
262
  }
263
 
 
 
 
 
264
  if (value < 0 || value > stars) {
265
- throw new Error("Value too high. Please set a rating of " + stars + " or below.");
 
 
266
  }
267
 
268
  rating = value;
269
  elem.querySelector(".star-value").style.width = value / stars * 100 + "%";
270
  elem.setAttribute("data-rating", value);
271
  }
272
- /**
273
- * Gets the rating
274
- */
275
-
276
 
277
  function getRating() {
278
  return rating;
279
  }
280
- /**
281
- * Set the rating to a value to inducate it's not rated.
282
- */
283
-
284
-
285
- function clear() {
286
- rating = null;
287
- elem.querySelector(".star-value").style.width = "0px";
288
- elem.removeAttribute("title");
289
- }
290
- /**
291
- * Remove event handlers.
292
- */
293
-
294
 
295
  function dispose() {
296
  elem.removeEventListener("mousemove", onMouseMove);
297
  elem.removeEventListener("mouseleave", onStarOut);
298
  elem.removeEventListener("click", onStarClick);
299
- elem.removeEventListener("touchmove", handleMove, false);
300
- elem.removeEventListener("touchstart", handleStart, false);
301
- elem.removeEventListener("touchend", handleEnd, false);
302
- elem.removeEventListener("touchcancel", handleCancel, false);
303
  }
304
 
305
  elem.addEventListener("mousemove", onMouseMove);
@@ -309,65 +213,15 @@
309
  getRating: getRating,
310
  disable: disable,
311
  enable: enable,
312
- clear: clear,
313
- dispose: dispose,
314
-
315
- get element() {
316
- return elem;
317
- }
318
-
319
  };
320
- /**
321
- * Handles touchmove event.
322
- * @param {TouchEvent} e
323
- */
324
-
325
- function handleMove(e) {
326
- e.preventDefault();
327
- onMove(e, true);
328
- }
329
- /**
330
- * Handles touchstart event.
331
- * @param {TouchEvent} e
332
- */
333
-
334
-
335
- function handleStart(e) {
336
- e.preventDefault();
337
- onMove(e, true);
338
- }
339
- /**
340
- * Handles touchend event.
341
- * @param {TouchEvent} e
342
- */
343
-
344
-
345
- function handleEnd(evt) {
346
- evt.preventDefault();
347
- onMove(evt, true);
348
- onStarClick.call(module);
349
- }
350
- /**
351
- * Handles touchend event.
352
- * @param {TouchEvent} e
353
- */
354
-
355
-
356
- function handleCancel(e) {
357
- e.preventDefault();
358
- onStarOut(e);
359
- }
360
 
361
  elem.addEventListener("click", onStarClick.bind(module));
362
- elem.addEventListener("touchmove", handleMove, false);
363
- elem.addEventListener("touchstart", handleStart, false);
364
- elem.addEventListener("touchend", handleEnd, false);
365
- elem.addEventListener("touchcancel", handleCancel, false);
366
  return module;
367
  };
368
 
369
  },{"./style.css":2}],2:[function(require,module,exports){
370
- var css = ".star-rating {\n width: 0;\n position: relative;\n display: inline-block;\n background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDguOSIgaGVpZ2h0PSIxMDMuNiIgdmlld0JveD0iMCAwIDEwOC45IDEwMy42Ij48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6I2UzZTZlNjt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPnN0YXJfMDwvdGl0bGU+PGcgaWQ9IkxheWVyXzIiIGRhdGEtbmFtZT0iTGF5ZXIgMiI+PGcgaWQ9IkxheWVyXzEtMiIgZGF0YS1uYW1lPSJMYXllciAxIj48cG9seWdvbiBjbGFzcz0iY2xzLTEiIHBvaW50cz0iMTA4LjkgMzkuNiA3MS4zIDM0LjEgNTQuNCAwIDM3LjYgMzQuMSAwIDM5LjYgMjcuMiA2Ni4xIDIwLjggMTAzLjYgNTQuNCA4NS45IDg4LjEgMTAzLjYgODEuNyA2Ni4xIDEwOC45IDM5LjYiLz48L2c+PC9nPjwvc3ZnPgo=);\n background-position: 0 0;\n background-repeat: repeat-x;\n cursor: pointer;\n}\n.star-rating .star-value {\n position: absolute;\n height: 100%;\n width: 100%;\n background: url('data:image/svg+xml;base64,PHN2ZwoJeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTA4LjkiIGhlaWdodD0iMTAzLjYiIHZpZXdCb3g9IjAgMCAxMDguOSAxMDMuNiI+Cgk8ZGVmcz4KCQk8c3R5bGU+LmNscy0xe2ZpbGw6I2YxYzk0Nzt9PC9zdHlsZT4KCTwvZGVmcz4KCTx0aXRsZT5zdGFyMTwvdGl0bGU+Cgk8ZyBpZD0iTGF5ZXJfMiIgZGF0YS1uYW1lPSJMYXllciAyIj4KCQk8ZyBpZD0iTGF5ZXJfMS0yIiBkYXRhLW5hbWU9IkxheWVyIDEiPgoJCQk8cG9seWdvbiBjbGFzcz0iY2xzLTEiIHBvaW50cz0iNTQuNCAwIDcxLjMgMzQuMSAxMDguOSAzOS42IDgxLjcgNjYuMSA4OC4xIDEwMy42IDU0LjQgODUuOSAyMC44IDEwMy42IDI3LjIgNjYuMSAwIDM5LjYgMzcuNiAzNC4xIDU0LjQgMCIvPgoJCTwvZz4KCTwvZz4KPC9zdmc+Cg==');\n background-repeat: repeat-x;\n}\n.star-rating.disabled {\n cursor: default;\n}\n.star-rating.is-busy {\n cursor: wait;\n}\n.star-rating .star-value.rtl {\n -moz-transform: scaleX(-1);\n -o-transform: scaleX(-1);\n -webkit-transform: scaleX(-1);\n transform: scaleX(-1);\n filter: FlipH;\n -ms-filter: \"FlipH\";\n right: 0;\n left: auto;\n}\n"; (require("browserify-css").createStyle(css, { "href": "lib\\style.css" }, { "insertAt": "bottom" })); module.exports = css;
371
  },{"browserify-css":3}],3:[function(require,module,exports){
372
  'use strict';
373
  // For more information about browser field, check out the browser field at https://github.com/substack/browserify-handbook#browser-field.
@@ -446,4 +300,4 @@
446
  };
447
 
448
  },{}]},{},[1])(1)
449
- });
2
  "use strict";
3
 
4
  /*! rater-js. [c] 2018 Fredrik Olsson. MIT License */
5
+ // var css = require('./style.css');
6
 
7
+ module.exports = function rater(options) {
8
  //private fields
9
  var showToolTip = true;
10
 
22
  }
23
  }
24
 
 
 
 
 
 
 
 
 
 
25
  var stars = options.max || 5;
26
  var starSize = options.starSize || 16;
27
  var step = options.step || 1;
28
  var onHover = options.onHover;
29
  var onLeave = options.onLeave;
30
+ var rating;
31
  var myRating;
32
+ var elem = options.element;
33
  elem.classList.add("star-rating");
34
  var div = document.createElement("div");
35
  div.classList.add("star-value");
 
 
 
 
 
36
  div.style.backgroundSize = starSize + "px";
37
  elem.appendChild(div);
38
  elem.style.width = starSize * stars + "px";
68
  }
69
  }
70
 
71
+ if (typeof rating === "undefined") {
72
  elem.querySelector(".star-value").style.width = "0px";
73
  }
74
 
78
 
79
 
80
  function onMouseMove(e) {
 
 
 
 
 
 
 
 
81
  if (disabled === true || isRating === true) {
82
  return;
83
  }
84
 
85
+ var xCoor = e.offsetX;
 
86
  var width = elem.offsetWidth;
87
+ var percent = xCoor / width * 100;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  if (percent < 101) {
90
  if (step === 1) {
105
  if (showToolTip) {
106
  var toolTip = ratingText.replace("{rating}", currentRating);
107
  toolTip = toolTip.replace("{maxRating}", stars);
108
+ elem.setAttribute("data-title", toolTip);
109
  }
110
 
111
  if (typeof onHover === "function") {
113
  }
114
  }
115
  }
 
 
 
 
 
116
 
117
  function onStarOut(e) {
118
+ if (typeof rating !== "undefined") {
 
 
 
119
  elem.querySelector(".star-value").style.width = rating / stars * 100 + "%";
120
  elem.setAttribute("data-rating", rating);
121
+ } else {
122
+ elem.querySelector(".star-value").style.width = "0%";
123
+ elem.removeAttribute("data-rating");
124
  }
125
 
126
  if (typeof onLeave === "function") {
127
  onLeave(currentRating, rating);
128
  }
129
  }
 
 
 
 
 
130
 
131
  function onStarClick(e) {
132
  if (disabled === true) {
142
  myRating = currentRating;
143
 
144
  if (typeof isBusyText === "undefined") {
145
+ elem.removeAttribute("data-title");
146
  } else {
147
+ elem.setAttribute("data-title", isBusyText);
148
  }
149
 
 
150
  callback.call(this, myRating, function () {
151
  if (disabled === false) {
152
+ elem.removeAttribute("data-title");
153
  }
154
 
155
  isRating = false;
 
156
  });
157
  }
158
+ } //public methods
 
 
 
159
 
160
 
161
  function disable() {
162
  disabled = true;
 
163
 
164
  if (showToolTip && !!disableText) {
165
+ var toolTip = disableText.replace("{rating}", rating);
166
  toolTip = toolTip.replace("{maxRating}", stars);
167
+ elem.setAttribute("data-title", toolTip);
168
  } else {
169
+ elem.removeAttribute("data-title");
170
  }
171
  }
 
 
 
 
172
 
173
  function enable() {
174
  disabled = false;
175
+ elem.removeAttribute("data-title");
 
176
  }
 
 
 
 
177
 
178
  function setRating(value) {
 
 
 
 
 
 
 
 
 
 
 
 
179
  //Added for Yasr
180
  if (value === -1) {
181
  value = undefined;
182
  }
183
 
184
+ if (typeof value !== "number" && typeof value !== "undefined") {
185
+ throw new Error("Value must be a number or undefined.");
186
+ }
187
+
188
  if (value < 0 || value > stars) {
189
+ var ratingError = new Error("Value too high. Please set a rating of " + stars + " or below.");
190
+ ratingError.name = "ratingError";
191
+ throw ratingError;
192
  }
193
 
194
  rating = value;
195
  elem.querySelector(".star-value").style.width = value / stars * 100 + "%";
196
  elem.setAttribute("data-rating", value);
197
  }
 
 
 
 
198
 
199
  function getRating() {
200
  return rating;
201
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
  function dispose() {
204
  elem.removeEventListener("mousemove", onMouseMove);
205
  elem.removeEventListener("mouseleave", onStarOut);
206
  elem.removeEventListener("click", onStarClick);
 
 
 
 
207
  }
208
 
209
  elem.addEventListener("mousemove", onMouseMove);
213
  getRating: getRating,
214
  disable: disable,
215
  enable: enable,
216
+ dispose: dispose
 
 
 
 
 
 
217
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  elem.addEventListener("click", onStarClick.bind(module));
 
 
 
 
220
  return module;
221
  };
222
 
223
  },{"./style.css":2}],2:[function(require,module,exports){
224
+ var css = ".star-rating {\n width: 0;\n position: relative;\n display: inline-block;\n background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDguOSIgaGVpZ2h0PSIxMDMuNiIgdmlld0JveD0iMCAwIDEwOC45IDEwMy42Ij48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6I2UzZTZlNjt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPnN0YXJfMDwvdGl0bGU+PGcgaWQ9IkxheWVyXzIiIGRhdGEtbmFtZT0iTGF5ZXIgMiI+PGcgaWQ9IkxheWVyXzEtMiIgZGF0YS1uYW1lPSJMYXllciAxIj48cG9seWdvbiBjbGFzcz0iY2xzLTEiIHBvaW50cz0iMTA4LjkgMzkuNiA3MS4zIDM0LjEgNTQuNCAwIDM3LjYgMzQuMSAwIDM5LjYgMjcuMiA2Ni4xIDIwLjggMTAzLjYgNTQuNCA4NS45IDg4LjEgMTAzLjYgODEuNyA2Ni4xIDEwOC45IDM5LjYiLz48L2c+PC9nPjwvc3ZnPgo=);\n background-position: 0 0;\n background-repeat: repeat-x;\n cursor: pointer;\n}\n.star-rating[data-title]:hover:after {\n content: attr(data-title);\n padding: 4px 8px;\n color: #333;\n position: absolute;\n left: 0;\n top: 100%;\n z-index: 20;\n white-space: nowrap;\n -moz-border-radius: 5px;\n -webkit-border-radius: 5px;\n border-radius: 5px;\n -moz-box-shadow: 0px 0px 4px #222;\n -webkit-box-shadow: 0px 0px 4px #222;\n box-shadow: 0px 0px 4px #222;\n background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);\n background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #eeeeee),color-stop(1, #cccccc));\n background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);\n background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);\n background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);\n background-image: -o-linear-gradient(top, #eeeeee, #cccccc);\n}\n.star-rating .star-value {\n height: 100%;\n position: absolute;\n}\n.star-rating .star-value {\n position: absolute;\n height: 100%;\n width: 100%;\n background: url('data:image/svg+xml;base64,PHN2ZwoJeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTA4LjkiIGhlaWdodD0iMTAzLjYiIHZpZXdCb3g9IjAgMCAxMDguOSAxMDMuNiI+Cgk8ZGVmcz4KCQk8c3R5bGU+LmNscy0xe2ZpbGw6I2YxYzk0Nzt9PC9zdHlsZT4KCTwvZGVmcz4KCTx0aXRsZT5zdGFyMTwvdGl0bGU+Cgk8ZyBpZD0iTGF5ZXJfMiIgZGF0YS1uYW1lPSJMYXllciAyIj4KCQk8ZyBpZD0iTGF5ZXJfMS0yIiBkYXRhLW5hbWU9IkxheWVyIDEiPgoJCQk8cG9seWdvbiBjbGFzcz0iY2xzLTEiIHBvaW50cz0iNTQuNCAwIDcxLjMgMzQuMSAxMDguOSAzOS42IDgxLjcgNjYuMSA4OC4xIDEwMy42IDU0LjQgODUuOSAyMC44IDEwMy42IDI3LjIgNjYuMSAwIDM5LjYgMzcuNiAzNC4xIDU0LjQgMCIvPgoJCTwvZz4KCTwvZz4KPC9zdmc+Cg==');\n background-repeat: repeat-x;\n}\n"; (require("browserify-css").createStyle(css, { "href": "lib\\style.css" }, { "insertAt": "bottom" })); module.exports = css;
225
  },{"browserify-css":3}],3:[function(require,module,exports){
226
  'use strict';
227
  // For more information about browser field, check out the browser field at https://github.com/substack/browserify-handbook#browser-field.
300
  };
301
 
302
  },{}]},{},[1])(1)
303
+ });
lib/yasr-functions.php CHANGED
@@ -47,7 +47,13 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
47
  wp_add_inline_style( 'yasrcss', YASR_CUSTOM_CSS_RULES );
48
  }
49
 
50
- wp_enqueue_script( 'rater', YASR_JS_DIR . 'rater-js.js' , '', YASR_VERSION_NUM, TRUE );
 
 
 
 
 
 
51
 
52
  wp_enqueue_script( 'yasrfront', YASR_JS_DIR . 'yasr-front.js' , array('jquery', 'rater'), YASR_VERSION_NUM, TRUE );
53
  wp_enqueue_script('tippy', YASR_JS_DIR . 'tippy.all.min.js', '', '3.6.0', TRUE );
47
  wp_add_inline_style( 'yasrcss', YASR_CUSTOM_CSS_RULES );
48
  }
49
 
50
+ if (!is_rtl()) {
51
+ wp_enqueue_script( 'rater', YASR_JS_DIR . 'rater-js.js' , '', YASR_VERSION_NUM, TRUE );
52
+ }
53
+ else {
54
+ wp_enqueue_script( 'rater', YASR_JS_DIR . 'rater-js-rtl.js' , '', YASR_VERSION_NUM, TRUE );
55
+ }
56
+
57
 
58
  wp_enqueue_script( 'yasrfront', YASR_JS_DIR . 'yasr-front.js' , array('jquery', 'rater'), YASR_VERSION_NUM, TRUE );
59
  wp_enqueue_script('tippy', YASR_JS_DIR . 'tippy.all.min.js', '', '3.6.0', TRUE );
readme.txt CHANGED
@@ -5,7 +5,7 @@ Requires at least: 4.3.0
5
  Contributors: Dudo
6
  Tested up to: 5.1
7
  Requires PHP: 5.3
8
- Stable tag: 1.9.1
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your website, e-commerce or blog with an easy and intuitive WordPress rating system!
@@ -127,6 +127,9 @@ If doesn't, it's suggested to ask in a SEO oriented forum.
127
 
128
  The full changelog can be found in the plugin's directory. Recent entries:
129
 
 
 
 
130
  = 1.9.1 =
131
  * FIXED: In some (rare) case, overall rating get empty with Gutenberg
132
 
@@ -176,4 +179,4 @@ External Libraries: [Rater](https://github.com/fredolss/rater-js)
176
  [tippy](https://atomiks.github.io/tippyjs/)
177
 
178
  Svg star icon made by [Freepik](http://www.freepik.com)
179
- from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)
5
  Contributors: Dudo
6
  Tested up to: 5.1
7
  Requires PHP: 5.3
8
+ Stable tag: 1.9.2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Boost the way people interact with your website, e-commerce or blog with an easy and intuitive WordPress rating system!
127
 
128
  The full changelog can be found in the plugin's directory. Recent entries:
129
 
130
+ = 1.9.2 =
131
+ * FIXED: Javascript error on some mobile device
132
+
133
  = 1.9.1 =
134
  * FIXED: In some (rare) case, overall rating get empty with Gutenberg
135
 
179
  [tippy](https://atomiks.github.io/tippyjs/)
180
 
181
  Svg star icon made by [Freepik](http://www.freepik.com)
182
+ from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)
yet-another-stars-rating.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Yet Another Stars Rating
5
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
6
  * Description: Yasr - Yet Another Stars Rating is a powerful way to add SEO-friendly user-generated reviews and testimonials to your website posts, pages and CPT, without affecting its speed.
7
- * Version: 1.9.1
8
  * Author: Dario Curvino
9
  * Author URI: https://dariocurvino.it/
10
  * Text Domain: yet-another-stars-rating
@@ -76,7 +76,7 @@ if ( !function_exists( 'yasr_fs' ) ) {
76
  yasr_fs();
77
  // Signal that SDK was initiated.
78
  do_action( 'yasr_fs_loaded' );
79
- define( 'YASR_VERSION_NUM', '1.9.1' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)
4
  * Plugin Name: Yet Another Stars Rating
5
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
6
  * Description: Yasr - Yet Another Stars Rating is a powerful way to add SEO-friendly user-generated reviews and testimonials to your website posts, pages and CPT, without affecting its speed.
7
+ * Version: 1.9.2
8
  * Author: Dario Curvino
9
  * Author URI: https://dariocurvino.it/
10
  * Text Domain: yet-another-stars-rating
76
  yasr_fs();
77
  // Signal that SDK was initiated.
78
  do_action( 'yasr_fs_loaded' );
79
+ define( 'YASR_VERSION_NUM', '1.9.2' );
80
  //Plugin relative path
81
  define( "YASR_ABSOLUTE_PATH", dirname( __FILE__ ) );
82
  //Plugin RELATIVE PATH without slashes (just the directory's name)