New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.1.4 to 1.2.0

dist/themes/fontawesome-stars-o.css

2

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

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

@@ -0,1 +1,14 @@

1.2.0
_____
- deprecated `wrapperClass` option removed
- readonly ratings - `cursor: default` rule added to all themes
- support for displaying of fractional star ratings (2.5, 3.7, 4.9) - fractional ratings will be marked with `br-fractional` and `br-fractional-*` classes (where * is 10, 20, 30...)
- reset select field when ratings are cleared
- `deselectable` option added
1.1.4

@@ -2,0 +15,0 @@ -----

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

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

@@ -24,3 +24,3 @@ $(function() {

showSelectedRating: false,
onSelect:function(value, text) {
onSelect: function(value, text) {
alert('Selected rating: ' + value);

@@ -55,3 +55,44 @@ }

showSelectedRating: false
});
});
var currentRating = $('#example-fontawesome-o').data('current-rating');
$('.stars-example-fontawesome-o .current-rating')
.find('span')
.html(currentRating);
$('.stars-example-fontawesome-o .clear-rating').on('click', function(event) {
event.preventDefault();
$('#example-fontawesome-o')
.barrating('clear');
});
$('#example-fontawesome-o').barrating({
theme: 'fontawesome-stars-o',
showSelectedRating: false,
initialRating: currentRating,
onSelect: function(value, text) {
if (!value) {
$('#example-fontawesome-o')
.barrating('clear');
} else {
$('.stars-example-fontawesome-o .current-rating')
.addClass('hidden');
$('.stars-example-fontawesome-o .your-rating')
.removeClass('hidden')
.find('span')
.html(value);
}
},
onClear: function(value, text) {
$('.stars-example-fontawesome-o')
.find('.current-rating')
.removeClass('hidden')
.end()
.find('.your-rating')
.addClass('hidden');
}
});
}

@@ -58,0 +99,0 @@

/**
* jQuery Bar Rating Plugin v1.1.4
* jQuery Bar Rating Plugin v1.2.0
*
* http://github.com/antennaio/jquery-bar-rating
*
* Copyright (c) 2012-2015 Kazik Pietruszewski
* Copyright (c) 2012-2016 Kazik Pietruszewski
*
* Dual licensed under the MIT and GPL licenses:
* This plugin is available under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/

@@ -32,3 +31,3 @@ (function (factory) {

var wrapElement = function() {
var classes = [self.options.wrapperClass];
var classes = ['br-wrapper'];

@@ -49,13 +48,20 @@ if (self.options.theme !== '') {

// return initial option
// find option by value
var findOption = function(value) {
if ($.isNumeric(value)) {
value = Math.floor(value);
}
return $('option[value="' + value + '"]', self.$elem);
};
// find initial option
var findInitialOption = function() {
var option;
var initialRating = self.options.initialRating;
if (self.options.initialRating) {
option = $('option[value="' + self.options.initialRating + '"]', self.$elem);
} else {
option = $('option:selected', self.$elem);
if (!initialRating) {
return $('option:selected', self.$elem);
}
return option;
return findOption(initialRating);
};

@@ -87,2 +93,5 @@

var value = $opt.val();
var text = $opt.data('html') ? $opt.data('html') : $opt.text();
setData(null, {

@@ -92,8 +101,8 @@ userOptions: self.options,

// initial rating based on the OPTION value
ratingValue: $opt.val(),
ratingText: ($opt.data('html')) ? $opt.data('html') : $opt.text(),
ratingValue: value,
ratingText: text,
// rating will be restored by calling clear method
originalRatingValue: $opt.val(),
originalRatingText: ($opt.data('html')) ? $opt.data('html') : $opt.text(),
originalRatingValue: value,
originalRatingText: text,

@@ -103,4 +112,4 @@ // read-only state

// first OPTION empty - allow deselecting of ratings
deselectable: (!self.$elem.find('option:first').val()) ? true : false
// did the user already select a rating?
ratingMade: false
});

@@ -180,7 +189,17 @@ };

var setSelectFieldValue = function(value) {
// change selected OPTION in the select field (hidden)
self.$elem.find('option[value="' + value + '"]').prop('selected', true);
// change selected option
findOption(value).prop('selected', true);
self.$elem.change();
};
// reset select field
var resetSelectField = function() {
$('option', self.$elem).prop('selected', function() {
return this.defaultSelected;
});
self.$elem.change();
};
// display the currently selected rating

@@ -197,11 +216,40 @@ var showSelectedRating = function(text) {

// return rounded fraction of a value (14.4 -> 40, 0.99 -> 90)
var fraction = function(value) {
return Math.round(((Math.floor(value * 10) / 10) % 1) * 100);
};
// remove all classes from elements
var resetStyle = function() {
self.$widget.find('a').removeClass();
};
// apply style by setting classes on elements
var applyStyle = function() {
// remove classes
self.$widget.find('a').removeClass('br-selected br-current');
var $a = self.$widget.find('a[data-rating-value="' + ratingValue() + '"]');
var initialRating = getData('userOptions').initialRating;
var baseValue = $.isNumeric(ratingValue()) ? ratingValue() : 0;
var f = fraction(initialRating);
var $all, $fractional;
resetStyle();
// add classes
self.$widget.find('a[data-rating-value="' + ratingValue() + '"]')
.addClass('br-selected br-current')[nextAllorPreviousAll()]()
$a.addClass('br-selected br-current')[nextAllorPreviousAll()]()
.addClass('br-selected');
if (!getData('ratingMade') && $.isNumeric(initialRating)) {
if ((initialRating <= baseValue) || !f) {
return;
}
$all = self.$widget.find('a');
$fractional = ($a.length) ?
$a[(getData('userOptions').reverse) ? 'prev' : 'next']() :
$all[(getData('userOptions').reverse) ? 'last' : 'first']();
$fractional.addClass('br-fractional');
$fractional.addClass('br-fractional-' + f);
}
};

@@ -211,3 +259,12 @@

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

@@ -225,6 +282,2 @@

$elements.removeClass('br-active br-selected');
$a.addClass('br-selected')[nextAllorPreviousAll()]()
.addClass('br-selected');
value = $a.attr('data-rating-value');

@@ -235,8 +288,4 @@ text = $a.attr('data-rating-text');

if (isDeselectable($a)) {
$a.removeClass('br-selected br-current')[nextAllorPreviousAll()]()
.removeClass('br-selected br-current');
value = ''; text = '';
} else {
$elements.removeClass('br-current');
$a.addClass('br-current');
value = '';
text = '';
}

@@ -247,2 +296,3 @@

setData('ratingText', text);
setData('ratingMade', true);

@@ -252,2 +302,4 @@ setSelectFieldValue(value);

applyStyle();
// onSelect callback

@@ -267,6 +319,7 @@ options.onSelect.call(

var attachMouseEnterHandler = function($elements) {
$elements.on('mouseenter.barrating focus.barrating', function() {
$elements.on('mouseenter.barrating', function() {
var $a = $(this);
$elements.removeClass('br-active br-selected');
resetStyle();
$a.addClass('br-active')[nextAllorPreviousAll()]()

@@ -282,3 +335,2 @@ .addClass('br-active');

self.$widget.on('mouseleave.barrating blur.barrating', function() {
$elements.removeClass('br-active');
showSelectedRating();

@@ -381,2 +433,3 @@ applyStyle();

setData('ratingText', self.$elem.find('option[value="' + value + '"]').text());
setData('ratingMade', true);

@@ -404,4 +457,5 @@ setSelectFieldValue(ratingValue());

setData('ratingText', getData('originalRatingText'));
setData('ratingMade', false);
setSelectFieldValue(ratingValue());
resetSelectField();
showSelectedRating(ratingText());

@@ -497,2 +551,3 @@

showSelectedRating:true, // append a div with a rating to the widget?
deselectable:true, // allow to deselect ratings
reverse:false, // reverse the rating?

@@ -503,3 +558,2 @@ readonly:false, // make the rating ready-only?

silent:false, // supress callbacks when controlling ratings programatically
wrapperClass:'br-wrapper', // class applied to wrapper div
onSelect:function (value, text, event) {

@@ -506,0 +560,0 @@ }, // callback fired when a rating is selected

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

@@ -6,0 +6,0 @@ "keywords": [

@@ -99,2 +99,42 @@ var expect = window.chai.expect;

describe('bar rating plugin on set fractional value', function () {
before(function () {
createSelect();
$('#rating')
.barrating('show', { initialRating: 3.3 });
});
after(function () {
$('#rating').barrating('destroy');
destroySelect();
});
it('should set .br-half class', function () {
expect($('.br-widget a:nth-child(4)').hasClass('br-fractional')).to.equal(true);
expect($('.br-widget a:nth-child(4)').hasClass('br-fractional-30')).to.equal(true);
});
});
describe('bar rating plugin on set fractional value < 1', function () {
before(function () {
createSelect();
$('#rating')
.barrating('show', { initialRating: 0.99 });
});
after(function () {
$('#rating').barrating('destroy');
destroySelect();
});
it('should set .br-half class', function () {
expect($('.br-widget a:first').hasClass('br-fractional')).to.equal(true);
expect($('.br-widget a:first').hasClass('br-fractional-90')).to.equal(true);
});
});
describe('bar rating themes', function() {

@@ -246,6 +286,2 @@

it('should update data', function () {
expect($('#rating').data('barrating').deselectable).to.equal(true);
});
it('should successfully deselect rating', function () {

@@ -285,2 +321,6 @@ expect($('#rating').data('barrating').ratingValue).to.equal('');

it('should reset select field', function () {
expect($('#rating').val()).to.equal('5');
});
it('should set correct class', function () {

@@ -287,0 +327,0 @@ expect($('.br-widget a:nth-child(4)').hasClass('br-selected')).to.equal(true);

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

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