diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dca71c..d1cfb2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -1.2 -___ +1.2.0 +_____ - deprecated `wrapperClass` option removed diff --git a/bower.json b/bower.json index cc3bc9e..dea42a8 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-bar-rating", - "version": "1.2", + "version": "1.2.0", "homepage": "http://antenna.io/demo/jquery-bar-rating/examples/", "repository": { "type": "git", diff --git a/dist/jquery.barrating.min.js.map b/dist/jquery.barrating.min.js.map index c6cc251..f3510f4 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","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,OAAO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AEzB0E,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 +{"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,MAA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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 3aa9f97..c14c77e 100644 --- a/jquery.barrating.js +++ b/jquery.barrating.js @@ -1,5 +1,5 @@ /** - * jQuery Bar Rating Plugin v1.2 + * jQuery Bar Rating Plugin v1.2.0 * * http://github.com/antennaio/jquery-bar-rating * diff --git a/package.json b/package.json index 51e330b..7a28aa0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jquery-bar-rating", "description": "Minimal, light-weight jQuery ratings.", - "version": "1.2", + "version": "1.2.0", "main": "jquery.barrating.js", "keywords": [ "jquery",