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