11 lines
10 KiB
JavaScript
11 lines
10 KiB
JavaScript
|
/*!
|
||
|
* jQuery Raty - A Star Rating Plugin
|
||
|
*
|
||
|
* The MIT License
|
||
|
*
|
||
|
* @author : Washington Botelho
|
||
|
* @doc : http://wbotelhos.com/raty
|
||
|
* @version : 2.7.0
|
||
|
*
|
||
|
*/
|
||
|
!function(a){"use strict";var b={init:function(c){return this.each(function(){this.self=a(this),b.destroy.call(this.self),this.opt=a.extend(!0,{},a.fn.raty.defaults,c),b._adjustCallback.call(this),b._adjustNumber.call(this),b._adjustHints.call(this),this.opt.score=b._adjustedScore.call(this,this.opt.score),"img"!==this.opt.starType&&b._adjustStarType.call(this),b._adjustPath.call(this),b._createStars.call(this),this.opt.cancel&&b._createCancel.call(this),this.opt.precision&&b._adjustPrecision.call(this),b._createScore.call(this),b._apply.call(this,this.opt.score),b._setTitle.call(this,this.opt.score),b._target.call(this,this.opt.score),this.opt.readOnly?b._lock.call(this):(this.style.cursor="pointer",b._binds.call(this))})},_adjustCallback:function(){for(var a=["number","readOnly","score","scoreName","target"],b=0;b<a.length;b++)"function"==typeof this.opt[a[b]]&&(this.opt[a[b]]=this.opt[a[b]].call(this))},_adjustedScore:function(a){return a?b._between(a,0,this.opt.number):a},_adjustHints:function(){if(this.opt.hints||(this.opt.hints=[]),this.opt.halfShow||this.opt.half)for(var a=this.opt.precision?10:2,b=0;b<this.opt.number;b++){var c=this.opt.hints[b];"[object Array]"!==Object.prototype.toString.call(c)&&(c=[c]),this.opt.hints[b]=[];for(var d=0;a>d;d++){var e=c[d],f=c[c.length-1];void 0===f&&(f=null),this.opt.hints[b][d]=void 0===e?f:e}}},_adjustNumber:function(){this.opt.number=b._between(this.opt.number,1,this.opt.numberMax)},_adjustPath:function(){this.opt.path=this.opt.path||"",this.opt.path&&"/"!==this.opt.path.charAt(this.opt.path.length-1)&&(this.opt.path+="/")},_adjustPrecision:function(){this.opt.half=!0},_adjustStarType:function(){var a=["cancelOff","cancelOn","starHalf","starOff","starOn"];this.opt.path="";for(var b=0;b<a.length;b++)this.opt[a[b]]=this.opt[a[b]].replace(".","-")},_apply:function(a){b._fill.call(this,a),a&&(a>0&&this.score.val(a),b._roundStars.call(this,a))},_between:function(a,b,c){return Math.min(Math.max(parseFloat(a),b),c)},_binds:function(){this.cancel&&(b._bindOverCancel.call(this),b._bindClickCancel.call(this),b._bindOutCancel.call(this)),b._bindOver.call(this),b._bindClick.call(this),b._bindOut.call(this)},_bindClick:function(){var c=this;c.stars.on("click.raty",function(d){var e=!0,f=c.opt.half||c.opt.precision?c.self.data("score"):this.alt||a(this).data("alt");c.opt.click&&(e=c.opt.click.call(c,+f,d)),(e||void 0===e)&&(c.opt.half&&!c.opt.precision&&(f=b._roundHalfScore.call(c,f)),b._apply.call(c,f))})},_bindClickCancel:function(){var a=this;a.cancel.on("click.raty",function(b){a.score.removeAttr("value"),a.opt.click&&a.opt.click.call(a,null,b)})},_bindOut:function(){var a=this;a.self.on("mouseleave.raty",function(c){var d=+a.score.val()||void 0;b._apply.call(a,d),b._target.call(a,d,c),b._resetTitle.call(a),a.opt.mouseout&&a.opt.mouseout.call(a,d,c)})},_bindOutCancel:function(){var a=this;a.cancel.on("mouseleave.raty",function(c){var d=a.opt.cancelOff;if("img"!==a.opt.starType&&(d=a.opt.cancelClass+" "+d),b._setIcon.call(a,this,d),a.opt.mouseout){var e=+a.score.val()||void 0;a.opt.mouseout.call(a,e,c)}})},_bindOver:function(){var a=this,c=a.opt.half?"mousemove.raty":"mouseover.raty";a.stars.on(c,function(c){var d=b._getScoreByPosition.call(a,c,this);b._fill.call(a,d),a.opt.half&&(b._roundStars.call(a,d,c),b._setTitle.call(a,d,c),a.self.data("score",d)),b._target.call(a,d,c),a.opt.mouseover&&a.opt.mouseover.call(a,d,c)})},_bindOverCancel:function(){var a=this;a.cancel.on("mouseover.raty",function(c){var d=a.opt.path+a.opt.starOff,e=a.opt.cancelOn;"img"===a.opt.starType?a.stars.attr("src",d):(e=a.opt.cancelClass+" "+e,a.stars.attr("class",d)),b._setIcon.call(a,this,e),b._target.call(a,null,c),a.opt.mouseover&&a.opt.mouseover.call(a,null)})},_buildScoreField:function(){return a("<input />",{name:this.opt.scoreName,type:"hidden"}).appendTo(this)},_createCancel:function(){var b=this.opt.path+this.opt.cancelOff,c=a("<"+this.opt.starType+" />",{title:this.opt.cancelHint,"class":this.opt.cancelClass});"img"===this.opt.starType?c.attr({src:b,alt:"x"}):c.attr("data-alt","x").addClass(b),"left
|