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 lines
3.9 KiB

!function(a,b,c,d){a.fn.rating=function(b){var c,e=a(this),f=e.selector||"",g=a.extend(!0,{},a.fn.rating.settings,b),h=g.namespace,i=g.className,j=g.metadata,k=g.selector,l=g.error,m="."+h,n="module-"+h,o=(new Date).getTime(),p=[],q=arguments[0],r="string"==typeof q,s=[].slice.call(arguments,1);return e.each(function(){var b,e=a(this),h=e.find(k.icon),t=this,u=e.data(n);b={initialize:function(){b.verbose("Initializing rating module",g),g.interactive?b.enable():b.disable(),g.initialRating&&(b.debug("Setting initial rating"),b.setRating(g.initialRating)),e.data(j.rating)&&(b.debug("Rating found in metadata"),b.setRating(e.data(j.rating))),b.instantiate()},instantiate:function(){b.verbose("Instantiating module",g),e.data(n,b)},destroy:function(){e.removeData(n),h.off(m)},event:{mouseenter:function(){var b=a(this);b.nextAll().removeClass(i.hover),e.addClass(i.hover),b.addClass(i.hover).prevAll().addClass(i.hover)},mouseleave:function(){e.removeClass(i.hover),h.removeClass(i.hover)},click:function(){var c=a(this),d=b.getRating(),e=h.index(c)+1;g.clearable&&d==e?b.clearRating():b.setRating(e)}},clearRating:function(){b.debug("Clearing current rating"),b.setRating(0)},getRating:function(){var a=h.filter("."+i.active).size();return b.verbose("Current rating retrieved",a),a},enable:function(){b.debug("Setting rating to interactive mode"),h.on("mouseenter"+m,b.event.mouseenter).on("mouseleave"+m,b.event.mouseleave).on("click"+m,b.event.click),e.addClass(i.active)},disable:function(){b.debug("Setting rating to read-only mode"),h.off(m),e.removeClass(i.active)},setRating:function(c){var d=c-1>=0?c-1:0,f=h.eq(d);e.removeClass(i.hover),h.removeClass(i.hover).removeClass(i.active),c>0&&(b.verbose("Setting current rating to",c),f.addClass(i.active).prevAll().addClass(i.active)),a.proxy(g.onRate,t)(c)},setting:function(b,c){return c===d?g[b]:(a.isPlainObject(b)?a.extend(!0,g,b):g[b]=c,void 0)},internal:function(c,e){return e===d?b[c]:(a.isPlainObject(c)?a.extend(!0,b,c):b[c]=e,void 0)},debug:function(){g.debug&&(g.performance?b.performance.log(arguments):(b.debug=Function.prototype.bind.call(console.info,console,g.name+":"),b.debug.apply(console,arguments)))},verbose:function(){g.verbose&&g.debug&&(g.performance?b.performance.log(arguments):(b.verbose=Function.prototype.bind.call(console.info,console,g.name+":"),b.verbose.apply(console,arguments)))},error:function(){b.error=Function.prototype.bind.call(console.error,console,g.name+":"),b.error.apply(console,arguments)},performance:{log:function(a){var c,d,e;g.performance&&(c=(new Date).getTime(),e=o||c,d=c-e,o=c,p.push({Element:t,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":d})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,100)},display:function(){var c=g.name+":",e=0;o=!1,clearTimeout(b.performance.timer),a.each(p,function(a,b){e+=b["Execution Time"]}),c+=" "+e+"ms",f&&(c+=" '"+f+"'"),(console.group!==d||console.table!==d)&&p.length>0&&(console.groupCollapsed(c),console.table?console.table(p):a.each(p,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),p=[]}},invoke:function(e,f,g){var h,i,j;return f=f||s,g=t||g,"string"==typeof e&&u!==d&&(e=e.split(/[\. ]/),h=e.length-1,a.each(e,function(c,f){var g=c!=h?f+e[c+1].charAt(0).toUpperCase()+e[c+1].slice(1):e;if(a.isPlainObject(u[f])&&c!=h)u=u[f];else{if(!a.isPlainObject(u[g])||c==h)return u[f]!==d?(i=u[f],!1):u[g]!==d?(i=u[g],!1):(b.error(l.method),!1);u=u[g]}})),a.isFunction(i)?j=i.apply(g,f):i!==d&&(j=i),a.isArray(c)?c.push(j):"string"==typeof c?c=[c,j]:j!==d&&(c=j),i}},r?(u===d&&b.initialize(),b.invoke(q)):(u!==d&&b.destroy(),b.initialize())}),c!==d?c:this},a.fn.rating.settings={name:"Rating",namespace:"rating",verbose:!0,debug:!0,performance:!0,initialRating:0,interactive:!0,clearable:!1,onRate:function(){},error:{method:"The method you called is not defined"},metadata:{rating:"rating"},className:{active:"active",hover:"hover",loading:"loading"},selector:{icon:".icon"}}}(jQuery,window,document);