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