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

jquery-bar-rating

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jquery-bar-rating - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

2

bower.json
{
"name": "jquery-bar-rating",
"version": "1.2.1",
"version": "1.2.2",
"homepage": "http://antenna.io/demo/jquery-bar-rating/examples/",

@@ -5,0 +5,0 @@ "repository": {

@@ -0,1 +1,16 @@

1.2.2
-----
- new option added: `allowEmpty`
- new option added: `emptyValue`
- bugfix: accept empty string in set method (@kzmi, [#85](https://github.com/antennaio/jquery-bar-rating/pull/85))
- bugfix: little CSS fix (@bygiro, [#74](https://github.com/antennaio/jquery-bar-rating/pull/74))
- bugfix: syntax error within example in documentation (@sorter, [#72](https://github.com/antennaio/jquery-bar-rating/pull/72))
- added optimal travis config (@amilajack, [#71](https://github.com/antennaio/jquery-bar-rating/pull/71))
1.2.1

@@ -2,0 +17,0 @@ -----

@@ -1,2 +0,2 @@

!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof module&&module.exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){var e=function(){function e(){var e=this,n=function(){var n=["br-wrapper"];""!==e.options.theme&&n.push("br-theme-"+e.options.theme),e.$elem.wrap(t("<div />",{"class":n.join(" ")}))},i=function(){e.$elem.unwrap()},a=function(n){return t.isNumeric(n)&&(n=Math.floor(n)),t('option[value="'+n+'"]',e.$elem)},r=function(){var n=e.options.initialRating;return n?a(n):t("option:selected",e.$elem)},o=function(t){var n=e.$elem.data("barrating");return"undefined"!=typeof t?n[t]:n},l=function(t,n){null!==n&&"object"==typeof n?e.$elem.data("barrating",n):e.$elem.data("barrating")[t]=n},s=function(){var t=r(),n=t.val(),i=t.data("html")?t.data("html"):t.text();l(null,{userOptions:e.options,ratingValue:n,ratingText:i,originalRatingValue:n,originalRatingText:i,readOnly:e.options.readonly,ratingMade:!1})},u=function(){e.$elem.removeData("barrating")},d=function(){return o("ratingText")},c=function(){return o("ratingValue")},f=function(){var n=t("<div />",{"class":"br-widget"});return e.$elem.find("option").each(function(){var i,a,r,o;i=t(this).val(),i&&(a=t(this).text(),r=t(this).data("html"),r&&(a=r),o=t("<a />",{href:"#","data-rating-value":i,"data-rating-text":a,html:e.options.showValues?a:""}),n.append(o))}),e.options.showSelectedRating&&n.append(t("<div />",{text:"","class":"br-current-rating"})),e.options.reverse&&n.addClass("br-reverse"),e.options.readonly&&n.addClass("br-readonly"),n},g=function(){return o("userOptions").reverse?"nextAll":"prevAll"},p=function(t){a(t).prop("selected",!0),e.$elem.change()},h=function(){t("option",e.$elem).prop("selected",function(){return this.defaultSelected}),e.$elem.change()},v=function(t){t=t?t:d(),e.options.showSelectedRating&&e.$elem.parent().find(".br-current-rating").text(t)},m=function(t){return Math.round(Math.floor(10*t)/10%1*100)},b=function(){e.$widget.find("a").removeClass(function(t,e){return(e.match(/(^|\s)br-\S+/g)||[]).join(" ")})},$=function(){var n,i,a=e.$widget.find('a[data-rating-value="'+c()+'"]'),r=o("userOptions").initialRating,l=t.isNumeric(c())?c():0,s=m(r);if(b(),a.addClass("br-selected br-current")[g()]().addClass("br-selected"),!o("ratingMade")&&t.isNumeric(r)){if(l>=r||!s)return;n=e.$widget.find("a"),i=a.length?a[o("userOptions").reverse?"prev":"next"]():n[o("userOptions").reverse?"last":"first"](),i.addClass("br-fractional"),i.addClass("br-fractional-"+s)}},w=function(t){return e.options.deselectable?e.$elem.find("option:first").val()?!1:c()==t.attr("data-rating-value"):!1},y=function(n){n.on("click.barrating",function(n){var i,a,r=t(this),s=o("userOptions");return n.preventDefault(),i=r.attr("data-rating-value"),a=r.attr("data-rating-text"),w(r)&&(i="",a=""),l("ratingValue",i),l("ratingText",a),l("ratingMade",!0),p(i),v(a),$(),s.onSelect.call(e,c(),d(),n),!1})},x=function(e){e.on("mouseenter.barrating",function(){var e=t(this);b(),e.addClass("br-active")[g()]().addClass("br-active"),v(e.attr("data-rating-text"))})},C=function(t){e.$widget.on("mouseleave.barrating blur.barrating",function(){v(),$()})},O=function(e){e.on("touchstart.barrating",function(e){e.preventDefault(),e.stopPropagation(),t(this).click()})},R=function(t){t.on("click.barrating",function(t){t.preventDefault()})},S=function(t){y(t),e.options.hoverState&&(x(t),C(t))},j=function(t){t.off(".barrating")},M=function(t){var n=e.$widget.find("a");O&&O(n),t?(j(n),R(n)):S(n)};this.show=function(){o()||(n(),s(),e.$widget=f(),e.$widget.insertAfter(e.$elem),$(),v(),M(e.options.readonly),e.$elem.hide())},this.readonly=function(t){"boolean"==typeof t&&o("readOnly")!=t&&(M(t),l("readOnly",t),e.$widget.toggleClass("br-readonly"))},this.set=function(t){var n=o("userOptions");e.$elem.find('option[value="'+t+'"]').val()&&(l("ratingValue",t),l("ratingText",e.$elem.find('option[value="'+t+'"]').text()),l("ratingMade",!0),p(c()),v(d()),$(),n.silent||n.onSelect.call(this,c(),d()))},this.clear=function(){var t=o("userOptions");l("ratingValue",o("originalRatingValue")),l("ratingText",o("originalRatingText")),l("ratingMade",!1),h(),v(d()),$(),t.onClear.call(this,c(),d())},this.destroy=function(){var t=c(),n=d(),a=o("userOptions");j(e.$widget.find("a")),e.$widget.remove(),u(),i(),e.$elem.show(),a.onDestroy.call(this,t,n)}}return e.prototype.init=function(e,n){return this.$elem=t(n),this.options=t.extend({},t.fn.barrating.defaults,e),this.options},e}();t.fn.barrating=function(n,i){return this.each(function(){var a=new e;if(t(this).is("select")||t.error("Sorry, this plugin only works with select fields."),a.hasOwnProperty(n)){if(a.init(i,this),"show"===n)return a.show(i);if(a.$elem.data("barrating"))return a.$widget=t(this).next(".br-widget"),a[n](i)}else{if("object"==typeof n||!n)return i=n,a.init(i,this),a.show();t.error("Method "+n+" does not exist on jQuery.barrating")}})},t.fn.barrating.defaults={theme:"",initialRating:null,showValues:!1,showSelectedRating:!0,deselectable:!0,reverse:!1,readonly:!1,fastClicks:!0,hoverState:!0,silent:!1,onSelect:function(t,e,n){},onClear:function(t,e){},onDestroy:function(t,e){}},t.fn.barrating.BarRating=e});
!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof module&&module.exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){var e=function(){function e(){var e=this,n=function(){var n=["br-wrapper"];""!==e.options.theme&&n.push("br-theme-"+e.options.theme),e.$elem.wrap(t("<div />",{"class":n.join(" ")}))},i=function(){e.$elem.unwrap()},a=function(n){return t.isNumeric(n)&&(n=Math.floor(n)),t('option[value="'+n+'"]',e.$elem)},r=function(){var n=e.options.initialRating;return n?a(n):t("option:selected",e.$elem)},o=function(){var n=e.$elem.find('option[value="'+e.options.emptyValue+'"]');return!n.length&&e.options.allowEmpty?(n=t("<option />",{value:e.options.emptyValue}),n.prependTo(e.$elem)):n},l=function(t){var n=e.$elem.data("barrating");return"undefined"!=typeof t?n[t]:n},s=function(t,n){null!==n&&"object"==typeof n?e.$elem.data("barrating",n):e.$elem.data("barrating")[t]=n},u=function(){var t=r(),n=o(),i=t.val(),a=t.data("html")?t.data("html"):t.text(),l=null!==e.options.allowEmpty?e.options.allowEmpty:!!n.length,u=n.length?n.val():null,d=n.length?n.text():null;s(null,{userOptions:e.options,ratingValue:i,ratingText:a,originalRatingValue:i,originalRatingText:a,allowEmpty:l,emptyRatingValue:u,emptyRatingText:d,readOnly:e.options.readonly,ratingMade:!1})},d=function(){e.$elem.removeData("barrating")},c=function(){return l("ratingText")},f=function(){return l("ratingValue")},g=function(){var n=t("<div />",{"class":"br-widget"});return e.$elem.find("option").each(function(){var i,a,r,o;i=t(this).val(),i!==l("emptyRatingValue")&&(a=t(this).text(),r=t(this).data("html"),r&&(a=r),o=t("<a />",{href:"#","data-rating-value":i,"data-rating-text":a,html:e.options.showValues?a:""}),n.append(o))}),e.options.showSelectedRating&&n.append(t("<div />",{text:"","class":"br-current-rating"})),e.options.reverse&&n.addClass("br-reverse"),e.options.readonly&&n.addClass("br-readonly"),n},p=function(){return l("userOptions").reverse?"nextAll":"prevAll"},h=function(t){a(t).prop("selected",!0),e.$elem.change()},m=function(){t("option",e.$elem).prop("selected",function(){return this.defaultSelected}),e.$elem.change()},v=function(t){t=t?t:c(),t==l("emptyRatingText")&&(t=""),e.options.showSelectedRating&&e.$elem.parent().find(".br-current-rating").text(t)},y=function(t){return Math.round(Math.floor(10*t)/10%1*100)},b=function(){e.$widget.find("a").removeClass(function(t,e){return(e.match(/(^|\s)br-\S+/g)||[]).join(" ")})},w=function(){var n,i,a=e.$widget.find('a[data-rating-value="'+f()+'"]'),r=l("userOptions").initialRating,o=t.isNumeric(f())?f():0,s=y(r);if(b(),a.addClass("br-selected br-current")[p()]().addClass("br-selected"),!l("ratingMade")&&t.isNumeric(r)){if(o>=r||!s)return;n=e.$widget.find("a"),i=a.length?a[l("userOptions").reverse?"prev":"next"]():n[l("userOptions").reverse?"last":"first"](),i.addClass("br-fractional"),i.addClass("br-fractional-"+s)}},$=function(t){return l("allowEmpty")&&l("userOptions").deselectable?f()==t.attr("data-rating-value"):!1},x=function(n){n.on("click.barrating",function(n){var i,a,r=t(this),o=l("userOptions");return n.preventDefault(),i=r.attr("data-rating-value"),a=r.attr("data-rating-text"),$(r)&&(i=l("emptyRatingValue"),a=l("emptyRatingText")),s("ratingValue",i),s("ratingText",a),s("ratingMade",!0),h(i),v(a),w(),o.onSelect.call(e,f(),c(),n),!1})},R=function(e){e.on("mouseenter.barrating",function(){var e=t(this);b(),e.addClass("br-active")[p()]().addClass("br-active"),v(e.attr("data-rating-text"))})},V=function(t){e.$widget.on("mouseleave.barrating blur.barrating",function(){v(),w()})},O=function(e){e.on("touchstart.barrating",function(e){e.preventDefault(),e.stopPropagation(),t(this).click()})},C=function(t){t.on("click.barrating",function(t){t.preventDefault()})},S=function(t){x(t),e.options.hoverState&&(R(t),V(t))},T=function(t){t.off(".barrating")},j=function(t){var n=e.$widget.find("a");O&&O(n),t?(T(n),C(n)):S(n)};this.show=function(){l()||(n(),u(),e.$widget=g(),e.$widget.insertAfter(e.$elem),w(),v(),j(e.options.readonly),e.$elem.hide())},this.readonly=function(t){"boolean"==typeof t&&l("readOnly")!=t&&(j(t),s("readOnly",t),e.$widget.toggleClass("br-readonly"))},this.set=function(t){var n=l("userOptions");0!==e.$elem.find('option[value="'+t+'"]').length&&(s("ratingValue",t),s("ratingText",e.$elem.find('option[value="'+t+'"]').text()),s("ratingMade",!0),h(f()),v(c()),w(),n.silent||n.onSelect.call(this,f(),c()))},this.clear=function(){var t=l("userOptions");s("ratingValue",l("originalRatingValue")),s("ratingText",l("originalRatingText")),s("ratingMade",!1),m(),v(c()),w(),t.onClear.call(this,f(),c())},this.destroy=function(){var t=f(),n=c(),a=l("userOptions");T(e.$widget.find("a")),e.$widget.remove(),d(),i(),e.$elem.show(),a.onDestroy.call(this,t,n)}}return e.prototype.init=function(e,n){return this.$elem=t(n),this.options=t.extend({},t.fn.barrating.defaults,e),this.options},e}();t.fn.barrating=function(n,i){return this.each(function(){var a=new e;if(t(this).is("select")||t.error("Sorry, this plugin only works with select fields."),a.hasOwnProperty(n)){if(a.init(i,this),"show"===n)return a.show(i);if(a.$elem.data("barrating"))return a.$widget=t(this).next(".br-widget"),a[n](i)}else{if("object"==typeof n||!n)return i=n,a.init(i,this),a.show();t.error("Method "+n+" does not exist on jQuery.barrating")}})},t.fn.barrating.defaults={theme:"",initialRating:null,allowEmpty:null,emptyValue:"",showValues:!1,showSelectedRating:!0,deselectable:!0,reverse:!1,readonly:!1,fastClicks:!0,hoverState:!0,silent:!1,onSelect:function(t,e,n){},onClear:function(t,e){},onDestroy:function(t,e){}},t.fn.barrating.BarRating=e});
//# sourceMappingURL=jquery.barrating.min.js.map

@@ -24,2 +24,4 @@ $(function() {

showSelectedRating: false,
allowEmpty: true,
emptyValue: '-- no rating selected --',
onSelect: function(value, text) {

@@ -26,0 +28,0 @@ alert('Selected rating: ' + value);

/**
* jQuery Bar Rating Plugin v1.2.1
* jQuery Bar Rating Plugin v1.2.2
*

@@ -56,4 +56,4 @@ * http://github.com/antennaio/jquery-bar-rating

// find initial option
var findInitialOption = function() {
// get initial option
var getInitialOption = function() {
var initialRating = self.options.initialRating;

@@ -68,2 +68,15 @@

// get empty option
var getEmptyOption = function() {
var $emptyOpt = self.$elem.find('option[value="' + self.options.emptyValue + '"]');
if (!$emptyOpt.length && self.options.allowEmpty) {
$emptyOpt = $('<option />', { 'value': self.options.emptyValue });
return $emptyOpt.prependTo(self.$elem);
}
return $emptyOpt;
};
// get data

@@ -91,3 +104,4 @@ var getData = function(key) {

var saveDataOnElement = function() {
var $opt = findInitialOption();
var $opt = getInitialOption();
var $emptyOpt = getEmptyOption();

@@ -97,2 +111,10 @@ var value = $opt.val();

// if the allowEmpty option is not set let's check if empty option exists in the select field
var allowEmpty = (self.options.allowEmpty !== null) ?
self.options.allowEmpty :
!!$emptyOpt.length;
var emptyValue = ($emptyOpt.length) ? $emptyOpt.val() : null;
var emptyText = ($emptyOpt.length) ? $emptyOpt.text() : null;
setData(null, {

@@ -109,2 +131,9 @@ userOptions: self.options,

// allow empty ratings?
allowEmpty: allowEmpty,
// rating value and text of the empty OPTION
emptyRatingValue: emptyValue,
emptyRatingText: emptyText,
// read-only state

@@ -143,4 +172,4 @@ readOnly: self.options.readonly,

// create ratings - but only if val is defined
if (val) {
// create ratings - but only if val is not defined as empty
if (val !== getData('emptyRatingValue')) {
text = $(this).text();

@@ -210,2 +239,7 @@ html = $(this).data('html');

// special case when the selected rating is defined as empty
if (text == getData('emptyRatingText')) {
text = '';
}
// update .br-current-rating div

@@ -262,11 +296,6 @@ if (self.options.showSelectedRating) {

var isDeselectable = function($element) {
if (!self.options.deselectable) {
if (!getData('allowEmpty') || !getData('userOptions').deselectable) {
return false;
}
if (self.$elem.find('option:first').val()) {
// empty option not found
return false;
}
return (ratingValue() == $element.attr('data-rating-value'));

@@ -290,4 +319,4 @@ };

if (isDeselectable($a)) {
value = '';
text = '';
value = getData('emptyRatingValue');
text = getData('emptyRatingText');
}

@@ -426,3 +455,3 @@

if (!self.$elem.find('option[value="' + value + '"]').val()) return;
if (self.$elem.find('option[value="' + value + '"]').length === 0) return;

@@ -546,5 +575,7 @@ // set data

initialRating:null, // initial rating
allowEmpty:null, // allow empty ratings?
emptyValue:'', // this is the expected value of the empty rating
showValues:false, // display rating values on the bars?
showSelectedRating:true, // append a div with a rating to the widget?
deselectable:true, // allow to deselect ratings
deselectable:true, // allow to deselect ratings?
reverse:false, // reverse the rating?

@@ -551,0 +582,0 @@ readonly:false, // make the rating ready-only?

{
"name": "jquery-bar-rating",
"description": "Minimal, light-weight jQuery ratings.",
"version": "1.2.1",
"version": "1.2.2",
"main": "jquery.barrating.js",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -32,6 +32,12 @@ var expect = window.chai.expect;

expect(BarRating.options.initialRating).to.equal(null);
expect(BarRating.options.allowEmpty).to.equal(null);
expect(BarRating.options.emptyValue).to.equal('');
expect(BarRating.options.showValues).to.equal(false);
expect(BarRating.options.showSelectedRating).to.equal(true);
expect(BarRating.options.deselectable).to.equal(true);
expect(BarRating.options.reverse).to.equal(false);
expect(BarRating.options.readonly).to.equal(false);
expect(BarRating.options.fastClicks).to.equal(true);
expect(BarRating.options.hoverState).to.equal(true);
expect(BarRating.options.silent).to.equal(false);
});

@@ -209,2 +215,31 @@

describe('bar rating plugin on show and empty ratings are allowed', function () {
before(function () {
createSelect();
$('#rating').barrating('show', {
allowEmpty: true,
emptyValue: '-- not defined --'
});
});
after(function () {
$('#rating').barrating('destroy');
destroySelect();
});
it('should update data', function () {
expect($('#rating').data('barrating').allowEmpty).to.equal(true);
expect($('#rating').data('barrating').emptyRatingValue).to.equal('-- not defined --');
expect($('#rating').data('barrating').emptyRatingText).to.equal('');
});
it('should set correct class', function () {
expect($('#rating option').first().val()).to.equal('-- not defined --');
});
});
describe('bar rating plugin reversed', function () {

@@ -211,0 +246,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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