bazarr/static/semantic/components/rating.min.js

1 line
5.3 KiB
JavaScript
Raw Normal View History

2017-09-28 01:55:21 +00:00
!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&&