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