From aa22130a8183a18d8c91a0ad2c0d159beebe7013 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Fri, 21 May 2021 01:40:39 +0530 Subject: [PATCH] Updates to release v4.0.8 fixes #209 --- CHANGE.md | 6 ++++++ README.md | 12 +++++------ bower.json | 2 +- css/star-rating.css | 45 ++++++++++++++++++++++++++++++++++++++++- css/star-rating.min.css | 4 ++-- examples/index.html | 21 ++++++++++--------- js/star-rating.js | 26 ++++++++++++------------ js/star-rating.min.js | 4 ++-- package.json | 2 +- 9 files changed, 87 insertions(+), 35 deletions(-) diff --git a/CHANGE.md b/CHANGE.md index 083c9f5..584fb40 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -1,6 +1,12 @@ Change Log: `bootstrap-star-rating` =================================== +## Version 4.0.8 + +**Date:** 21-May-2021 + +- (enh #209): Enhancements to support BS 5.x (and 4.x/3.x). + ## Version 4.0.7 **Date:** 20-May-2021 diff --git a/README.md b/README.md index 5dd60cb..4e5a383 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- + Krajee Logo
@@ -115,20 +115,20 @@ Step 1: Load the following assets in your header. ```html - + - + - + - + - + ``` If you noticed, you need to load the `jquery.min.js` and `bootstrap.min.css` in addition to the `star-rating.min.css` and `star-rating.min.js` for diff --git a/bower.json b/bower.json index 145d30e..ca3ef91 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-star-rating", - "version": "4.0.7", + "version": "4.0.8", "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 18b25cc..ba58b9d 100644 --- a/css/star-rating.css +++ b/css/star-rating.css @@ -1,5 +1,5 @@ /*! - * bootstrap-star-rating v4.0.7 + * bootstrap-star-rating v4.0.8 * http://plugins.krajee.com/star-rating * * Author: Kartik Visweswaran @@ -203,3 +203,46 @@ .rating-xs .caption { font-size: 12px; } + +/** + * Caption + */ +.caption-badge { + font-family: Arial, Helvetica, sans-serif; + display: inline-block; + padding: .35em .65em; + font-size: .75em; + font-weight: 700; + line-height: 1; + color: #fff; + text-align: center; + white-space: nowrap; + vertical-align: baseline; + border-radius: .25rem; +} + +.caption-secondary { + background-color: #6c757d !important; +} + +.caption-danger { + background-color: #dc3545 !important; +} + +.caption-warning { + background-color: #ffc107 !important; + color: #212529 !important; +} + +.caption-info { + background-color: #0dcaf0 !important; + color: #212529 !important; +} + +.caption-primary { + background-color: #0d6efd !important; +} + +.caption-success { + background-color: #198754 !important; +} \ No newline at end of file diff --git a/css/star-rating.min.css b/css/star-rating.min.css index c286742..32f3278 100644 --- a/css/star-rating.min.css +++ b/css/star-rating.min.css @@ -1,5 +1,5 @@ /*! - * bootstrap-star-rating v4.0.7 + * bootstrap-star-rating v4.0.8 * http://plugins.krajee.com/star-rating * * Author: Kartik Visweswaran @@ -7,4 +7,4 @@ * * Licensed under the BSD 3-Clause * https://github.com/kartik-v/bootstrap-star-rating/blob/master/LICENSE.md - */.rating-loading{width:25px;height:25px;font-size:0;color:#fff;background:url(../img/loading.gif) top left no-repeat;border:none}.rating-container .rating-stars{position:relative;cursor:pointer;vertical-align:middle;display:inline-block;overflow:hidden;white-space:nowrap}.rating-container .rating-stars:focus{outline:dotted 1px}.rating-input{display:absolute;cursor:pointer;width:100%;height:1px;bottom:0;left:0;font-size:1px;border:none;background:0 0;opacity:0;padding:0;margin:0}.rating-container.is-display-only .rating-stars{cursor:default}.rating-disabled .rating-stars{cursor:not-allowed}.rating-container .star{display:inline-block;margin:0 2px;text-align:center}.rating-container .empty-stars{color:#aaa}.rating-container .filled-stars{position:absolute;left:0;top:0;margin:auto;color:#fde16d;white-space:nowrap;overflow:hidden;-webkit-text-stroke:1px #777;text-shadow:1px 1px #999}.rating-rtl{float:right}.rating-animate .filled-stars{transition:width .25s ease}.rating-rtl .filled-stars{left:auto;right:0;transition:none;-webkit-transform:matrix(-1,0,0,1,0,0);transform:matrix(-1,0,0,1,0,0)}.rating-rtl.is-star .filled-stars{right:.06em}.rating-rtl.is-heart .empty-stars{margin-right:.07em}.rating-container .clear-rating{color:#aaa;cursor:not-allowed;display:inline-block;vertical-align:middle;font-size:60%;padding-right:5px}.clear-rating-active{cursor:pointer!important}.clear-rating-active:hover{color:#843534}.rating-container .caption .label{display:inline-block;padding:.25em .4em;line-height:1;text-align:center;vertical-align:baseline;border-radius:.25rem}.rating-container .caption{color:#999;display:inline-block;vertical-align:middle;line-height:1;margin-left:5px;margin-right:0}.rating-rtl .caption{margin-right:5px;margin-left:0}@media print{.rating-container .clear-rating{display:none}}.rating-xl{font-size:48px}.rating-lg{font-size:40px}.rating-md{font-size:32px}.rating-sm{font-size:24px}.rating-xs{font-size:16px}.rating-xl .caption{font-size:20px}.rating-lg .caption{font-size:18px}.rating-md .caption{font-size:16px}.rating-sm .caption{font-size:14px}.rating-xs .caption{font-size:12px} \ No newline at end of file + */.rating-loading{width:25px;height:25px;font-size:0;color:#fff;background:url(../img/loading.gif) top left no-repeat;border:none}.rating-container .rating-stars{position:relative;cursor:pointer;vertical-align:middle;display:inline-block;overflow:hidden;white-space:nowrap}.rating-container .rating-stars:focus{outline:dotted 1px}.rating-input{display:absolute;cursor:pointer;width:100%;height:1px;bottom:0;left:0;font-size:1px;border:none;background:0 0;opacity:0;padding:0;margin:0}.caption-badge,.rating-container .caption .label{line-height:1;text-align:center;border-radius:.25rem}.rating-container.is-display-only .rating-stars{cursor:default}.rating-disabled .rating-stars{cursor:not-allowed}.rating-container .star{display:inline-block;margin:0 2px;text-align:center}.rating-container .empty-stars{color:#aaa}.rating-container .filled-stars{position:absolute;left:0;top:0;margin:auto;color:#fde16d;white-space:nowrap;overflow:hidden;-webkit-text-stroke:1px #777;text-shadow:1px 1px #999}.rating-rtl{float:right}.rating-animate .filled-stars{transition:width .25s ease}.rating-rtl .filled-stars{left:auto;right:0;transition:none;-webkit-transform:matrix(-1,0,0,1,0,0);transform:matrix(-1,0,0,1,0,0)}.rating-rtl.is-star .filled-stars{right:.06em}.rating-rtl.is-heart .empty-stars{margin-right:.07em}.rating-container .clear-rating{color:#aaa;cursor:not-allowed;display:inline-block;vertical-align:middle;font-size:60%;padding-right:5px}.clear-rating-active{cursor:pointer!important}.clear-rating-active:hover{color:#843534}.rating-container .caption .label{display:inline-block;padding:.25em .4em;vertical-align:baseline}.rating-container .caption{color:#999;display:inline-block;vertical-align:middle;line-height:1;margin-left:5px;margin-right:0}.rating-rtl .caption{margin-right:5px;margin-left:0}@media print{.rating-container .clear-rating{display:none}}.rating-xl{font-size:48px}.rating-lg{font-size:40px}.rating-md{font-size:32px}.rating-sm{font-size:24px}.rating-xs{font-size:16px}.rating-xl .caption{font-size:20px}.rating-lg .caption{font-size:18px}.rating-md .caption{font-size:16px}.rating-sm .caption{font-size:14px}.rating-xs .caption{font-size:12px}.caption-badge{font-family:Arial,Helvetica,sans-serif;display:inline-block;padding:.35em .65em;font-size:.75em;font-weight:700;color:#fff;white-space:nowrap;vertical-align:baseline}.caption-secondary{background-color:#6c757d!important}.caption-danger{background-color:#dc3545!important}.caption-warning{background-color:#ffc107!important;color:#212529!important}.caption-info{background-color:#0dcaf0!important;color:#212529!important}.caption-primary{background-color:#0d6efd!important}.caption-success{background-color:#198754!important} \ No newline at end of file diff --git a/examples/index.html b/examples/index.html index f60c3aa..fe4038f 100644 --- a/examples/index.html +++ b/examples/index.html @@ -3,12 +3,15 @@ Krajee JQuery Plugins - © Kartik - - + + + - + + +
-


-
-
- +
-
-

diff --git a/js/star-rating.js b/js/star-rating.js index 783cbde..4533e6a 100644 --- a/js/star-rating.js +++ b/js/star-rating.js @@ -1,5 +1,5 @@ /*! - * bootstrap-star-rating v4.0.7 + * bootstrap-star-rating v4.0.8 * http://plugins.krajee.com/star-rating * * Author: Kartik Visweswaran @@ -649,21 +649,21 @@ showClear: true, showCaption: true, starCaptionClasses: { - 0.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' + 0.5: 'caption-badge caption-danger', + 1: 'caption-badge caption-danger', + 1.5: 'caption-badge caption-warning', + 2: 'caption-badge caption-warning', + 2.5: 'caption-badge caption-info', + 3: 'caption-badge caption-info', + 3.5: 'caption-badge caption-primary', + 4: 'caption-badge caption-primary', + 4.5: 'caption-badge caption-success', + 5: 'caption-badge caption-success' }, clearButton: '', clearButtonBaseClass: 'clear-rating', clearButtonActiveClass: 'clear-rating-active', - clearCaptionClass: 'label label-default badge-secondary', + clearCaptionClass: 'caption-badge caption-secondary', clearValue: null, captionElement: null, clearElement: null, @@ -711,4 +711,4 @@ $input.removeClass('rating-loading').addClass('rating-loading').rating(); } }); -})); +})); \ No newline at end of file diff --git a/js/star-rating.min.js b/js/star-rating.min.js index b44021e..03c9e35 100644 --- a/js/star-rating.min.js +++ b/js/star-rating.min.js @@ -1,5 +1,5 @@ /*! - * bootstrap-star-rating v4.0.7 + * bootstrap-star-rating v4.0.8 * 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(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(a,n,i,r,l){var s=l?n:n.split(" ").join(t.NAMESPACE+" ")+t.NAMESPACE;r||a.off(s),a.on(s,function(t){var a=e.proxy(i,self);a(t)})}},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,a._setDefault("minThreshold",a.min),a.minThresholda.max&&(a.minThreshold=a.max)},_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.keyboardEnabled&&r.$rating.attr("tabindex",r.tabindex),r.$emptyStars=a.find(".empty-stars"),r.$filledStars=a.find(".filled-stars"),r._renderCaption(),r._renderClear(),r._initHighlight(),r._initStarTitles();r.rtl&&(i=Math.max(r.$emptyStars.outerWidth(),r.$filledStars.outerWidth()),r.$emptyStars.width(i)),n.insertBefore(l)},_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(a){var n,i=this,r=i.$element.attr("tabindex",-1).addClass("rating-input"),l=i.minThreshold;return i.options=a,e.each(a,function(e,t){i[e]=t}),(i.rtl||"rtl"===r.attr("dir"))&&(i.rtl=!0,r.attr("dir","rtl")),i.starClicked=!1,i.clearClicked=!1,i._initSlider(a),i._checkDisabled(),i.displayOnly&&(i.inactive=!0,i.showClear=!1,i.hoverEnabled=!1,i.hoverChangeCaption=!1,i.hoverChangeStars=!1),i._generateRating(),i._initEvents(),i._listen(),!t.isEmpty(l)&&(t.isEmpty(r.val())||r.val()'+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()},focus:function(){e.$rating.focus(),e.$element.trigger("rating:focus")},blur:function(){e.$element.trigger("rating:blur")},keydown:function(a){if(!e.inactive&&e.keyboardEnabled){var n=e.$element,i=n.val(),r=!1,l=parseFloat(e.step),s=t.getDecimalPlaces(e.step),o=i?parseFloat(i):0,c=parseInt(a.which||a.keyCode||0,10);39===c&&oe.minThreshold&&(o-=l,r=!0),r&&(o=t.applyPrecision(o,s),n.val(o),e._trigChange([o,e._getCaption()]),e.showStars(n.val()),e.$rating.focus()),37!==c&&39!==c||n.trigger("rating:keydown",[o,e._getCaption()])}}}},_listen:function(){var a=this,n=a.$element,i=n.closest("form"),r=a.$rating,l=a.$clear,s=a.events,o=t.NAMESPACE,c="mousenter"+o+" mouseleave"+o,u=a.$rating.find(".star");return t.handler(r,"touchstart touchmove touchend",s.initTouch),t.handler(r,"click touchstart",s.starClick),t.handler(r,"mousemove",s.starMouseMove),t.handler(r,"mouseleave",s.starMouseLeave),t.handler(r,"keydown",s.keydown),t.handler(r,"blur",s.blur),a.showClear&&l.length&&(t.handler(l,"click touchstart",s.clearClick),t.handler(l,"mousemove",s.clearMouseMove),t.handler(l,"mouseleave",s.clearMouseLeave)),i.length&&t.handler(i,"reset",s.resetForm,!0),u.off(c).on(c,function(t){var n=e(this),i=n.index(),r=n.parent().attr("class").slice(0,-1);a.$element.trigger("rating:"+t.type,[i+1,r,n])}),t.handler(a.$container,"click",s.focus),n},_getStars:function(e){var t,a=this,n='';for(t=1;t<=a.stars;t++)n+=''+a[e+"Star"]+"";return n+""},_initStarTitles:function(t){var a=this;if(a.showCaptionAsTitle)return void a._initCaptionTitle();var n,i=a.starTitles;n=function(a){var n=1;a.each(function(){var a,r,l=e(this);"function"==typeof i?(a=n===Math.floor(t)?t:n,r=i(a)):r=i[n],r&&l.attr({title:r}),n++})},n(a.$emptyStars.find(".star")),n(a.$filledStars.find(".star"))},_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,t._initStarTitles(i),n},showStars:function(e){var t=this,a=t._parseValue(e);return t.$element.val(a),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.minThreshold),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||e<=n.min||i===r?0:(e=Math.max(e,n.minThreshold),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,d=s.getWidthFromValue(o);return o&&o!==s.clearValue&&(o=t.applyPrecision(o,t.getDecimalPlaces(s.step))),r="function"==typeof u?u(o,d):u[o],i="function"==typeof c?c(o,d):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",h={},g={};o||(u&&(h=e.fn.ratingThemes[u]||{}),"en"===d||t.isEmpty(e.fn.ratingLocales[d])||(g=e.fn.ratingLocales[d]),l=e.extend(!0,{},e.fn.rating.defaults,h,e.fn.ratingLocales.en,g,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,tabindex:0,minThreshold:1,keyboardEnabled:!0,mouseEnabled:!0,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:!1,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"},starTitles:{1:"One Star",2:"Two Stars",3:"Three Stars",4:"Four 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 +!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";t.fn.ratingLocales={},t.fn.ratingThemes={};var e,a;e={NAMESPACE:".rating",DEFAULT_MIN:0,DEFAULT_MAX:5,DEFAULT_STEP:.5,isEmpty:function(e,a){return null===e||void 0===e||0===e.length||a&&""===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(a,n,i,r,s){var l=s?n:n.split(" ").join(e.NAMESPACE+" ")+e.NAMESPACE;r||a.off(l),a.on(l,function(e){var a=t.proxy(i,self);a(e)})}},a=function(e,a){var n=this;n.$element=t(e),n._init(a)},a.prototype={constructor:a,_parseAttr:function(t,a){var n,i,r,s,l=this,o=l.$element,c=o.attr("type");if("range"===c||"number"===c){switch(i=a[t]||o.data(t)||o.attr(t),t){case"min":r=e.DEFAULT_MIN;break;case"max":r=e.DEFAULT_MAX;break;default:r=e.DEFAULT_STEP}n=e.isEmpty(i)?r:i,s=parseFloat(n)}else s=parseFloat(a[t]);return isNaN(s)?r:s},_parseValue:function(t){var e=this,a=parseFloat(t);return isNaN(a)&&(a=e.clearValue),!e.zeroAsNull||0!==a&&"0"!==a?a:null},_setDefault:function(t,a){var n=this;e.isEmpty(n[t])&&(n[t]=a)},_initSlider:function(t){var a=this,n=a.$element.val();a.initialValue=e.isEmpty(n)?0:n,a._setDefault("min",a._parseAttr("min",t)),a._setDefault("max",a._parseAttr("max",t)),a._setDefault("step",a._parseAttr("step",t)),(isNaN(a.min)||e.isEmpty(a.min))&&(a.min=e.DEFAULT_MIN),(isNaN(a.max)||e.isEmpty(a.max))&&(a.max=e.DEFAULT_MAX),(isNaN(a.step)||e.isEmpty(a.step)||0===a.step)&&(a.step=e.DEFAULT_STEP),a.diff=a.max-a.min,a._setDefault("minThreshold",a.min),a.minThresholda.max&&(a.minThreshold=a.max)},_initHighlight:function(t){var e,a=this,n=a._getCaption();t||(t=a.$element.val()),e=a.getWidthFromValue(t)+"%",a.$filledStars.width(e),a.cache={caption:n,width:e,val:t}},_getContainerCss:function(){var t=this;return"rating-container"+e.getCss(t.theme,"theme-"+t.theme)+e.getCss(t.rtl,"rating-rtl")+e.getCss(t.size,"rating-"+t.size)+e.getCss(t.animate,"rating-animate")+e.getCss(t.disabled||t.readonly,"rating-disabled")+e.getCss(t.containerClass,t.containerClass)+(t.displayOnly?" is-display-only":"")},_checkDisabled:function(){var t=this,e=t.$element,a=t.options;t.disabled=void 0===a.disabled?e.attr("disabled")||!1:a.disabled,t.readonly=void 0===a.readonly?e.attr("readonly")||!1:a.readonly,t.inactive=t.disabled||t.readonly,e.attr({disabled:t.disabled,readonly:t.readonly})},_addContent:function(t,e){var a=this,n=a.$container,i="clear"===t;return a.rtl?i?n.append(e):n.prepend(e):i?n.prepend(e):n.append(e)},_generateRating:function(){var a,n,i,r=this,s=r.$element;n=r.$container=t(document.createElement("div")).insertBefore(s),e.addCss(n,r._getContainerCss()),r.$rating=a=t(document.createElement("div")).attr("class","rating-stars").appendTo(n).append(r._getStars("empty")).append(r._getStars("filled")),r.keyboardEnabled&&r.$rating.attr("tabindex",r.tabindex),r.$emptyStars=a.find(".empty-stars"),r.$filledStars=a.find(".filled-stars"),r._renderCaption(),r._renderClear(),r._initHighlight(),r._initStarTitles();r.rtl&&(i=Math.max(r.$emptyStars.outerWidth(),r.$filledStars.outerWidth()),r.$emptyStars.width(i)),n.insertBefore(s)},_getCaption:function(){var t=this;return t.$caption&&t.$caption.length?t.$caption.html():t.defaultCaption},_setCaption:function(t){var e=this;e.$caption&&e.$caption.length&&e.$caption.html(t)},_renderCaption:function(){var a,n=this,i=n.$element.val(),r=n.captionElement?t(n.captionElement):"";if(n.showCaption){if(a=n.fetchCaption(i),r&&r.length)return e.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?t(n.clearElement):"";if(n.showClear){if(a=n._getClearClass(),i.length)return e.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 t=this;return t.clearButtonBaseClass+" "+(t.inactive?"":t.clearButtonActiveClass)},_toggleHover:function(t){var e,a,n,i=this;t&&(i.hoverChangeStars&&(e=i.getWidthFromValue(i.clearValue),a=t.val<=i.clearValue?e+"%":t.width,i.$filledStars.css("width",a)),i.hoverChangeCaption&&(n=t.val<=i.clearValue?i.fetchCaption(i.clearValue):t.caption,n&&i._setCaption(n+"")))},_init:function(a){var n,i=this,r=i.$element.attr("tabindex",-1).addClass("rating-input"),s=i.minThreshold;return i.options=a,t.each(a,function(t,e){i[t]=e}),(i.rtl||"rtl"===r.attr("dir"))&&(i.rtl=!0,r.attr("dir","rtl")),i.starClicked=!1,i.clearClicked=!1,i._initSlider(a),i._checkDisabled(),i.displayOnly&&(i.inactive=!0,i.showClear=!1,i.hoverEnabled=!1,i.hoverChangeCaption=!1,i.hoverChangeStars=!1),i._generateRating(),i._initEvents(),i._listen(),!e.isEmpty(s)&&(e.isEmpty(r.val())||r.val()'+t.clearCaption+"",n=t.clearValue,i=t.getWidthFromValue(n)||0,r={caption:a,width:i,val:n},t._toggleHover(r),t.$element.trigger("rating:hover",[n,a,"clear"]))},clearMouseLeave:function(e){var a;t.events._noMouseAction(e)||t.clearClicked||!t.hoverOnClear||(a=t.cache,t._toggleHover(a),t.$element.trigger("rating:hoverleave",["clear"]))},resetForm:function(e){e&&e.isDefaultPrevented()||t.inactive||t.reset()},focus:function(){t.$rating.focus(),t.$element.trigger("rating:focus")},blur:function(){t.$element.trigger("rating:blur")},keydown:function(a){if(!t.inactive&&t.keyboardEnabled){var n=t.$element,i=n.val(),r=!1,s=parseFloat(t.step),l=e.getDecimalPlaces(t.step),o=i?parseFloat(i):0,c=parseInt(a.which||a.keyCode||0,10);39===c&&ot.minThreshold&&(o-=s,r=!0),r&&(o=e.applyPrecision(o,l),n.val(o),t._trigChange([o,t._getCaption()]),t.showStars(n.val()),t.$rating.focus()),37!==c&&39!==c||n.trigger("rating:keydown",[o,t._getCaption()])}}}},_listen:function(){var a=this,n=a.$element,i=n.closest("form"),r=a.$rating,s=a.$clear,l=a.events,o=e.NAMESPACE,c="mousenter"+o+" mouseleave"+o,u=a.$rating.find(".star");return e.handler(r,"touchstart touchmove touchend",l.initTouch),e.handler(r,"click touchstart",l.starClick),e.handler(r,"mousemove",l.starMouseMove),e.handler(r,"mouseleave",l.starMouseLeave),e.handler(r,"keydown",l.keydown),e.handler(r,"blur",l.blur),a.showClear&&s.length&&(e.handler(s,"click touchstart",l.clearClick),e.handler(s,"mousemove",l.clearMouseMove),e.handler(s,"mouseleave",l.clearMouseLeave)),i.length&&e.handler(i,"reset",l.resetForm,!0),u.off(c).on(c,function(e){var n=t(this),i=n.index(),r=n.parent().attr("class").slice(0,-1);a.$element.trigger("rating:"+e.type,[i+1,r,n])}),e.handler(a.$container,"click",l.focus),n},_getStars:function(t){var e,a=this,n='';for(e=1;e<=a.stars;e++)n+=''+a[t+"Star"]+"";return n+""},_initStarTitles:function(e){var a=this;if(a.showCaptionAsTitle)return void a._initCaptionTitle();var n,i=a.starTitles;n=function(a){var n=1;a.each(function(){var a,r,s=t(this);"function"==typeof i?(a=n===Math.floor(e)?e:n,r=i(a)):r=i[n],r&&s.attr({title:r}),n++})},n(a.$emptyStars.find(".star")),n(a.$filledStars.find(".star"))},_setStars:function(t){var e=this,a=arguments.length?e.calculate(t):e.calculate(),n=e.$element,i=e._parseValue(a.val);return n.val(i),e.$filledStars.css("width",a.width),e._setCaption(a.caption),e.cache=a,e._initStarTitles(i),n},showStars:function(t){var e=this,a=e._parseValue(t);return e.$element.val(a),e._setStars()},calculate:function(t){var a=this,n=e.isEmpty(a.$element.val())?0:a.$element.val(),i=arguments.length?a.getValueFromPosition(t):n,r=a.fetchCaption(i),s=a.getWidthFromValue(i);return s+="%",{caption:r,width:s,val:i}},getValueFromPosition:function(t){var a,n,i=this,r=e.getDecimalPlaces(i.step),s=i.$rating.width();return n=i.diff*t/(s*i.step),n=i.rtl?Math.floor(n):Math.ceil(n),a=e.applyPrecision(parseFloat(i.min+n*i.step),r),a=Math.max(Math.min(a,i.max),i.minThreshold),i.rtl?i.max-a:a},getWidthFromValue:function(t){var e,a,n=this,i=n.min,r=n.max,s=n.$emptyStars;return!t||t<=n.min||i===r?0:(t=Math.max(t,n.minThreshold),a=s.outerWidth(),e=a?s.width()/a:1,t>=r?100:(t-i)*e*100/(r-i))},fetchCaption:function(t){var a,n,i,r,s,l=this,o=parseFloat(t)||l.clearValue,c=l.starCaptions,u=l.starCaptionClasses,d=l.getWidthFromValue(o);return o&&o!==l.clearValue&&(o=e.applyPrecision(o,e.getDecimalPlaces(l.step))),r="function"==typeof u?u(o,d):u[o],i="function"==typeof c?c(o,d):c[o],n=e.isEmpty(i)?l.defaultCaption.replace(/\{rating}/g,o):i,a=e.isEmpty(r)?l.clearCaptionClass:r,s=o===l.clearValue?l.clearCaption:n,''+s+""},destroy:function(){var a=this,n=a.$element;return e.isEmpty(a.$container)||a.$container.before(n).remove(),t.removeData(n.get(0)),n.off("rating").removeClass("rating rating-input")},create:function(t){var e=this,a=t||e.options||{};return e.destroy().rating(a)},clear:function(){var t=this,e=''+t.clearCaption+"";return t.inactive||t._setCaption(e),t.showStars(t.clearValue).trigger("change").trigger("rating:clear")},reset:function(){var t=this;return t.showStars(t.initialValue).trigger("rating:reset")},update:function(t){var e=this;return arguments.length?e.showStars(t):e.$element},refresh:function(e){var a=this,n=a.$element;return e?a.destroy().rating(t.extend(!0,a.options,e)).trigger("rating:refresh"):n}},t.fn.rating=function(n){var i=Array.apply(null,arguments),r=[];switch(i.shift(),this.each(function(){var s,l=t(this),o=l.data("rating"),c="object"==typeof n&&n,u=c.theme||l.data("theme"),d=c.language||l.data("language")||"en",h={},p={};o||(u&&(h=t.fn.ratingThemes[u]||{}),"en"===d||e.isEmpty(t.fn.ratingLocales[d])||(p=t.fn.ratingLocales[d]),s=t.extend(!0,{},t.fn.rating.defaults,h,t.fn.ratingLocales.en,p,c,l.data()),o=new a(this,s),l.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}},t.fn.rating.defaults={theme:"",language:"en",stars:5,tabindex:0,minThreshold:1,keyboardEnabled:!0,mouseEnabled:!0,filledStar:'',emptyStar:'',containerClass:"",size:"md",animate:!0,displayOnly:!1,rtl:!1,showClear:!0,showCaption:!0,starCaptionClasses:{.5:"caption-badge caption-danger",1:"caption-badge caption-danger",1.5:"caption-badge caption-warning",2:"caption-badge caption-warning",2.5:"caption-badge caption-info",3:"caption-badge caption-info",3.5:"caption-badge caption-primary",4:"caption-badge caption-primary",4.5:"caption-badge caption-success",5:"caption-badge caption-success"},clearButton:'',clearButtonBaseClass:"clear-rating",clearButtonActiveClass:"clear-rating-active",clearCaptionClass:"caption-badge caption-secondary",clearValue:null,captionElement:null,clearElement:null,showCaptionAsTitle:!1,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"},starTitles:{1:"One Star",2:"Two Stars",3:"Three Stars",4:"Four Stars",5:"Five Stars"},clearButtonTitle:"Clear",clearCaption:"Not Rated"},t.fn.rating.Constructor=a,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 diff --git a/package.json b/package.json index dd08e6f..a514b98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-star-rating", - "version": "4.0.7", + "version": "4.0.8", "homepage": "https://github.com/kartik-v/bootstrap-star-rating", "author": "Kartik Visweswaran ", "description": "A simple yet powerful JQuery star rating plugin for Bootstrap.",