Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rater-js

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rater-js - npm Package Compare versions

Comparing version 0.5.6 to 0.5.7

1

index.d.ts

@@ -10,2 +10,3 @@ interface RaterOptions {

starSize?:number;
step?:number;
}

@@ -12,0 +13,0 @@

360

index.js
(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){
"use strict";
/*! rater-js. [c] 2018 Fredrik Olsson. MIT License */
var css = require('./style.css');
var css = require('./style.css');
module.exports = function rater(options) {
//private fields
var showToolTip = true;
//private fields
var showToolTip = true;
if (typeof options.element === "undefined" || options.element === null) {
throw new Error("element required");
}
if (typeof options.element === "undefined" || options.element === null) {
throw new Error("element required");
}
if (typeof options.showToolTip !== "undefined") {
showToolTip = !!options.showToolTip;
}
if (typeof options.showToolTip !== "undefined") {
showToolTip = !!options.showToolTip;
}
if (typeof options.step !== "undefined") {
if (options.step <= 0 || options.step > 1) {
throw new Error("step must be a number between 0 and 1");
}
}
if(typeof options.step !== "undefined") {
if(options.step <= 0 || options.step > 1){
throw new Error("step must be a number between 0 and 1");
}
}
var stars = options.max || 5;
var starSize = options.starSize || 16;
var step = options.step || 1;
var onHover = options.onHover;
var onLeave = options.onLeave;
var rating;
var myRating;
var elem = options.element;
elem.classList.add("star-rating");
var div = document.createElement("div");
div.classList.add("star-value");
div.style.backgroundSize = starSize + "px";
elem.appendChild(div);
elem.style.width = starSize * stars + "px";
elem.style.height = starSize + "px";
elem.style.backgroundSize = starSize + "px";
var callback = options.rateCallback;
var disabled = !!options.readOnly;
var disableText;
var isRating = false;
var isBusyText = options.isBusyText;
var currentRating;
var ratingText;
var stars = options.max || 5;
var starSize = options.starSize || 16;
var step = options.step || 1;
var onHover = options.onHover;
var onLeave = options.onLeave;
var rating;
var myRating;
var elem = options.element;
elem.classList.add("star-rating");
var div = document.createElement("div");
div.classList.add("star-value");
div.style.backgroundSize = starSize + "px";
elem.appendChild(div);
elem.style.width = starSize * stars + "px";
elem.style.height = starSize + "px";
elem.style.backgroundSize = starSize + "px";
var callback = options.rateCallback;
var disabled = !!options.readOnly;
var disableText;
var isRating = false;
var isBusyText = options.isBusyText;
var currentRating;
if (typeof options.disableText !== "undefined") {
disableText = options.disableText;
} else {
disableText = "{rating}/{maxRating}";
}
if (!options.readOnly) {
disableText = options.disableText || "Thank you for your vote!";
}
var ratingText = options.ratingText || "{rating}/{maxRating}";
if (typeof options.ratingText !== "undefined") {
ratingText = options.ratingText;
} else {
ratingText = "{rating}/{maxRating}";
}
if(options.rating){
setRating(options.rating);
} else {
var dataRating = elem.dataset.rating;
if (options.rating) {
setRating(options.rating);
} else {
var dataRating = elem.dataset.rating;
if(dataRating){
setRating(+dataRating);
}
}
if (dataRating) {
setRating(+dataRating);
}
}
if(typeof rating === "undefined"){
elem.querySelector(".star-value").style.width = "0px";
}
if (typeof rating === "undefined") {
elem.querySelector(".star-value").style.width = "0px";
}
//private methods
function onMouseMove(e) {
if (disabled) {
disable();
} //private methods
if(disabled){
if (showToolTip) {
let toolTip = ratingText.replace("{rating}", rating);
toolTip = toolTip.replace("{maxRating}", stars);
elem.setAttribute("data-title", toolTip);
}
}
if (disabled === true || isRating === true) {
return;
}
var xCoor = e.offsetX;
var width = elem.offsetWidth;
var percent = (xCoor/width) * 100;
function onMouseMove(e) {
if (disabled === true || isRating === true) {
return;
}
if (percent < 101) {
if(step === 1) {
currentRating = Math.ceil((percent / 100) * stars);
} else {
var rat = (percent / 100) * stars;
for(var i = 0;; i+=step){
if(i >= rat){
currentRating = i;
break;
}
}
}
if (showToolTip) {
let toolTip = ratingText.replace("{rating}", currentRating);
toolTip = toolTip.replace("{maxRating}", stars);
elem.setAttribute("data-title", toolTip);
}
elem.querySelector(".star-value").style.width = currentRating/stars * 100 + "%";
if (typeof onHover === "function") {
onHover(currentRating, rating);
}
}
}
var xCoor = e.offsetX;
var width = elem.offsetWidth;
var percent = xCoor / width * 100;
function onStarOut(e) {
if (percent < 101) {
if (step === 1) {
currentRating = Math.ceil(percent / 100 * stars);
} else {
var rat = percent / 100 * stars;
if (typeof rating !== "undefined") {
elem.querySelector(".star-value").style.width = rating/stars * 100 + "%";
elem.setAttribute("data-rating", rating);
} else {
elem.querySelector(".star-value").style.width = "0%";
elem.removeAttribute("data-rating");
}
for (var i = 0;; i += step) {
if (i >= rat) {
currentRating = i;
break;
}
}
}
if (typeof onLeave === "function") {
onLeave(currentRating, rating);
}
}
elem.querySelector(".star-value").style.width = currentRating / stars * 100 + "%";
function onStarClick(e) {
if (disabled === true) {
return;
}
if (showToolTip) {
var toolTip = ratingText.replace("{rating}", currentRating);
toolTip = toolTip.replace("{maxRating}", stars);
elem.setAttribute("data-title", toolTip);
}
if (isRating === true) {
return;
}
if (typeof onHover === "function") {
onHover(currentRating, rating);
}
}
}
if (typeof callback !== "undefined") {
isRating = true;
myRating = currentRating;
function onStarOut(e) {
if (typeof rating !== "undefined") {
elem.querySelector(".star-value").style.width = rating / stars * 100 + "%";
elem.setAttribute("data-rating", rating);
} else {
elem.querySelector(".star-value").style.width = "0%";
elem.removeAttribute("data-rating");
}
if (typeof isBusyText === "undefined") {
elem.removeAttribute("data-title");
} else {
elem.setAttribute("data-title", isBusyText);
}
callback.call(this, myRating, function() {
if (disabled === false) {
elem.removeAttribute("data-title");
}
if (typeof onLeave === "function") {
onLeave(currentRating, rating);
}
}
isRating = false;
});
}
}
function onStarClick(e) {
if (disabled === true) {
return;
}
//public methods
function disable() {
disabled = true;
elem.setAttribute("data-title", disableText);
}
if (isRating === true) {
return;
}
function enable() {
disabled = false;
elem.removeAttribute("data-title");
}
if (typeof callback !== "undefined") {
isRating = true;
myRating = currentRating;
function setRating(value) {
if(typeof value === "undefined"){
throw new Error("Value not set.");
}
if (typeof isBusyText === "undefined") {
elem.removeAttribute("data-title");
} else {
elem.setAttribute("data-title", isBusyText);
}
if(typeof value !== "number"){
throw new Error("Value must be a number.");
}
callback.call(this, myRating, function () {
if (disabled === false) {
elem.removeAttribute("data-title");
}
if(value < 0 || value > stars){
let ratingError = new Error("Value too high. Please set a rating of " + stars + " or below");
ratingError.name = "ratingError";
throw ratingError;
}
isRating = false;
});
}
} //public methods
rating = value;
elem.querySelector(".star-value").style.width = value/stars * 100 + "%";
elem.setAttribute("data-rating", value);
}
function getRating() {
return rating;
}
function disable() {
disabled = true;
function dispose() {
elem.removeEventListener("mousemove", onMouseMove);
elem.removeEventListener("mouseleave", onStarOut);
elem.removeEventListener("click", onStarClick);
}
elem.addEventListener("mousemove", onMouseMove);
elem.addEventListener("mouseleave", onStarOut);
if (showToolTip && !!disableText) {
var toolTip = disableText.replace("{rating}", rating);
toolTip = toolTip.replace("{maxRating}", stars);
elem.setAttribute("data-title", toolTip);
} else {
elem.removeAttribute("data-title");
}
}
var module = {
setRating:setRating,
getRating:getRating,
disable:disable,
enable:enable,
dispose:dispose
};
function enable() {
disabled = false;
elem.removeAttribute("data-title");
}
elem.addEventListener("click", onStarClick.bind(module));
function setRating(value) {
if (typeof value === "undefined") {
throw new Error("Value not set.");
}
return module;
}
if (typeof value !== "number") {
throw new Error("Value must be a number.");
}
if (value < 0 || value > stars) {
var ratingError = new Error("Value too high. Please set a rating of " + stars + " or below.");
ratingError.name = "ratingError";
throw ratingError;
}
rating = value;
elem.querySelector(".star-value").style.width = value / stars * 100 + "%";
elem.setAttribute("data-rating", value);
}
function getRating() {
return rating;
}
function dispose() {
elem.removeEventListener("mousemove", onMouseMove);
elem.removeEventListener("mouseleave", onStarOut);
elem.removeEventListener("click", onStarClick);
}
elem.addEventListener("mousemove", onMouseMove);
elem.addEventListener("mouseleave", onStarOut);
var module = {
setRating: setRating,
getRating: getRating,
disable: disable,
enable: enable,
dispose: dispose
};
elem.addEventListener("click", onStarClick.bind(module));
return module;
};
},{"./style.css":2}],2:[function(require,module,exports){

@@ -214,0 +222,0 @@ 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}\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;

/*! rater-js. [c] 2018 Fredrik Olsson. MIT License */
var css = require('./style.css');
let css = require('./style.css');

@@ -8,3 +8,3 @@ module.exports = function rater(options) {

//private fields
var showToolTip = true;
let showToolTip = true;

@@ -16,3 +16,3 @@ if (typeof options.element === "undefined" || options.element === null) {

if (typeof options.showToolTip !== "undefined") {
showToolTip = !!options.showToolTip;
showToolTip = !!options.showToolTip;
}

@@ -26,12 +26,12 @@

var stars = options.max || 5;
var starSize = options.starSize || 16;
var step = options.step || 1;
var onHover = options.onHover;
var onLeave = options.onLeave;
var rating;
var myRating;
var elem = options.element;
let stars = options.max || 5;
let starSize = options.starSize || 16;
let step = options.step || 1;
let onHover = options.onHover;
let onLeave = options.onLeave;
let rating;
let myRating;
let elem = options.element;
elem.classList.add("star-rating");
var div = document.createElement("div");
let div = document.createElement("div");
div.classList.add("star-value");

@@ -43,15 +43,22 @@ div.style.backgroundSize = starSize + "px";

elem.style.backgroundSize = starSize + "px";
var callback = options.rateCallback;
var disabled = !!options.readOnly;
var disableText;
var isRating = false;
var isBusyText = options.isBusyText;
var currentRating;
let callback = options.rateCallback;
let disabled = !!options.readOnly;
let disableText;
let isRating = false;
let isBusyText = options.isBusyText;
let currentRating;
let ratingText;
if (typeof options.disableText !== "undefined") {
disableText = options.disableText;
} else {
disableText = "{rating}/{maxRating}";
}
if (!options.readOnly) {
disableText = options.disableText || "Thank you for your vote!";
if(typeof options.ratingText !== "undefined"){
ratingText = options.ratingText;
} else {
ratingText = "{rating}/{maxRating}";
}
var ratingText = options.ratingText || "{rating}/{maxRating}";
if(options.rating){

@@ -71,13 +78,9 @@ setRating(options.rating);

if(disabled){
disable();
}
//private methods
function onMouseMove(e) {
if(disabled){
if (showToolTip) {
let toolTip = ratingText.replace("{rating}", rating);
toolTip = toolTip.replace("{maxRating}", stars);
elem.setAttribute("data-title", toolTip);
}
}
if (disabled === true || isRating === true) {

@@ -87,5 +90,5 @@ return;

var xCoor = e.offsetX;
var width = elem.offsetWidth;
var percent = (xCoor/width) * 100;
let xCoor = e.offsetX;
let width = elem.offsetWidth;
let percent = (xCoor/width) * 100;

@@ -96,4 +99,4 @@ if (percent < 101) {

} else {
var rat = (percent / 100) * stars;
for(var i = 0;; i+=step){
let rat = (percent / 100) * stars;
for(let i = 0;; i+=step){
if(i >= rat){

@@ -105,3 +108,5 @@ currentRating = i;

}
elem.querySelector(".star-value").style.width = currentRating/stars * 100 + "%";
if (showToolTip) {

@@ -112,4 +117,3 @@ let toolTip = ratingText.replace("{rating}", currentRating);

}
elem.querySelector(".star-value").style.width = currentRating/stars * 100 + "%";
if (typeof onHover === "function") {

@@ -168,3 +172,9 @@ onHover(currentRating, rating);

disabled = true;
elem.setAttribute("data-title", disableText);
if(showToolTip && !!disableText){
let toolTip = disableText.replace("{rating}", rating);
toolTip = toolTip.replace("{maxRating}", stars);
elem.setAttribute("data-title", toolTip);
} else {
elem.removeAttribute("data-title");
}
}

@@ -187,3 +197,3 @@

if(value < 0 || value > stars){
let ratingError = new Error("Value too high. Please set a rating of " + stars + " or below");
let ratingError = new Error("Value too high. Please set a rating of " + stars + " or below.");
ratingError.name = "ratingError";

@@ -211,3 +221,3 @@ throw ratingError;

var module = {
let module = {
setRating:setRating,

@@ -214,0 +224,0 @@ getRating:getRating,

{
"name": "rater-js",
"description": "Star rating widget for the browser.",
"version": "0.5.6",
"version": "0.5.7",
"repository": {

@@ -13,3 +13,3 @@ "type": "git",

"scripts": {
"build": "browserify -t [ browserify-css --inlineImages ] ./lib/rater-js -o index.js --standalone rater-js",
"build": "browserify -t [ browserify-css --inlineImages] -t [babelify --presets [ @babel/preset-env] ] ./lib/rater-js -o index.js --standalone rater-js",
"test": "mocha --require ignore-styles"

@@ -35,2 +35,5 @@ },

"devDependencies": {
"@babel/core": "^7.0.0-beta.47",
"@babel/preset-env": "^7.0.0-beta.47",
"babelify": "^9.0.0",
"browserify": "^16.1.1",

@@ -37,0 +40,0 @@ "browserify-css": "^0.14.0",

@@ -5,3 +5,3 @@ Rater Js

![rater-js Logo](ratings.png)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=N2F7QTTZAHKZS)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/folssondev)
[![NPM version][npm-image]][npm-url]

@@ -8,0 +8,0 @@ [![License][license-image]][license-url]

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc