You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
5.2 KiB

!function(C,e,n,T){"use strict";e=void 0!==e&&e.Math==Math?e:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),C.fn.rating=function(m){var f,v=C(this),p=v.selector||"",b=(new Date).getTime(),h=[],y=m,x="string"==typeof y,R=[].slice.call(arguments,1);return v.each(function(){var e,i,a=C.isPlainObject(m)?C.extend(!0,{},C.fn.rating.settings,m):C.extend({},C.fn.rating.settings),n=a.namespace,o=a.className,t=a.metadata,r=a.selector,s=(a.error,"."+n),l="module-"+n,c=this,u=C(this).data(l),d=C(this),g=d.find(r.icon);i={initialize:function(){i.verbose("Initializing rating module",a),0===g.length&&i.setup.layout(),a.interactive?i.enable():i.disable(),i.set.initialLoad(),i.set.rating(i.get.initialRating()),i.remove.initialLoad(),i.instantiate()},instantiate:function(){i.verbose("Instantiating module",a),u=i,d.data(l,i)},destroy:function(){i.verbose("Destroying previous instance",u),i.remove.events(),d.removeData(l)},refresh:function(){g=d.find(r.icon)},setup:{layout:function(){var e=i.get.maxRating(),n=C.fn.rating.settings.templates.icon(e);i.debug("Generating icon html dynamically"),d.html(n),i.refresh()}},event:{mouseenter:function(){var e=C(this);e.nextAll().removeClass(o.selected),d.addClass(o.selected),e.addClass(o.selected).prevAll().addClass(o.selected)},mouseleave:function(){d.removeClass(o.selected),g.removeClass(o.selected)},click:function(){var e=C(this),n=i.get.rating(),t=g.index(e)+1;("auto"==a.clearable?1===g.length:a.clearable)&&n==t?i.clearRating():i.set.rating(t)}},clearRating:function(){i.debug("Clearing current rating"),i.set.rating(0)},bind:{events:function(){i.verbose("Binding events"),d.on("mouseenter"+s,r.icon,i.event.mouseenter).on("mouseleave"+s,r.icon,i.event.mouseleave).on("click"+s,r.icon,i.event.click)}},remove:{events:function(){i.verbose("Removing events"),d.off(s)},initialLoad:function(){e=!1}},enable:function(){i.debug("Setting rating to interactive mode"),i.bind.events(),d.removeClass(o.disabled)},disable:function(){i.debug("Setting rating to read-only mode"),i.remove.events(),d.addClass(o.disabled)},is:{initialLoad:function(){return e}},get:{initialRating:function(){return d.data(t.rating)!==T?(d.removeData(t.rating),d.data(t.rating)):a.initialRating},maxRating:function(){return d.data(t.maxRating)!==T?(d.removeData(t.maxRating),d.data(t.maxRating)):a.maxRating},rating:function(){var e=g.filter("."+o.active).length;return i.verbose("Current rating retrieved",e),e}},set:{rating:function(e){var n=0<=e-1?e-1:0,t=g.eq(n);d.removeClass(o.selected),g.removeClass(o.selected).removeClass(o.active),0<e&&(i.verbose("Setting current rating to",e),t.prevAll().addBack().addClass(o.active)),i.is.initialLoad()||a.onRate.call(c,e)},initialLoad:function(){e=!0}},setting:function(e,n){if(i.debug("Changing setting",e,n),C.isPlainObject(e))C.extend(!0,a,e);else{if(n===T)return a[e];C.isPlainObject(a[e])?C.extend(!0,a[e],n):a[e]=n}},internal:function(e,n){if(C.isPlainObject(e))C.extend(!0,i,e);else{if(n===T)return i[e];i[e]=n}},debug:function(){!a.silent&&a.debug&&(a.performance?i.performance.log(arguments):(i.debug=Function.prototype.bind.call(console.info,console,a.name+":"),i.debug.apply(console,arguments)))},verbose:function(){!a.silent&&a.verbose&&a.debug&&(a.performance?i.performance.log(arguments):(i.verbose=Function.prototype.bind.call(console.info,console,a.name+":"),i.verbose.apply(console,arguments)))},error:function(){a.silent||(i.error=Function.prototype.bind.call(console.error,console,a.name+":"),i.error.apply(console,arguments))},performance:{log:function(e){var n,t;a.performance&&(t=(n=(new Date).getTime())-(b||n),b=n,h.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:c,"Execution Time":t})),clearTimeout(i.performance.timer),i.performance.timer=setTimeout(i.performance.display,500)},display:function(){var e=a.name+":",t=0;b=!1,clearTimeout(i.performance.timer),C.each(h,function(e,n){t+=n["Execution Time"]}),e+=" "+t+"ms",p&&(e+=" '"+p+"'"),1<v.length&&(e+=" ("+v.length+")"),(console.group!==T||console.table!==T)&&0<h.length&&(console.groupCollapsed(e),console.table?cons