diff --git a/CHANGELOG.md b/CHANGELOG.md index 51f17d3..2dca71c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -HEAD -____ +1.2 +___ - deprecated `wrapperClass` option removed diff --git a/bower.json b/bower.json index a665bea..cc3bc9e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-bar-rating", - "version": "1.1.4", + "version": "1.2", "homepage": "http://antenna.io/demo/jquery-bar-rating/examples/", "repository": { "type": "git", diff --git a/dist/jquery.barrating.min.js b/dist/jquery.barrating.min.js index 4cd82fa..0600dca 100644 --- a/dist/jquery.barrating.min.js +++ b/dist/jquery.barrating.min.js @@ -1,2 +1,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("
",{"class":n.join(" ")}))},r=function(){t.$elem.unwrap()},a=function(n){return e.isNumeric(n)&&(n=Math.floor(n)),e('option[value="'+n+'"]',t.$elem)},i=function(){var n=t.options.initialRating;return n?a(n):e("option:selected",t.$elem)},o=function(e){var n=t.$elem.data("barrating");return"undefined"!=typeof e?n[e]:n},s=function(e,n){null!==n&&"object"==typeof n?t.$elem.data("barrating",n):t.$elem.data("barrating")[e]=n},l=function(){var e=i(),n=e.val(),r=e.data("html")?e.data("html"):e.text();s(null,{userOptions:t.options,ratingValue:n,ratingText:r,originalRatingValue:n,originalRatingText:r,readOnly:t.options.readonly,ratingMade:!1})},u=function(){t.$elem.removeData("barrating")},c=function(){return o("ratingText")},d=function(){return o("ratingValue")},f=function(){var n=e("
",{"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("",{href:"#","data-rating-value":r,"data-rating-text":a,html:t.options.showValues?a:""}),n.append(o))}),t.options.showSelectedRating&&n.append(e("
",{text:"","class":"br-current-rating"})),t.options.reverse&&n.addClass("br-reverse"),t.options.readonly&&n.addClass("br-readonly"),n},g=function(){return o("userOptions").reverse?"nextAll":"prevAll"},p=function(e){a(e).prop("selected",!0),t.$elem.change()},h=function(){e("option",t.$elem).prop("selected",function(){return this.defaultSelected}),t.$elem.change()},b=function(e){e=e?e:c(),t.options.showSelectedRating&&t.$elem.parent().find(".br-current-rating").text(e)},v=function(){var n=t.$widget.find('a[data-rating-value="'+d()+'"]'),r=o("userOptions").initialRating;t.$widget.find("a").removeClass("br-selected br-current br-half"),n.addClass("br-selected br-current")[g()]().addClass("br-selected"),!o("ratingMade")&&e.isNumeric(r)&&e.isNumeric(d())&&r>d()&&n[o("userOptions").reverse?"prev":"next"]().addClass("br-half")},m=function(e){return t.options.deselectable?t.$elem.find("option:first").val()?!1:e.hasClass("br-current"):!1},$=function(n){n.on("click.barrating",function(r){var a,i,l=e(this),u=o("userOptions");return r.preventDefault(),n.removeClass("br-active br-selected br-half"),l.addClass("br-selected")[g()]().addClass("br-selected"),a=l.attr("data-rating-value"),i=l.attr("data-rating-text"),m(l)?(l.removeClass("br-selected br-current")[g()]().removeClass("br-selected br-current"),a="",i=""):(n.removeClass("br-current"),l.addClass("br-current")),s("ratingValue",a),s("ratingText",i),s("ratingMade",!0),p(a),b(i),u.onSelect.call(t,d(),c(),r),!1})},w=function(t){t.on("mouseenter.barrating",function(){var n=e(this);t.removeClass("br-active br-selected br-half"),n.addClass("br-active")[g()]().addClass("br-active"),b(n.attr("data-rating-text"))})},y=function(e){t.$widget.on("mouseleave.barrating blur.barrating",function(){e.removeClass("br-active"),b(),v()})},C=function(t){t.on("touchstart.barrating",function(t){t.preventDefault(),t.stopPropagation(),e(this).click()})},x=function(e){e.on("click.barrating",function(e){e.preventDefault()})},O=function(e){$(e),t.options.hoverState&&(w(e),y(e))},R=function(e){e.off(".barrating")},S=function(e){$elements=t.$widget.find("a"),C&&C($elements),e?(R($elements),x($elements)):O($elements)};this.show=function(){o()||(n(),l(),t.$widget=f(),t.$widget.insertAfter(t.$elem),v(),b(),S(t.options.readonly),t.$elem.hide())},this.readonly=function(e){"boolean"==typeof e&&o("readOnly")!=e&&(S(e),s("readOnly",e),t.$widget.toggleClass("br-readonly"))},this.set=function(e){var n=o("userOptions");t.$elem.find('option[value="'+e+'"]').val()&&(s("ratingValue",e),s("ratingText",t.$elem.find('option[value="'+e+'"]').text()),s("ratingMade",!0),p(d()),b(c()),v(),n.silent||n.onSelect.call(this,d(),c()))},this.clear=function(){var e=o("userOptions");s("ratingValue",o("originalRatingValue")),s("ratingText",o("originalRatingText")),s("ratingMade",!1),h(),b(c()),v(),e.onClear.call(this,d(),c())},this.destroy=function(){var e=d(),n=c(),a=o("userOptions");R(t.$widget.find("a")),t.$widget.remove(),u(),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,deselectable:!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("
",{"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("
",{"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("",{href:"#","data-rating-value":i,"data-rating-text":a,html:e.options.showValues?a:""}),n.append(o))}),e.options.showSelectedRating&&n.append(t("
",{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 \ No newline at end of file diff --git a/dist/jquery.barrating.min.js.map b/dist/jquery.barrating.min.js.map index 08b3cf9..c6cc251 100644 --- a/dist/jquery.barrating.min.js.map +++ b/dist/jquery.barrating.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["jquery.barrating.js"],"names":["factory","define","amd","module","exports","require","jQuery","$","BarRating","self","this","wrapElement","classes","options","wrapperClass","theme","push","$elem","wrap","class","join","unwrapElement","unwrap","findOption","value","isNumeric","Math","floor","findInitialOption","initialRating","getData","key","data","setData","saveDataOnElement","$opt","val","text","userOptions","ratingValue","ratingText","originalRatingValue","originalRatingText","readOnly","readonly","ratingMade","removeDataOnElement","removeData","buildWidget","$w","find","each","html","$a","href","data-rating-value","data-rating-text","append","showSelectedRating","reverse","addClass","nextAllorPreviousAll","setSelectFieldValue","prop","change","resetSelectField","defaultSelected","parent","applyStyle","$widget","removeClass","isDeselectable","$element","deselectable","hasClass","attachClickHandler","$elements","on","event","preventDefault","attr","onSelect","call","attachMouseEnterHandler","attachMouseLeaveHandler","fastClicks","stopPropagation","click","disableClicks","attachHandlers","hoverState","detachHandlers","off","setupHandlers","show","insertAfter","hide","state","toggleClass","set","silent","clear","onClear","destroy","remove","onDestroy","prototype","init","elem","extend","fn","barrating","defaults","method","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AAOa,KAEzBoE,UAAU,SAAUjF,EAAOa,MAI/B9B,EAAEuG,GAAGC,UAAUvG,UAAYA","file":"jquery.barrating.min.js","sourcesContent":["/**\n * jQuery Bar Rating Plugin v1.1.4\n *\n * http://github.com/antennaio/jquery-bar-rating\n *\n * Copyright (c) 2012-2016 Kazik Pietruszewski\n *\n * This plugin is available under the MIT license.\n * http://www.opensource.org/licenses/mit-license.php\n */\n(function (factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD\n define(['jquery'], factory);\n } else if (typeof module === 'object' && module.exports) {\n // Node/CommonJS\n module.exports = factory(require('jquery'));\n } else {\n // browser globals\n factory(jQuery);\n }\n}(function ($) {\n\n var BarRating = (function() {\n\n function BarRating() {\n var self = this;\n\n // wrap element in a wrapper div\n var wrapElement = function() {\n var classes = [self.options.wrapperClass];\n\n if (self.options.theme !== '') {\n classes.push('br-theme-' + self.options.theme);\n }\n \n self.$elem.wrap($('
', {\n 'class': classes.join(' ')\n }));\n };\n\n // unwrap element\n var unwrapElement = function() {\n self.$elem.unwrap();\n };\n\n // find option by value\n var findOption = function(value) {\n if ($.isNumeric(value)) {\n value = Math.floor(value);\n }\n\n return $('option[value=\"' + value + '\"]', self.$elem);\n };\n\n // find initial option\n var findInitialOption = function() {\n var initialRating = self.options.initialRating;\n\n if (!initialRating) {\n return $('option:selected', self.$elem);\n }\n\n return findOption(initialRating);\n };\n\n // get data\n var getData = function(key) {\n var data = self.$elem.data('barrating');\n\n if (typeof key !== 'undefined') {\n return data[key];\n }\n\n return data;\n };\n\n // set data\n var setData = function(key, value) {\n if (value !== null && typeof value === 'object') {\n self.$elem.data('barrating', value);\n } else {\n self.$elem.data('barrating')[key] = value;\n }\n };\n\n // save data on element\n var saveDataOnElement = function() {\n var $opt = findInitialOption();\n\n var value = $opt.val();\n var text = $opt.data('html') ? $opt.data('html') : $opt.text();\n\n setData(null, {\n userOptions: self.options,\n\n // initial rating based on the OPTION value\n ratingValue: value,\n ratingText: text,\n\n // rating will be restored by calling clear method\n originalRatingValue: value,\n originalRatingText: text,\n\n // read-only state\n readOnly: self.options.readonly,\n\n // did the user already select a rating?\n ratingMade: false\n });\n };\n\n // remove data on element\n var removeDataOnElement = function() {\n self.$elem.removeData('barrating');\n };\n\n // return current rating text\n var ratingText = function() {\n return getData('ratingText');\n };\n\n // return current rating value\n var ratingValue = function() {\n return getData('ratingValue');\n };\n\n // build widget and return jQuery element\n var buildWidget = function() {\n var $w = $('
', { 'class': 'br-widget' });\n\n // create A elements that will replace OPTIONs\n self.$elem.find('option').each(function() {\n var val, text, html, $a;\n\n val = $(this).val();\n\n // create ratings - but only if val is defined\n if (val) {\n text = $(this).text();\n html = $(this).data('html');\n if (html) { text = html; }\n\n $a = $('', {\n 'href': '#',\n 'data-rating-value': val,\n 'data-rating-text': text,\n 'html': (self.options.showValues) ? text : ''\n });\n\n $w.append($a);\n }\n\n });\n\n // append .br-current-rating div to the widget\n if (self.options.showSelectedRating) {\n $w.append($('
', { 'text': '', 'class': 'br-current-rating' }));\n }\n\n // additional classes for the widget\n if (self.options.reverse) {\n $w.addClass('br-reverse');\n }\n\n if (self.options.readonly) {\n $w.addClass('br-readonly');\n }\n\n return $w;\n };\n\n // return a jQuery function name depending on the 'reverse' setting\n var nextAllorPreviousAll = function() {\n if (getData('userOptions').reverse) {\n return 'nextAll';\n } else {\n return 'prevAll';\n }\n };\n\n // set the value of the select field\n var setSelectFieldValue = function(value) {\n // change selected option\n findOption(value).prop('selected', true);\n\n self.$elem.change();\n };\n\n // reset select field\n var resetSelectField = function() {\n $('option', self.$elem).prop('selected', function() {\n return this.defaultSelected;\n });\n\n self.$elem.change();\n };\n\n // display the currently selected rating\n var showSelectedRating = function(text) {\n // text undefined?\n text = text ? text : ratingText();\n\n // update .br-current-rating div\n if (self.options.showSelectedRating) {\n self.$elem.parent().find('.br-current-rating').text(text);\n }\n };\n\n // apply style by setting classes on elements\n var applyStyle = function() {\n var $a = self.$widget.find('a[data-rating-value=\"' + ratingValue() + '\"]');\n var initialRating = getData('userOptions').initialRating;\n\n // remove classes\n self.$widget.find('a').removeClass('br-selected br-current br-half');\n\n // add classes\n $a.addClass('br-selected br-current')[nextAllorPreviousAll()]()\n .addClass('br-selected');\n\n if (!getData('ratingMade') && $.isNumeric(initialRating) && $.isNumeric(ratingValue())) {\n if (initialRating > ratingValue()) {\n $a[(getData('userOptions').reverse) ? 'prev' : 'next']().addClass('br-half');\n }\n }\n };\n\n // check if the element is deselectable?\n var isDeselectable = function($element) {\n if (!self.options.deselectable) {\n return false;\n }\n\n if (self.$elem.find('option:first').val()) {\n // empty option not found\n return false;\n }\n\n return $element.hasClass('br-current');\n };\n\n // handle click events\n var attachClickHandler = function($elements) {\n $elements.on('click.barrating', function(event) {\n var $a = $(this),\n options = getData('userOptions'),\n value,\n text;\n\n event.preventDefault();\n\n $elements.removeClass('br-active br-selected br-half');\n $a.addClass('br-selected')[nextAllorPreviousAll()]()\n .addClass('br-selected');\n\n value = $a.attr('data-rating-value');\n text = $a.attr('data-rating-text');\n\n // is current and deselectable?\n if (isDeselectable($a)) {\n $a.removeClass('br-selected br-current')[nextAllorPreviousAll()]()\n .removeClass('br-selected br-current');\n value = ''; text = '';\n } else {\n $elements.removeClass('br-current');\n $a.addClass('br-current');\n }\n\n // remember selected rating\n setData('ratingValue', value);\n setData('ratingText', text);\n setData('ratingMade', true);\n\n setSelectFieldValue(value);\n showSelectedRating(text);\n\n // onSelect callback\n options.onSelect.call(\n self,\n ratingValue(),\n ratingText(),\n event\n );\n\n return false;\n });\n };\n\n // handle mouseenter events\n var attachMouseEnterHandler = function($elements) {\n $elements.on('mouseenter.barrating', function() {\n var $a = $(this);\n\n $elements.removeClass('br-active br-selected br-half');\n $a.addClass('br-active')[nextAllorPreviousAll()]()\n .addClass('br-active');\n\n showSelectedRating($a.attr('data-rating-text'));\n });\n };\n\n // handle mouseleave events\n var attachMouseLeaveHandler = function($elements) {\n self.$widget.on('mouseleave.barrating blur.barrating', function() {\n $elements.removeClass('br-active');\n showSelectedRating();\n applyStyle();\n });\n };\n\n // somewhat primitive way to remove 300ms click delay on touch devices\n // for a more advanced solution consider setting `fastClicks` option to false\n // and using a library such as fastclick (https://github.com/ftlabs/fastclick)\n var fastClicks = function($elements) {\n $elements.on('touchstart.barrating', function(event) {\n event.preventDefault();\n event.stopPropagation();\n\n $(this).click();\n });\n };\n\n // disable clicks\n var disableClicks = function($elements) {\n $elements.on('click.barrating', function(event) {\n event.preventDefault();\n });\n };\n\n var attachHandlers = function($elements) {\n // attach click event handler\n attachClickHandler($elements);\n\n if (self.options.hoverState) {\n // attach mouseenter event handler\n attachMouseEnterHandler($elements);\n\n // attach mouseleave event handler\n attachMouseLeaveHandler($elements);\n }\n };\n\n var detachHandlers = function($elements) {\n // remove event handlers in the \".barrating\" namespace\n $elements.off('.barrating');\n };\n\n var setupHandlers = function(readonly) {\n $elements = self.$widget.find('a');\n\n if (fastClicks) {\n fastClicks($elements);\n }\n\n if (readonly) {\n detachHandlers($elements);\n disableClicks($elements);\n } else {\n attachHandlers($elements);\n }\n };\n\n this.show = function() {\n // run only once\n if (getData()) return;\n\n // wrap element\n wrapElement();\n\n // save data\n saveDataOnElement();\n\n // build & append widget to the DOM\n self.$widget = buildWidget();\n self.$widget.insertAfter(self.$elem);\n\n applyStyle();\n\n showSelectedRating();\n\n setupHandlers(self.options.readonly);\n\n // hide the select field\n self.$elem.hide();\n };\n\n this.readonly = function(state) {\n if (typeof state !== 'boolean' || getData('readOnly') == state) return;\n\n setupHandlers(state);\n setData('readOnly', state);\n self.$widget.toggleClass('br-readonly');\n };\n\n this.set = function(value) {\n var options = getData('userOptions');\n\n if (!self.$elem.find('option[value=\"' + value + '\"]').val()) return;\n\n // set data\n setData('ratingValue', value);\n setData('ratingText', self.$elem.find('option[value=\"' + value + '\"]').text());\n setData('ratingMade', true);\n\n setSelectFieldValue(ratingValue());\n showSelectedRating(ratingText());\n\n applyStyle();\n\n // onSelect callback\n if (!options.silent) {\n options.onSelect.call(\n this,\n ratingValue(),\n ratingText()\n );\n }\n };\n\n this.clear = function() {\n var options = getData('userOptions');\n\n // restore original data\n setData('ratingValue', getData('originalRatingValue'));\n setData('ratingText', getData('originalRatingText'));\n setData('ratingMade', false);\n\n resetSelectField();\n showSelectedRating(ratingText());\n\n applyStyle();\n\n // onClear callback\n options.onClear.call(\n this,\n ratingValue(),\n ratingText()\n );\n };\n\n this.destroy = function() {\n var value = ratingValue();\n var text = ratingText();\n var options = getData('userOptions');\n\n // detach handlers\n detachHandlers(self.$widget.find('a'));\n\n // remove widget\n self.$widget.remove();\n\n // remove data\n removeDataOnElement();\n\n // unwrap the element\n unwrapElement();\n\n // show the element\n self.$elem.show();\n\n // onDestroy callback\n options.onDestroy.call(\n this,\n value,\n text\n );\n };\n }\n\n BarRating.prototype.init = function (options, elem) {\n this.$elem = $(elem);\n this.options = $.extend({}, $.fn.barrating.defaults, options);\n\n return this.options;\n };\n\n return BarRating;\n })();\n\n $.fn.barrating = function (method, options) {\n return this.each(function () {\n var plugin = new BarRating();\n\n // plugin works with select fields\n if (!$(this).is('select')) {\n $.error('Sorry, this plugin only works with select fields.');\n }\n\n // method supplied\n if (plugin.hasOwnProperty(method)) {\n plugin.init(options, this);\n if (method === 'show') {\n return plugin.show(options);\n } else {\n // plugin exists?\n if (plugin.$elem.data('barrating')) {\n plugin.$widget = $(this).next('.br-widget');\n return plugin[method](options);\n }\n }\n\n // no method supplied or only options supplied\n } else if (typeof method === 'object' || !method) {\n options = method;\n plugin.init(options, this);\n return plugin.show();\n\n } else {\n $.error('Method ' + method + ' does not exist on jQuery.barrating');\n }\n });\n };\n\n $.fn.barrating.defaults = {\n theme:'',\n initialRating:null, // initial rating\n showValues:false, // display rating values on the bars?\n showSelectedRating:true, // append a div with a rating to the widget?\n deselectable:true, // allow to deselect ratings\n reverse:false, // reverse the rating?\n readonly:false, // make the rating ready-only?\n fastClicks:true, // remove 300ms click delay on touch devices?\n hoverState:true, // change state on hover?\n silent:false, // supress callbacks when controlling ratings programatically\n wrapperClass:'br-wrapper', // class applied to wrapper div\n onSelect:function (value, text, event) {\n }, // callback fired when a rating is selected\n onClear:function (value, text) {\n }, // callback fired when a rating is cleared\n onDestroy:function (value, text) {\n } // callback fired when a widget is destroyed\n };\n\n $.fn.barrating.BarRating = BarRating;\n\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["jquery.barrating.js"],"names":["factory","define","amd","module","exports","require","jQuery","$","BarRating","self","this","wrapElement","classes","options","theme","push","$elem","wrap","class","join","unwrapElement","unwrap","findOption","value","isNumeric","Math","floor","findInitialOption","initialRating","getData","key","data","setData","saveDataOnElement","$opt","val","text","userOptions","ratingValue","ratingText","originalRatingValue","originalRatingText","readOnly","readonly","ratingMade","removeDataOnElement","removeData","buildWidget","$w","find","each","html","$a","href","data-rating-value","data-rating-text","append","showSelectedRating","reverse","addClass","nextAllorPreviousAll","setSelectFieldValue","prop","change","resetSelectField","defaultSelected","parent","fraction","round","resetStyle","$widget","removeClass","applyStyle","$all","$fractional","baseValue","f","isDeselectable","$element","deselectable","attr","attachClickHandler","$elements","on","event","preventDefault","onSelect","call","attachMouseEnterHandler","attachMouseLeaveHandler","fastClicks","stopPropagation","click","disableClicks","attachHandlers","hoverState","detachHandlers","off","setupHandlers","show","insertAfter","hide","state","toggleClass","set","silent","clear","onClear","destroy","remove","onDestroy","prototype","init","elem","extend","fn","barrating","defaults","method","plugin","is","error","hasOwnProperty","next","showValues"],"mappings":"CAUC,SAAUA,GACe,kBAAXC,SAAyBA,OAAOC,IAEvCD,QAAQ,UAAWD,GACM,gBAAXG,SAAuBA,OAAOC,QAE5CD,OAAOC,QAAUJ,EAAQK,QAAQ,WAGjCL,EAAQM,SAEd,SAAUC,GAER,GAAIC,GAAY,WAEZ,QAASA,KACL,GAAIC,GAAOC,KAGPC,EAAc,WACd,GAAIC,IAAW,aAEY,MAAvBH,EAAKI,QAAQC,OACbF,EAAQG,KAAK,YAAcN,EAAKI,QAAQC,OAG5CL,EAA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AKO,MAAMmF,OAGXtF,EAAQiG,UAAUvB,KACd7E,KACAa,EACAa,IAYZ,MAPA5B,GAAUuG,UAAUC,KAAO,SAAUnG,EAASoG,GAI1C,MAHAvG,MAAKM,MAAQT,EAAE0G,GACfvG,KAAKG,QAAUN,EAAE2G,UAAW3G,EAAE4G,GAAGC,UAAUC,SAAUxG,GAE9CH,KAAKG,SAGTL,IAGXD,GAAE4G,GAAGC,UAAY,SAAUE,EAAQzG,GAC/B,MAAOH,MAAKwC,KAAK,WACb,GAAIqE,GAAS,GAAI/G,EAQjB,IALKD,EAAEG,MAAM8G,GAAG,WACZjH,EAAEkH,MAAM,qDAIRF,EAAOG,eAAeJ,GAAS,CAE/B,GADAC,EAAOP,KAAKnG,EAASH,MACN,SAAX4G,EACA,MAAOC,GAAOpB,KAAKtF,EAGnB,IAAI0G,EAAOvG,MAAMe,KAAK,aAElB,MADAwF,GAAOjD,QAAU/D,EAAEG,MAAMiH,KAAK,cACvBJ,EAAOD,GAAQzG,OAK3B,CAAA,GAAsB,gBAAXyG,KAAwBA,EAGtC,MAFAzG,GAAUyG,EACVC,EAAOP,KAAKnG,EAASH,MACd6G,EAAOpB,MAGd5F,GAAEkH,MAAM,UAAYH,EAAS,2CAKzC/G,EAAE4G,GAAGC,UAAUC,UACXvG,MAAM,GACNc,cAAc,KACdgG,YAAW,EACXnE,oBAAmB,EACnBsB,cAAa,EACbrB,SAAQ,EACRf,UAAS,EACT+C,YAAW,EACXK,YAAW,EACXU,QAAO,EACPnB,SAAS,SAAU/D,EAAOa,EAAMgD,KAEhCuB,QAAQ,SAAUpF,EAAOa,KAEzB0E,UAAU,SAAUvF,EAAOa,MAI/B7B,EAAE4G,GAAGC,UAAU5G,UAAYA","file":"jquery.barrating.min.js","sourcesContent":["/**\n * jQuery Bar Rating Plugin v1.2\n *\n * http://github.com/antennaio/jquery-bar-rating\n *\n * Copyright (c) 2012-2016 Kazik Pietruszewski\n *\n * This plugin is available under the MIT license.\n * http://www.opensource.org/licenses/mit-license.php\n */\n(function (factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD\n define(['jquery'], factory);\n } else if (typeof module === 'object' && module.exports) {\n // Node/CommonJS\n module.exports = factory(require('jquery'));\n } else {\n // browser globals\n factory(jQuery);\n }\n}(function ($) {\n\n var BarRating = (function() {\n\n function BarRating() {\n var self = this;\n\n // wrap element in a wrapper div\n var wrapElement = function() {\n var classes = ['br-wrapper'];\n\n if (self.options.theme !== '') {\n classes.push('br-theme-' + self.options.theme);\n }\n \n self.$elem.wrap($('
', {\n 'class': classes.join(' ')\n }));\n };\n\n // unwrap element\n var unwrapElement = function() {\n self.$elem.unwrap();\n };\n\n // find option by value\n var findOption = function(value) {\n if ($.isNumeric(value)) {\n value = Math.floor(value);\n }\n\n return $('option[value=\"' + value + '\"]', self.$elem);\n };\n\n // find initial option\n var findInitialOption = function() {\n var initialRating = self.options.initialRating;\n\n if (!initialRating) {\n return $('option:selected', self.$elem);\n }\n\n return findOption(initialRating);\n };\n\n // get data\n var getData = function(key) {\n var data = self.$elem.data('barrating');\n\n if (typeof key !== 'undefined') {\n return data[key];\n }\n\n return data;\n };\n\n // set data\n var setData = function(key, value) {\n if (value !== null && typeof value === 'object') {\n self.$elem.data('barrating', value);\n } else {\n self.$elem.data('barrating')[key] = value;\n }\n };\n\n // save data on element\n var saveDataOnElement = function() {\n var $opt = findInitialOption();\n\n var value = $opt.val();\n var text = $opt.data('html') ? $opt.data('html') : $opt.text();\n\n setData(null, {\n userOptions: self.options,\n\n // initial rating based on the OPTION value\n ratingValue: value,\n ratingText: text,\n\n // rating will be restored by calling clear method\n originalRatingValue: value,\n originalRatingText: text,\n\n // read-only state\n readOnly: self.options.readonly,\n\n // did the user already select a rating?\n ratingMade: false\n });\n };\n\n // remove data on element\n var removeDataOnElement = function() {\n self.$elem.removeData('barrating');\n };\n\n // return current rating text\n var ratingText = function() {\n return getData('ratingText');\n };\n\n // return current rating value\n var ratingValue = function() {\n return getData('ratingValue');\n };\n\n // build widget and return jQuery element\n var buildWidget = function() {\n var $w = $('
', { 'class': 'br-widget' });\n\n // create A elements that will replace OPTIONs\n self.$elem.find('option').each(function() {\n var val, text, html, $a;\n\n val = $(this).val();\n\n // create ratings - but only if val is defined\n if (val) {\n text = $(this).text();\n html = $(this).data('html');\n if (html) { text = html; }\n\n $a = $('', {\n 'href': '#',\n 'data-rating-value': val,\n 'data-rating-text': text,\n 'html': (self.options.showValues) ? text : ''\n });\n\n $w.append($a);\n }\n\n });\n\n // append .br-current-rating div to the widget\n if (self.options.showSelectedRating) {\n $w.append($('
', { 'text': '', 'class': 'br-current-rating' }));\n }\n\n // additional classes for the widget\n if (self.options.reverse) {\n $w.addClass('br-reverse');\n }\n\n if (self.options.readonly) {\n $w.addClass('br-readonly');\n }\n\n return $w;\n };\n\n // return a jQuery function name depending on the 'reverse' setting\n var nextAllorPreviousAll = function() {\n if (getData('userOptions').reverse) {\n return 'nextAll';\n } else {\n return 'prevAll';\n }\n };\n\n // set the value of the select field\n var setSelectFieldValue = function(value) {\n // change selected option\n findOption(value).prop('selected', true);\n\n self.$elem.change();\n };\n\n // reset select field\n var resetSelectField = function() {\n $('option', self.$elem).prop('selected', function() {\n return this.defaultSelected;\n });\n\n self.$elem.change();\n };\n\n // display the currently selected rating\n var showSelectedRating = function(text) {\n // text undefined?\n text = text ? text : ratingText();\n\n // update .br-current-rating div\n if (self.options.showSelectedRating) {\n self.$elem.parent().find('.br-current-rating').text(text);\n }\n };\n\n // return rounded fraction of a value (14.4 -> 40, 0.99 -> 90)\n var fraction = function(value) {\n return Math.round(((Math.floor(value * 10) / 10) % 1) * 100);\n };\n\n // remove all classes from elements\n var resetStyle = function() {\n self.$widget.find('a').removeClass();\n };\n\n // apply style by setting classes on elements\n var applyStyle = function() {\n var $a = self.$widget.find('a[data-rating-value=\"' + ratingValue() + '\"]');\n var initialRating = getData('userOptions').initialRating;\n var baseValue = $.isNumeric(ratingValue()) ? ratingValue() : 0;\n var f = fraction(initialRating);\n var $all, $fractional;\n\n resetStyle();\n\n // add classes\n $a.addClass('br-selected br-current')[nextAllorPreviousAll()]()\n .addClass('br-selected');\n\n if (!getData('ratingMade') && $.isNumeric(initialRating)) {\n if ((initialRating <= baseValue) || !f) {\n return;\n }\n\n $all = self.$widget.find('a');\n\n $fractional = ($a.length) ?\n $a[(getData('userOptions').reverse) ? 'prev' : 'next']() :\n $all[(getData('userOptions').reverse) ? 'last' : 'first']();\n\n $fractional.addClass('br-fractional');\n $fractional.addClass('br-fractional-' + f);\n }\n };\n\n // check if the element is deselectable?\n var isDeselectable = function($element) {\n if (!self.options.deselectable) {\n return false;\n }\n\n if (self.$elem.find('option:first').val()) {\n // empty option not found\n return false;\n }\n\n return (ratingValue() == $element.attr('data-rating-value'));\n };\n\n // handle click events\n var attachClickHandler = function($elements) {\n $elements.on('click.barrating', function(event) {\n var $a = $(this),\n options = getData('userOptions'),\n value,\n text;\n\n event.preventDefault();\n\n value = $a.attr('data-rating-value');\n text = $a.attr('data-rating-text');\n\n // is current and deselectable?\n if (isDeselectable($a)) {\n value = '';\n text = '';\n }\n\n // remember selected rating\n setData('ratingValue', value);\n setData('ratingText', text);\n setData('ratingMade', true);\n\n setSelectFieldValue(value);\n showSelectedRating(text);\n\n applyStyle();\n\n // onSelect callback\n options.onSelect.call(\n self,\n ratingValue(),\n ratingText(),\n event\n );\n\n return false;\n });\n };\n\n // handle mouseenter events\n var attachMouseEnterHandler = function($elements) {\n $elements.on('mouseenter.barrating', function() {\n var $a = $(this);\n\n resetStyle();\n\n $a.addClass('br-active')[nextAllorPreviousAll()]()\n .addClass('br-active');\n\n showSelectedRating($a.attr('data-rating-text'));\n });\n };\n\n // handle mouseleave events\n var attachMouseLeaveHandler = function($elements) {\n self.$widget.on('mouseleave.barrating blur.barrating', function() {\n showSelectedRating();\n applyStyle();\n });\n };\n\n // somewhat primitive way to remove 300ms click delay on touch devices\n // for a more advanced solution consider setting `fastClicks` option to false\n // and using a library such as fastclick (https://github.com/ftlabs/fastclick)\n var fastClicks = function($elements) {\n $elements.on('touchstart.barrating', function(event) {\n event.preventDefault();\n event.stopPropagation();\n\n $(this).click();\n });\n };\n\n // disable clicks\n var disableClicks = function($elements) {\n $elements.on('click.barrating', function(event) {\n event.preventDefault();\n });\n };\n\n var attachHandlers = function($elements) {\n // attach click event handler\n attachClickHandler($elements);\n\n if (self.options.hoverState) {\n // attach mouseenter event handler\n attachMouseEnterHandler($elements);\n\n // attach mouseleave event handler\n attachMouseLeaveHandler($elements);\n }\n };\n\n var detachHandlers = function($elements) {\n // remove event handlers in the \".barrating\" namespace\n $elements.off('.barrating');\n };\n\n var setupHandlers = function(readonly) {\n $elements = self.$widget.find('a');\n\n if (fastClicks) {\n fastClicks($elements);\n }\n\n if (readonly) {\n detachHandlers($elements);\n disableClicks($elements);\n } else {\n attachHandlers($elements);\n }\n };\n\n this.show = function() {\n // run only once\n if (getData()) return;\n\n // wrap element\n wrapElement();\n\n // save data\n saveDataOnElement();\n\n // build & append widget to the DOM\n self.$widget = buildWidget();\n self.$widget.insertAfter(self.$elem);\n\n applyStyle();\n\n showSelectedRating();\n\n setupHandlers(self.options.readonly);\n\n // hide the select field\n self.$elem.hide();\n };\n\n this.readonly = function(state) {\n if (typeof state !== 'boolean' || getData('readOnly') == state) return;\n\n setupHandlers(state);\n setData('readOnly', state);\n self.$widget.toggleClass('br-readonly');\n };\n\n this.set = function(value) {\n var options = getData('userOptions');\n\n if (!self.$elem.find('option[value=\"' + value + '\"]').val()) return;\n\n // set data\n setData('ratingValue', value);\n setData('ratingText', self.$elem.find('option[value=\"' + value + '\"]').text());\n setData('ratingMade', true);\n\n setSelectFieldValue(ratingValue());\n showSelectedRating(ratingText());\n\n applyStyle();\n\n // onSelect callback\n if (!options.silent) {\n options.onSelect.call(\n this,\n ratingValue(),\n ratingText()\n );\n }\n };\n\n this.clear = function() {\n var options = getData('userOptions');\n\n // restore original data\n setData('ratingValue', getData('originalRatingValue'));\n setData('ratingText', getData('originalRatingText'));\n setData('ratingMade', false);\n\n resetSelectField();\n showSelectedRating(ratingText());\n\n applyStyle();\n\n // onClear callback\n options.onClear.call(\n this,\n ratingValue(),\n ratingText()\n );\n };\n\n this.destroy = function() {\n var value = ratingValue();\n var text = ratingText();\n var options = getData('userOptions');\n\n // detach handlers\n detachHandlers(self.$widget.find('a'));\n\n // remove widget\n self.$widget.remove();\n\n // remove data\n removeDataOnElement();\n\n // unwrap the element\n unwrapElement();\n\n // show the element\n self.$elem.show();\n\n // onDestroy callback\n options.onDestroy.call(\n this,\n value,\n text\n );\n };\n }\n\n BarRating.prototype.init = function (options, elem) {\n this.$elem = $(elem);\n this.options = $.extend({}, $.fn.barrating.defaults, options);\n\n return this.options;\n };\n\n return BarRating;\n })();\n\n $.fn.barrating = function (method, options) {\n return this.each(function () {\n var plugin = new BarRating();\n\n // plugin works with select fields\n if (!$(this).is('select')) {\n $.error('Sorry, this plugin only works with select fields.');\n }\n\n // method supplied\n if (plugin.hasOwnProperty(method)) {\n plugin.init(options, this);\n if (method === 'show') {\n return plugin.show(options);\n } else {\n // plugin exists?\n if (plugin.$elem.data('barrating')) {\n plugin.$widget = $(this).next('.br-widget');\n return plugin[method](options);\n }\n }\n\n // no method supplied or only options supplied\n } else if (typeof method === 'object' || !method) {\n options = method;\n plugin.init(options, this);\n return plugin.show();\n\n } else {\n $.error('Method ' + method + ' does not exist on jQuery.barrating');\n }\n });\n };\n\n $.fn.barrating.defaults = {\n theme:'',\n initialRating:null, // initial rating\n showValues:false, // display rating values on the bars?\n showSelectedRating:true, // append a div with a rating to the widget?\n deselectable:true, // allow to deselect ratings\n reverse:false, // reverse the rating?\n readonly:false, // make the rating ready-only?\n fastClicks:true, // remove 300ms click delay on touch devices?\n hoverState:true, // change state on hover?\n silent:false, // supress callbacks when controlling ratings programatically\n onSelect:function (value, text, event) {\n }, // callback fired when a rating is selected\n onClear:function (value, text) {\n }, // callback fired when a rating is cleared\n onDestroy:function (value, text) {\n } // callback fired when a widget is destroyed\n };\n\n $.fn.barrating.BarRating = BarRating;\n\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/jquery.barrating.js b/jquery.barrating.js index 9909865..3aa9f97 100644 --- a/jquery.barrating.js +++ b/jquery.barrating.js @@ -1,5 +1,5 @@ /** - * jQuery Bar Rating Plugin v1.1.4 + * jQuery Bar Rating Plugin v1.2 * * http://github.com/antennaio/jquery-bar-rating * diff --git a/package.json b/package.json index e7c7d9f..51e330b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jquery-bar-rating", "description": "Minimal, light-weight jQuery ratings.", - "version": "1.1.4", + "version": "1.2", "main": "jquery.barrating.js", "keywords": [ "jquery",