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