diff --git a/CHANGE.md b/CHANGE.md index 6a05bcb..fcf7d26 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -1,6 +1,13 @@ Change Log: `bootstrap-star-rating` =================================== +## Version 4.0.5 + +**Date:** 04-Oct-2018 + +- (enh #189): Add Bengali Translations. +- (enh #188): Allow `showCaption` when `displayOnly` is `true`. + ## Version 4.0.4 **Date:** 15-Sep-2018 diff --git a/bower.json b/bower.json index 06eb83f..caac16c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-star-rating", - "version": "4.0.4", + "version": "4.0.5", "homepage": "https://github.com/kartik-v/bootstrap-star-rating", "authors": [ "Kartik Visweswaran " diff --git a/css/star-rating.css b/css/star-rating.css index 4e6f13e..181a21c 100644 --- a/css/star-rating.css +++ b/css/star-rating.css @@ -1,5 +1,5 @@ /*! - * bootstrap-star-rating v4.0.4 + * bootstrap-star-rating v4.0.5 * http://plugins.krajee.com/star-rating * * Author: Kartik Visweswaran diff --git a/css/star-rating.min.css b/css/star-rating.min.css index fbdcee8..8a4bed8 100644 --- a/css/star-rating.min.css +++ b/css/star-rating.min.css @@ -1,5 +1,5 @@ /*! - * bootstrap-star-rating v4.0.4 + * bootstrap-star-rating v4.0.5 * http://plugins.krajee.com/star-rating * * Author: Kartik Visweswaran diff --git a/js/star-rating.js b/js/star-rating.js index 018d254..a7a1a69 100644 --- a/js/star-rating.js +++ b/js/star-rating.js @@ -1,5 +1,5 @@ /*! - * bootstrap-star-rating v4.0.4 + * bootstrap-star-rating v4.0.5 * http://plugins.krajee.com/star-rating * * Author: Kartik Visweswaran @@ -256,7 +256,9 @@ if (self.displayOnly) { self.inactive = true; self.showClear = false; - self.showCaption = false; + self.hoverEnabled = false; + self.hoverChangeCaption = false; + self.hoverChangeStars = false; } self._generateRating(); self._initEvents(); diff --git a/js/star-rating.min.js b/js/star-rating.min.js index 0a49f54..241e246 100644 --- a/js/star-rating.min.js +++ b/js/star-rating.min.js @@ -1,5 +1,5 @@ /*! - * bootstrap-star-rating v4.0.4 + * bootstrap-star-rating v4.0.5 * http://plugins.krajee.com/star-rating * * Author: Kartik Visweswaran @@ -8,4 +8,4 @@ * Licensed under the BSD 3-Clause * https://github.com/kartik-v/bootstrap-star-rating/blob/master/LICENSE.md */ -!function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof module&&module.exports?module.exports=t(require("jquery")):t(window.jQuery)}(function(t){"use strict";var e,i;t.fn.ratingLocales={},t.fn.ratingThemes={},e={NAMESPACE:".rating",DEFAULT_MIN:0,DEFAULT_MAX:5,DEFAULT_STEP:.5,isEmpty:function(e,i){return null==e||0===e.length||i&&""===t.trim(e)},getCss:function(t,e){return t?" "+e:""},addCss:function(t,e){t.removeClass(e).addClass(e)},getDecimalPlaces:function(t){var e=(""+t).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return e?Math.max(0,(e[1]?e[1].length:0)-(e[2]?+e[2]:0)):0},applyPrecision:function(t,e){return parseFloat(t.toFixed(e))},handler:function(t,i,a,n,s){var r=s?i:i.split(" ").join(e.NAMESPACE+" ")+e.NAMESPACE;n||t.off(r),t.on(r,a)}},(i=function(e,i){this.$element=t(e),this._init(i)}).prototype={constructor:i,_parseAttr:function(t,i){var a,n,s,r,l=this.$element,o=l.attr("type");if("range"===o||"number"===o){switch(n=i[t]||l.data(t)||l.attr(t),t){case"min":s=e.DEFAULT_MIN;break;case"max":s=e.DEFAULT_MAX;break;default:s=e.DEFAULT_STEP}a=e.isEmpty(n)?s:n,r=parseFloat(a)}else r=parseFloat(i[t]);return isNaN(r)?s:r},_parseValue:function(t){var e=parseFloat(t);return isNaN(e)&&(e=this.clearValue),!this.zeroAsNull||0!==e&&"0"!==e?e:null},_setDefault:function(t,i){e.isEmpty(this[t])&&(this[t]=i)},_initSlider:function(t){var i=this.$element.val();this.initialValue=e.isEmpty(i)?0:i,this._setDefault("min",this._parseAttr("min",t)),this._setDefault("max",this._parseAttr("max",t)),this._setDefault("step",this._parseAttr("step",t)),(isNaN(this.min)||e.isEmpty(this.min))&&(this.min=e.DEFAULT_MIN),(isNaN(this.max)||e.isEmpty(this.max))&&(this.max=e.DEFAULT_MAX),(isNaN(this.step)||e.isEmpty(this.step)||0===this.step)&&(this.step=e.DEFAULT_STEP),this.diff=this.max-this.min},_initHighlight:function(t){var e,i=this._getCaption();t||(t=this.$element.val()),e=this.getWidthFromValue(t)+"%",this.$filledStars.width(e),this.cache={caption:i,width:e,val:t}},_getContainerCss:function(){return"rating-container"+e.getCss(this.theme,"theme-"+this.theme)+e.getCss(this.rtl,"rating-rtl")+e.getCss(this.size,"rating-"+this.size)+e.getCss(this.animate,"rating-animate")+e.getCss(this.disabled||this.readonly,"rating-disabled")+e.getCss(this.containerClass,this.containerClass)+(this.displayOnly?" is-display-only":"")},_checkDisabled:function(){var t=this.$element,e=this.options;this.disabled=void 0===e.disabled?t.attr("disabled")||!1:e.disabled,this.readonly=void 0===e.readonly?t.attr("readonly")||!1:e.readonly,this.inactive=this.disabled||this.readonly,t.attr({disabled:this.disabled,readonly:this.readonly})},_addContent:function(t,e){var i=this.$container,a="clear"===t;return this.rtl?a?i.append(e):i.prepend(e):a?i.prepend(e):i.append(e)},_generateRating:function(){var i,a,n,s=this.$element;a=this.$container=t(document.createElement("div")).insertBefore(s),e.addCss(a,this._getContainerCss()),this.$rating=i=t(document.createElement("div")).attr("class","rating-stars").appendTo(a).append(this._getStars("empty")).append(this._getStars("filled")),this.$emptyStars=i.find(".empty-stars"),this.$filledStars=i.find(".filled-stars"),this._renderCaption(),this._renderClear(),this._initHighlight(),this._initCaptionTitle(),a.append(s),this.rtl&&(n=Math.max(this.$emptyStars.outerWidth(),this.$filledStars.outerWidth()),this.$emptyStars.width(n)),s.appendTo(i)},_getCaption:function(){return this.$caption&&this.$caption.length?this.$caption.html():this.defaultCaption},_setCaption:function(t){this.$caption&&this.$caption.length&&this.$caption.html(t)},_renderCaption:function(){var i,a=this.$element.val(),n=this.captionElement?t(this.captionElement):"";if(this.showCaption){if(i=this.fetchCaption(a),n&&n.length)return e.addCss(n,"caption"),n.html(i),void(this.$caption=n);this._addContent("caption",'
'+i+"
"),this.$caption=this.$container.find(".caption")}},_renderClear:function(){var i,a=this.clearElement?t(this.clearElement):"";if(this.showClear){if(i=this._getClearClass(),a.length)return e.addCss(a,i),a.attr({title:this.clearButtonTitle}).html(this.clearButton),void(this.$clear=a);this._addContent("clear",'
'+this.clearButton+"
"),this.$clear=this.$container.find("."+this.clearButtonBaseClass)}},_getClearClass:function(){return this.clearButtonBaseClass+" "+(this.inactive?"":this.clearButtonActiveClass)},_toggleHover:function(t){var e,i,a;t&&(this.hoverChangeStars&&(e=this.getWidthFromValue(this.clearValue),i=t.val<=this.clearValue?e+"%":t.width,this.$filledStars.css("width",i)),this.hoverChangeCaption&&(a=t.val<=this.clearValue?this.fetchCaption(this.clearValue):t.caption)&&this._setCaption(a+""))},_init:function(e){var i,a=this,n=a.$element.addClass("rating-input");return a.options=e,t.each(e,function(t,e){a[t]=e}),(a.rtl||"rtl"===n.attr("dir"))&&(a.rtl=!0,n.attr("dir","rtl")),a.starClicked=!1,a.clearClicked=!1,a._initSlider(e),a._checkDisabled(),a.displayOnly&&(a.inactive=!0,a.showClear=!1,a.showCaption=!1),a._generateRating(),a._initEvents(),a._listen(),i=a._parseValue(n.val()),n.val(i),n.removeClass("rating-loading")},_initCaptionTitle:function(){var e;this.showCaptionAsTitle&&(e=this.fetchCaption(this.$element.val()),this.$rating.attr("title",t(e).text()))},_trigChange:function(t){this._initCaptionTitle(),this.$element.trigger("change").trigger("rating:change",t)},_initEvents:function(){var t=this;t.events={_getTouchPosition:function(i){return(e.isEmpty(i.pageX)?i.originalEvent.touches[0].pageX:i.pageX)-t.$rating.offset().left},_listenClick:function(t,e){if(t.stopPropagation(),t.preventDefault(),!0===t.handled)return!1;e(t),t.handled=!0},_noMouseAction:function(e){return!t.hoverEnabled||t.inactive||e&&e.isDefaultPrevented()},initTouch:function(i){var a,n,s,r,l,o,h,c,u=t.clearValue||0;("ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch)&&!t.inactive&&(a=i.originalEvent,n=e.isEmpty(a.touches)?a.changedTouches:a.touches,s=t.events._getTouchPosition(n[0]),"touchend"===i.type?(t._setStars(s),c=[t.$element.val(),t._getCaption()],t._trigChange(c),t.starClicked=!0):(l=(r=t.calculate(s)).val<=u?t.fetchCaption(u):r.caption,o=t.getWidthFromValue(u),h=r.val<=u?o+"%":r.width,t._setCaption(l),t.$filledStars.css("width",h)))},starClick:function(e){var i,a;t.events._listenClick(e,function(e){if(t.inactive)return!1;i=t.events._getTouchPosition(e),t._setStars(i),a=[t.$element.val(),t._getCaption()],t._trigChange(a),t.starClicked=!0})},clearClick:function(e){t.events._listenClick(e,function(){t.inactive||(t.clear(),t.clearClicked=!0)})},starMouseMove:function(e){var i,a;t.events._noMouseAction(e)||(t.starClicked=!1,i=t.events._getTouchPosition(e),a=t.calculate(i),t._toggleHover(a),t.$element.trigger("rating:hover",[a.val,a.caption,"stars"]))},starMouseLeave:function(e){var i;t.events._noMouseAction(e)||t.starClicked||(i=t.cache,t._toggleHover(i),t.$element.trigger("rating:hoverleave",["stars"]))},clearMouseMove:function(e){var i,a,n;!t.events._noMouseAction(e)&&t.hoverOnClear&&(t.clearClicked=!1,i=''+t.clearCaption+"",a=t.clearValue,n={caption:i,width:t.getWidthFromValue(a)||0,val:a},t._toggleHover(n),t.$element.trigger("rating:hover",[a,i,"clear"]))},clearMouseLeave:function(e){var i;t.events._noMouseAction(e)||t.clearClicked||!t.hoverOnClear||(i=t.cache,t._toggleHover(i),t.$element.trigger("rating:hoverleave",["clear"]))},resetForm:function(e){e&&e.isDefaultPrevented()||t.inactive||t.reset()}}},_listen:function(){var i=this.$element,a=i.closest("form"),n=this.$rating,s=this.$clear,r=this.events;return e.handler(n,"touchstart touchmove touchend",t.proxy(r.initTouch,this)),e.handler(n,"click touchstart",t.proxy(r.starClick,this)),e.handler(n,"mousemove",t.proxy(r.starMouseMove,this)),e.handler(n,"mouseleave",t.proxy(r.starMouseLeave,this)),this.showClear&&s.length&&(e.handler(s,"click touchstart",t.proxy(r.clearClick,this)),e.handler(s,"mousemove",t.proxy(r.clearMouseMove,this)),e.handler(s,"mouseleave",t.proxy(r.clearMouseLeave,this))),a.length&&e.handler(a,"reset",t.proxy(r.resetForm,this),!0),i},_getStars:function(t){var e,i='';for(e=1;e<=this.stars;e++)i+=''+this[t+"Star"]+"";return i+""},_setStars:function(t){var e=arguments.length?this.calculate(t):this.calculate(),i=this.$element,a=this._parseValue(e.val);return i.val(a),this.$filledStars.css("width",e.width),this._setCaption(e.caption),this.cache=e,i},showStars:function(t){var e=this._parseValue(t);return this.$element.val(e),this._initCaptionTitle(),this._setStars()},calculate:function(t){var i=e.isEmpty(this.$element.val())?0:this.$element.val(),a=arguments.length?this.getValueFromPosition(t):i,n=this.fetchCaption(a),s=this.getWidthFromValue(a);return{caption:n,width:s+="%",val:a}},getValueFromPosition:function(t){var i,a,n=e.getDecimalPlaces(this.step),s=this.$rating.width();return a=this.diff*t/(s*this.step),a=this.rtl?Math.floor(a):Math.ceil(a),i=e.applyPrecision(parseFloat(this.min+a*this.step),n),i=Math.max(Math.min(i,this.max),this.min),this.rtl?this.max-i:i},getWidthFromValue:function(t){var e,i,a=this.min,n=this.max,s=this.$emptyStars;return!t||t<=a||a===n?0:(e=(i=s.outerWidth())?s.width()/i:1,t>=n?100:(t-a)*e*100/(n-a))},fetchCaption:function(t){var i,a,n,s=parseFloat(t)||this.clearValue,r=this.starCaptions,l=this.starCaptionClasses;return s&&s!==this.clearValue&&(s=e.applyPrecision(s,e.getDecimalPlaces(this.step))),n="function"==typeof l?l(s):l[s],a="function"==typeof r?r(s):r[s],i=e.isEmpty(a)?this.defaultCaption.replace(/\{rating}/g,s):a,''+(s===this.clearValue?this.clearCaption:i)+""},destroy:function(){var i=this.$element;return e.isEmpty(this.$container)||this.$container.before(i).remove(),t.removeData(i.get(0)),i.off("rating").removeClass("rating rating-input")},create:function(t){var e=t||this.options||{};return this.destroy().rating(e)},clear:function(){var t=''+this.clearCaption+"";return this.inactive||this._setCaption(t),this.showStars(this.clearValue).trigger("change").trigger("rating:clear")},reset:function(){return this.showStars(this.initialValue).trigger("rating:reset")},update:function(t){return arguments.length?this.showStars(t):this.$element},refresh:function(e){var i=this.$element;return e?this.destroy().rating(t.extend(!0,this.options,e)).trigger("rating:refresh"):i}},t.fn.rating=function(a){var n=Array.apply(null,arguments),s=[];switch(n.shift(),this.each(function(){var r,l=t(this),o=l.data("rating"),h="object"==typeof a&&a,c=h.theme||l.data("theme"),u=h.language||l.data("language")||"en",d={},p={};o||(c&&(d=t.fn.ratingThemes[c]||{}),"en"===u||e.isEmpty(t.fn.ratingLocales[u])||(p=t.fn.ratingLocales[u]),r=t.extend(!0,{},t.fn.rating.defaults,d,t.fn.ratingLocales.en,p,h,l.data()),o=new i(this,r),l.data("rating",o)),"string"==typeof a&&s.push(o[a].apply(o,n))}),s.length){case 0:return this;case 1:return void 0===s[0]?this:s[0];default:return s}},t.fn.rating.defaults={theme:"",language:"en",stars:5,filledStar:'',emptyStar:'',containerClass:"",size:"md",animate:!0,displayOnly:!1,rtl:!1,showClear:!0,showCaption:!0,starCaptionClasses:{.5:"label label-danger badge-danger",1:"label label-danger badge-danger",1.5:"label label-warning badge-warning",2:"label label-warning badge-warning",2.5:"label label-info badge-info",3:"label label-info badge-info",3.5:"label label-primary badge-primary",4:"label label-primary badge-primary",4.5:"label label-success badge-success",5:"label label-success badge-success"},clearButton:'',clearButtonBaseClass:"clear-rating",clearButtonActiveClass:"clear-rating-active",clearCaptionClass:"label label-default badge-secondary",clearValue:null,captionElement:null,clearElement:null,showCaptionAsTitle:!0,hoverEnabled:!0,hoverChangeCaption:!0,hoverChangeStars:!0,hoverOnClear:!0,zeroAsNull:!0},t.fn.ratingLocales.en={defaultCaption:"{rating} Stars",starCaptions:{.5:"Half Star",1:"One Star",1.5:"One & Half Star",2:"Two Stars",2.5:"Two & Half Stars",3:"Three Stars",3.5:"Three & Half Stars",4:"Four Stars",4.5:"Four & Half Stars",5:"Five Stars"},clearButtonTitle:"Clear",clearCaption:"Not Rated"},t.fn.rating.Constructor=i,t(document).ready(function(){var e=t("input.rating");e.length&&e.removeClass("rating-loading").addClass("rating-loading").rating()})}); \ No newline at end of file +!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=e(require("jquery")):e(window.jQuery)}(function(e){"use strict";e.fn.ratingLocales={},e.fn.ratingThemes={};var t,a;t={NAMESPACE:".rating",DEFAULT_MIN:0,DEFAULT_MAX:5,DEFAULT_STEP:.5,isEmpty:function(t,a){return null===t||void 0===t||0===t.length||a&&""===e.trim(t)},getCss:function(e,t){return e?" "+t:""},addCss:function(e,t){e.removeClass(t).addClass(t)},getDecimalPlaces:function(e){var t=(""+e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);return t?Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0)):0},applyPrecision:function(e,t){return parseFloat(e.toFixed(t))},handler:function(e,a,n,i,r){var l=r?a:a.split(" ").join(t.NAMESPACE+" ")+t.NAMESPACE;i||e.off(l),e.on(l,n)}},a=function(t,a){var n=this;n.$element=e(t),n._init(a)},a.prototype={constructor:a,_parseAttr:function(e,a){var n,i,r,l,s=this,o=s.$element,c=o.attr("type");if("range"===c||"number"===c){switch(i=a[e]||o.data(e)||o.attr(e),e){case"min":r=t.DEFAULT_MIN;break;case"max":r=t.DEFAULT_MAX;break;default:r=t.DEFAULT_STEP}n=t.isEmpty(i)?r:i,l=parseFloat(n)}else l=parseFloat(a[e]);return isNaN(l)?r:l},_parseValue:function(e){var t=this,a=parseFloat(e);return isNaN(a)&&(a=t.clearValue),!t.zeroAsNull||0!==a&&"0"!==a?a:null},_setDefault:function(e,a){var n=this;t.isEmpty(n[e])&&(n[e]=a)},_initSlider:function(e){var a=this,n=a.$element.val();a.initialValue=t.isEmpty(n)?0:n,a._setDefault("min",a._parseAttr("min",e)),a._setDefault("max",a._parseAttr("max",e)),a._setDefault("step",a._parseAttr("step",e)),(isNaN(a.min)||t.isEmpty(a.min))&&(a.min=t.DEFAULT_MIN),(isNaN(a.max)||t.isEmpty(a.max))&&(a.max=t.DEFAULT_MAX),(isNaN(a.step)||t.isEmpty(a.step)||0===a.step)&&(a.step=t.DEFAULT_STEP),a.diff=a.max-a.min},_initHighlight:function(e){var t,a=this,n=a._getCaption();e||(e=a.$element.val()),t=a.getWidthFromValue(e)+"%",a.$filledStars.width(t),a.cache={caption:n,width:t,val:e}},_getContainerCss:function(){var e=this;return"rating-container"+t.getCss(e.theme,"theme-"+e.theme)+t.getCss(e.rtl,"rating-rtl")+t.getCss(e.size,"rating-"+e.size)+t.getCss(e.animate,"rating-animate")+t.getCss(e.disabled||e.readonly,"rating-disabled")+t.getCss(e.containerClass,e.containerClass)+(e.displayOnly?" is-display-only":"")},_checkDisabled:function(){var e=this,t=e.$element,a=e.options;e.disabled=void 0===a.disabled?t.attr("disabled")||!1:a.disabled,e.readonly=void 0===a.readonly?t.attr("readonly")||!1:a.readonly,e.inactive=e.disabled||e.readonly,t.attr({disabled:e.disabled,readonly:e.readonly})},_addContent:function(e,t){var a=this,n=a.$container,i="clear"===e;return a.rtl?i?n.append(t):n.prepend(t):i?n.prepend(t):n.append(t)},_generateRating:function(){var a,n,i,r=this,l=r.$element;n=r.$container=e(document.createElement("div")).insertBefore(l),t.addCss(n,r._getContainerCss()),r.$rating=a=e(document.createElement("div")).attr("class","rating-stars").appendTo(n).append(r._getStars("empty")).append(r._getStars("filled")),r.$emptyStars=a.find(".empty-stars"),r.$filledStars=a.find(".filled-stars"),r._renderCaption(),r._renderClear(),r._initHighlight(),r._initCaptionTitle(),n.append(l),r.rtl&&(i=Math.max(r.$emptyStars.outerWidth(),r.$filledStars.outerWidth()),r.$emptyStars.width(i)),l.appendTo(a)},_getCaption:function(){var e=this;return e.$caption&&e.$caption.length?e.$caption.html():e.defaultCaption},_setCaption:function(e){var t=this;t.$caption&&t.$caption.length&&t.$caption.html(e)},_renderCaption:function(){var a,n=this,i=n.$element.val(),r=n.captionElement?e(n.captionElement):"";if(n.showCaption){if(a=n.fetchCaption(i),r&&r.length)return t.addCss(r,"caption"),r.html(a),void(n.$caption=r);n._addContent("caption",'
'+a+"
"),n.$caption=n.$container.find(".caption")}},_renderClear:function(){var a,n=this,i=n.clearElement?e(n.clearElement):"";if(n.showClear){if(a=n._getClearClass(),i.length)return t.addCss(i,a),i.attr({title:n.clearButtonTitle}).html(n.clearButton),void(n.$clear=i);n._addContent("clear",'
'+n.clearButton+"
"),n.$clear=n.$container.find("."+n.clearButtonBaseClass)}},_getClearClass:function(){var e=this;return e.clearButtonBaseClass+" "+(e.inactive?"":e.clearButtonActiveClass)},_toggleHover:function(e){var t,a,n,i=this;e&&(i.hoverChangeStars&&(t=i.getWidthFromValue(i.clearValue),a=e.val<=i.clearValue?t+"%":e.width,i.$filledStars.css("width",a)),i.hoverChangeCaption&&(n=e.val<=i.clearValue?i.fetchCaption(i.clearValue):e.caption,n&&i._setCaption(n+"")))},_init:function(t){var a,n=this,i=n.$element.addClass("rating-input");return n.options=t,e.each(t,function(e,t){n[e]=t}),(n.rtl||"rtl"===i.attr("dir"))&&(n.rtl=!0,i.attr("dir","rtl")),n.starClicked=!1,n.clearClicked=!1,n._initSlider(t),n._checkDisabled(),n.displayOnly&&(n.inactive=!0,n.showClear=!1,n.hoverEnabled=!1,n.hoverChangeCaption=!1,n.hoverChangeStars=!1),n._generateRating(),n._initEvents(),n._listen(),a=n._parseValue(i.val()),i.val(a),i.removeClass("rating-loading")},_initCaptionTitle:function(){var t,a=this;a.showCaptionAsTitle&&(t=a.fetchCaption(a.$element.val()),a.$rating.attr("title",e(t).text()))},_trigChange:function(e){var t=this;t._initCaptionTitle(),t.$element.trigger("change").trigger("rating:change",e)},_initEvents:function(){var e=this;e.events={_getTouchPosition:function(a){var n=t.isEmpty(a.pageX)?a.originalEvent.touches[0].pageX:a.pageX;return n-e.$rating.offset().left},_listenClick:function(e,t){return e.stopPropagation(),e.preventDefault(),e.handled===!0?!1:(t(e),void(e.handled=!0))},_noMouseAction:function(t){return!e.hoverEnabled||e.inactive||t&&t.isDefaultPrevented()},initTouch:function(a){var n,i,r,l,s,o,c,u,d=e.clearValue||0,p="ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch;p&&!e.inactive&&(n=a.originalEvent,i=t.isEmpty(n.touches)?n.changedTouches:n.touches,r=e.events._getTouchPosition(i[0]),"touchend"===a.type?(e._setStars(r),u=[e.$element.val(),e._getCaption()],e._trigChange(u),e.starClicked=!0):(l=e.calculate(r),s=l.val<=d?e.fetchCaption(d):l.caption,o=e.getWidthFromValue(d),c=l.val<=d?o+"%":l.width,e._setCaption(s),e.$filledStars.css("width",c)))},starClick:function(t){var a,n;e.events._listenClick(t,function(t){return e.inactive?!1:(a=e.events._getTouchPosition(t),e._setStars(a),n=[e.$element.val(),e._getCaption()],e._trigChange(n),void(e.starClicked=!0))})},clearClick:function(t){e.events._listenClick(t,function(){e.inactive||(e.clear(),e.clearClicked=!0)})},starMouseMove:function(t){var a,n;e.events._noMouseAction(t)||(e.starClicked=!1,a=e.events._getTouchPosition(t),n=e.calculate(a),e._toggleHover(n),e.$element.trigger("rating:hover",[n.val,n.caption,"stars"]))},starMouseLeave:function(t){var a;e.events._noMouseAction(t)||e.starClicked||(a=e.cache,e._toggleHover(a),e.$element.trigger("rating:hoverleave",["stars"]))},clearMouseMove:function(t){var a,n,i,r;!e.events._noMouseAction(t)&&e.hoverOnClear&&(e.clearClicked=!1,a=''+e.clearCaption+"",n=e.clearValue,i=e.getWidthFromValue(n)||0,r={caption:a,width:i,val:n},e._toggleHover(r),e.$element.trigger("rating:hover",[n,a,"clear"]))},clearMouseLeave:function(t){var a;e.events._noMouseAction(t)||e.clearClicked||!e.hoverOnClear||(a=e.cache,e._toggleHover(a),e.$element.trigger("rating:hoverleave",["clear"]))},resetForm:function(t){t&&t.isDefaultPrevented()||e.inactive||e.reset()}}},_listen:function(){var a=this,n=a.$element,i=n.closest("form"),r=a.$rating,l=a.$clear,s=a.events;return t.handler(r,"touchstart touchmove touchend",e.proxy(s.initTouch,a)),t.handler(r,"click touchstart",e.proxy(s.starClick,a)),t.handler(r,"mousemove",e.proxy(s.starMouseMove,a)),t.handler(r,"mouseleave",e.proxy(s.starMouseLeave,a)),a.showClear&&l.length&&(t.handler(l,"click touchstart",e.proxy(s.clearClick,a)),t.handler(l,"mousemove",e.proxy(s.clearMouseMove,a)),t.handler(l,"mouseleave",e.proxy(s.clearMouseLeave,a))),i.length&&t.handler(i,"reset",e.proxy(s.resetForm,a),!0),n},_getStars:function(e){var t,a=this,n='';for(t=1;t<=a.stars;t++)n+=''+a[e+"Star"]+"";return n+""},_setStars:function(e){var t=this,a=arguments.length?t.calculate(e):t.calculate(),n=t.$element,i=t._parseValue(a.val);return n.val(i),t.$filledStars.css("width",a.width),t._setCaption(a.caption),t.cache=a,n},showStars:function(e){var t=this,a=t._parseValue(e);return t.$element.val(a),t._initCaptionTitle(),t._setStars()},calculate:function(e){var a=this,n=t.isEmpty(a.$element.val())?0:a.$element.val(),i=arguments.length?a.getValueFromPosition(e):n,r=a.fetchCaption(i),l=a.getWidthFromValue(i);return l+="%",{caption:r,width:l,val:i}},getValueFromPosition:function(e){var a,n,i=this,r=t.getDecimalPlaces(i.step),l=i.$rating.width();return n=i.diff*e/(l*i.step),n=i.rtl?Math.floor(n):Math.ceil(n),a=t.applyPrecision(parseFloat(i.min+n*i.step),r),a=Math.max(Math.min(a,i.max),i.min),i.rtl?i.max-a:a},getWidthFromValue:function(e){var t,a,n=this,i=n.min,r=n.max,l=n.$emptyStars;return!e||i>=e||i===r?0:(a=l.outerWidth(),t=a?l.width()/a:1,e>=r?100:(e-i)*t*100/(r-i))},fetchCaption:function(e){var a,n,i,r,l,s=this,o=parseFloat(e)||s.clearValue,c=s.starCaptions,u=s.starCaptionClasses;return o&&o!==s.clearValue&&(o=t.applyPrecision(o,t.getDecimalPlaces(s.step))),r="function"==typeof u?u(o):u[o],i="function"==typeof c?c(o):c[o],n=t.isEmpty(i)?s.defaultCaption.replace(/\{rating}/g,o):i,a=t.isEmpty(r)?s.clearCaptionClass:r,l=o===s.clearValue?s.clearCaption:n,''+l+""},destroy:function(){var a=this,n=a.$element;return t.isEmpty(a.$container)||a.$container.before(n).remove(),e.removeData(n.get(0)),n.off("rating").removeClass("rating rating-input")},create:function(e){var t=this,a=e||t.options||{};return t.destroy().rating(a)},clear:function(){var e=this,t=''+e.clearCaption+"";return e.inactive||e._setCaption(t),e.showStars(e.clearValue).trigger("change").trigger("rating:clear")},reset:function(){var e=this;return e.showStars(e.initialValue).trigger("rating:reset")},update:function(e){var t=this;return arguments.length?t.showStars(e):t.$element},refresh:function(t){var a=this,n=a.$element;return t?a.destroy().rating(e.extend(!0,a.options,t)).trigger("rating:refresh"):n}},e.fn.rating=function(n){var i=Array.apply(null,arguments),r=[];switch(i.shift(),this.each(function(){var l,s=e(this),o=s.data("rating"),c="object"==typeof n&&n,u=c.theme||s.data("theme"),d=c.language||s.data("language")||"en",p={},h={};o||(u&&(p=e.fn.ratingThemes[u]||{}),"en"===d||t.isEmpty(e.fn.ratingLocales[d])||(h=e.fn.ratingLocales[d]),l=e.extend(!0,{},e.fn.rating.defaults,p,e.fn.ratingLocales.en,h,c,s.data()),o=new a(this,l),s.data("rating",o)),"string"==typeof n&&r.push(o[n].apply(o,i))}),r.length){case 0:return this;case 1:return void 0===r[0]?this:r[0];default:return r}},e.fn.rating.defaults={theme:"",language:"en",stars:5,filledStar:'',emptyStar:'',containerClass:"",size:"md",animate:!0,displayOnly:!1,rtl:!1,showClear:!0,showCaption:!0,starCaptionClasses:{.5:"label label-danger badge-danger",1:"label label-danger badge-danger",1.5:"label label-warning badge-warning",2:"label label-warning badge-warning",2.5:"label label-info badge-info",3:"label label-info badge-info",3.5:"label label-primary badge-primary",4:"label label-primary badge-primary",4.5:"label label-success badge-success",5:"label label-success badge-success"},clearButton:'',clearButtonBaseClass:"clear-rating",clearButtonActiveClass:"clear-rating-active",clearCaptionClass:"label label-default badge-secondary",clearValue:null,captionElement:null,clearElement:null,showCaptionAsTitle:!0,hoverEnabled:!0,hoverChangeCaption:!0,hoverChangeStars:!0,hoverOnClear:!0,zeroAsNull:!0},e.fn.ratingLocales.en={defaultCaption:"{rating} Stars",starCaptions:{.5:"Half Star",1:"One Star",1.5:"One & Half Star",2:"Two Stars",2.5:"Two & Half Stars",3:"Three Stars",3.5:"Three & Half Stars",4:"Four Stars",4.5:"Four & Half Stars",5:"Five Stars"},clearButtonTitle:"Clear",clearCaption:"Not Rated"},e.fn.rating.Constructor=a,e(document).ready(function(){var t=e("input.rating");t.length&&t.removeClass("rating-loading").addClass("rating-loading").rating()})}); \ No newline at end of file diff --git a/package.json b/package.json index 1a6eb91..0429c46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-star-rating", - "version": "4.0.4", + "version": "4.0.5", "homepage": "https://github.com/kartik-v/bootstrap-star-rating", "author": "Kartik Visweswaran ", "description": "A simple yet powerful JQuery star rating plugin for Bootstrap.",