mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-26 17:47:20 +00:00
1 line
No EOL
5.3 KiB
JavaScript
1 line
No EOL
5.3 KiB
JavaScript
!function(e,n,t,i){"use strict";n=void 0!==n&&n.Math==Math?n:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.rating=function(n){var t,i=e(this),a=i.selector||"",o=(new Date).getTime(),r=[],s=arguments[0],l="string"==typeof s,c=[].slice.call(arguments,1);return i.each(function(){var d,u,g=e.isPlainObject(n)?e.extend(!0,{},e.fn.rating.settings,n):e.extend({},e.fn.rating.settings),m=g.namespace,v=g.className,f=g.metadata,p=g.selector,b=(g.error,"."+m),h="module-"+m,y=this,x=e(this).data(h),R=e(this),C=R.find(p.icon);u={initialize:function(){u.verbose("Initializing rating module",g),0===C.length&&u.setup.layout(),g.interactive?u.enable():u.disable(),u.set.initialLoad(),u.set.rating(u.get.initialRating()),u.remove.initialLoad(),u.instantiate()},instantiate:function(){u.verbose("Instantiating module",g),x=u,R.data(h,u)},destroy:function(){u.verbose("Destroying previous instance",x),u.remove.events(),R.removeData(h)},refresh:function(){C=R.find(p.icon)},setup:{layout:function(){var n=u.get.maxRating(),t=e.fn.rating.settings.templates.icon(n);u.debug("Generating icon html dynamically"),R.html(t),u.refresh()}},event:{mouseenter:function(){var n=e(this);n.nextAll().removeClass(v.selected),R.addClass(v.selected),n.addClass(v.selected).prevAll().addClass(v.selected)},mouseleave:function(){R.removeClass(v.selected),C.removeClass(v.selected)},click:function(){var n=e(this),t=u.get.rating(),i=C.index(n)+1;("auto"==g.clearable?1===C.length:g.clearable)&&t==i?u.clearRating():u.set.rating(i)}},clearRating:function(){u.debug("Clearing current rating"),u.set.rating(0)},bind:{events:function(){u.verbose("Binding events"),R.on("mouseenter"+b,p.icon,u.event.mouseenter).on("mouseleave"+b,p.icon,u.event.mouseleave).on("click"+b,p.icon,u.event.click)}},remove:{events:function(){u.verbose("Removing events"),R.off(b)},initialLoad:function(){d=!1}},enable:function(){u.debug("Setting rating to interactive mode"),u.bind.events(),R.removeClass(v.disabled)},disable:function(){u.debug("Setting rating to read-only mode"),u.remove.events(),R.addClass(v.disabled)},is:{initialLoad:function(){return d}},get:{initialRating:function(){return void 0!==R.data(f.rating)?(R.removeData(f.rating),R.data(f.rating)):g.initialRating},maxRating:function(){return void 0!==R.data(f.maxRating)?(R.removeData(f.maxRating),R.data(f.maxRating)):g.maxRating},rating:function(){var e=C.filter("."+v.active).length;return u.verbose("Current rating retrieved",e),e}},set:{rating:function(e){var n=e-1>=0?e-1:0,t=C.eq(n);R.removeClass(v.selected),C.removeClass(v.selected).removeClass(v.active),e>0&&(u.verbose("Setting current rating to",e),t.prevAll().addBack().addClass(v.active)),u.is.initialLoad()||g.onRate.call(y,e)},initialLoad:function(){d=!0}},setting:function(n,t){if(u.debug("Changing setting",n,t),e.isPlainObject(n))e.extend(!0,g,n);else{if(void 0===t)return g[n];e.isPlainObject(g[n])?e.extend(!0,g[n],t):g[n]=t}},internal:function(n,t){if(e.isPlainObject(n))e.extend(!0,u,n);else{if(void 0===t)return u[n];u[n]=t}},debug:function(){!g.silent&&g.debug&&(g.performance?u.performance.log(arguments):(u.debug=Function.prototype.bind.call(console.info,console,g.name+":"),u.debug.apply(console,arguments)))},verbose:function(){!g.silent&&g.verbose&&g.debug&&(g.performance?u.performance.log(arguments):(u.verbose=Function.prototype.bind.call(console.info,console,g.name+":"),u.verbose.apply(console,arguments)))},error:function(){g.silent||(u.error=Function.prototype.bind.call(console.error,console,g.name+":"),u.error.apply(console,arguments))},performance:{log:function(e){var n,t,i;g.performance&&(n=(new Date).getTime(),i=o||n,t=n-i,o=n,r.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:y,"Execution Time":t})),clearTimeout(u.performance.timer),u.performance.timer=setTimeout(u.performance.display,500)},display:function(){var n=g.name+":",t=0;o=!1,clearTimeout(u.performance.timer),e.each(r,function(e,n){t+=n["Execution Time"]}),n+=" "+t+"ms",a&&(n+=" '"+a+"'"),i.length>1&&(n+=" ("+i.length+")"),(void 0!==console.group||void 0!==console.table)&&r.length>0&&(console.groupCollapsed(n),console.table?console.table(r):e.each(r,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),r=[]}},invoke:function(n,i,a){var o,r,s,l=x;return i=i||c,a=y||a,"string"==typeof n&&void 0!==l&&(n=n.split(/[\. ]/),o=n.length-1,e.each(n,function(t,i){var a=t!=o?i+n[t+1].charAt(0).toUpperCase()+n[t+1].slice(1):n;if(e.isPlainObject(l[a])&&t!=o)l=l[a];else{if(void 0!==l[a])return r=l[a],!1;if(!e.isPlainObject(l[i])||t==o)return void 0!==l[i]&&(r=l[i],!1);l=l[i]}})),e.isFunction(r)?s=r.apply(a,i):void 0!==r&&(s=r),e.isArray(t)?t.push(s):void 0!==t?t=[t,s]:void 0!==s&&(t=s),r}},l?(void 0===x&&u.initialize(),u.invoke(s)):(void 0!==x&&x.invoke("destroy"),u.initialize())}),void 0!==t?t:this},e.fn.rating.settings={name:"Rating",namespace:"rating",slent:!1,debug:!1,verbose:!1,performance:!0,initialRating:0,interactive:!0,maxRating:4,clearable:"auto",fireOnInit:!1,onRate:function(e){},error:{method:"The method you called is not defined",noMaximum:"No maximum rating specified. Cannot generate HTML automatically"},metadata:{rating:"rating",maxRating:"maxRating"},className:{active:"active",disabled:"disabled",selected:"selected",loading:"loading"},selector:{icon:".icon"},templates:{icon:function(e){for(var n=1,t="";n<=e;)t+='<i class="icon"></i>',n++;return t}}}}(jQuery,window,document); |