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.
 
 
 

11 lines
4.8 KiB

/*
* # Semantic UI
* https://github.com/Semantic-Org/Semantic-UI
* http://www.semantic-ui.com/
*
* Copyright 2014 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(e,n,t,i){"use strict";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=e.isPlainObject(n)?e.extend(!0,{},e.fn.rating.settings,n):e.extend({},e.fn.rating.settings),m=d.namespace,f=d.className,v=d.metadata,p=d.selector,b=(d.error,"."+m),h="module-"+m,y=this,R=e(this).data(h),C=e(this),x=C.find(p.icon);g={initialize:function(){g.verbose("Initializing rating module",d),0===x.size()&&g.setup.layout(),d.interactive?g.enable():g.disable(),d.initialRating&&(g.debug("Setting initial rating"),g.setRating(d.initialRating)),C.data(v.rating)&&(g.debug("Rating found in metadata"),g.setRating(C.data(v.rating))),g.instantiate()},instantiate:function(){g.verbose("Instantiating module",d),R=g,C.data(h,g)},destroy:function(){g.verbose("Destroying previous instance",R),C.removeData(h),x.off(b)},refresh:function(){x=C.find(p.icon)},setup:{layout:function(){var n=C.data(v.maxRating)||d.maxRating;g.debug("Generating icon html dynamically"),C.html(e.fn.rating.settings.templates.icon(n)),g.refresh()}},event:{mouseenter:function(){var n=e(this);n.nextAll().removeClass(f.selected),C.addClass(f.selected),n.addClass(f.selected).prevAll().addClass(f.selected)},mouseleave:function(){C.removeClass(f.selected),x.removeClass(f.selected)},click:function(){var n=e(this),t=g.getRating(),i=x.index(n)+1,a="auto"==d.clearable?1===x.size():d.clearable;a&&t==i?g.clearRating():g.setRating(i)}},clearRating:function(){g.debug("Clearing current rating"),g.setRating(0)},getRating:function(){var e=x.filter("."+f.active).size();return g.verbose("Current rating retrieved",e),e},enable:function(){g.debug("Setting rating to interactive mode"),x.on("mouseenter"+b,g.event.mouseenter).on("mouseleave"+b,g.event.mouseleave).on("click"+b,g.event.click),C.removeClass(f.disabled)},disable:function(){g.debug("Setting rating to read-only mode"),x.off(b),C.addClass(f.disabled)},setRating:function(n){var t=n-1>=0?n-1:0,i=x.eq(t);C.removeClass(f.selected),x.removeClass(f.selected).removeClass(f.active),n>0&&(g.verbose("Setting current rating to",n),i.prevAll().andSelf().addClass(f.active)),e.proxy(d.onRate,y)(n)},setting:function(n,t){if(g.debug("Changing setting",n,t),e.isPlainObject(n))e.extend(!0,d,n);else{if(t===i)return d[n];d[n]=t}},internal:function(n,t){if(e.isPlainObject(n))e.extend(!0,g,n);else{if(t===i)return g[n];g[n]=t}},debug:function(){d.debug&&(d.performance?g.performance.log(arguments):(g.debug=Function.prototype.bind.call(console.info,console,d.name+":"),g.debug.apply(console,arguments)))},verbose:function(){d.verbose&&d.debug&&(d.performance?g.performance.log(arguments):(g.verbose=Function.prototype.bind.call(console.info,console,d.name+":"),g.verbose.apply(console,arguments)))},error:function(){g.error=Function.prototype.bind.call(console.error,console,d.name+":"),g.error.apply(console,arguments)},performance:{log:function(e){var n,t,i;d.performance&&(n=(new Date).getTime(),i=r||n,t=n-i,r=n,s.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:y,"Execution Time":t})),clearTimeout(g.performance.timer),g.performance.timer=setTimeout(g.performance.display,100)},display:function(){var n=d.name+":",t=0;r=!1,clearTimeout(g.performance.timer),e.each(s,function(e,n){t+=n["Execution Time"]}),n+=" "+t+"ms",o&&(n+=" '"+o+"'"),a.size()>1&&(n+=" ("+a.size()+")"),(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=y||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&&g.initialize(),g.invoke(l)):(R!==i&&g.destroy(),g.initialize())}),t!==i?t:this},e.fn.rating.settings={name:"Rating",namespace:"rating",debug:!1,verbose:!0,performance:!0,initialRating:0,interactive:!0,maxRating:4,clearable:"auto",onRate:function(){},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+='<i class="icon"></i>',n++;return t}}}}(jQuery,window,document);