11 lines
No EOL
6.2 KiB
JavaScript
11 lines
No EOL
6.2 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.0
|
|
* 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),n=a.namespace,o=a.className,t=a.metadata,i=a.selector,r=a.cssVars,s="."+n,l="module-"+n,c=this,u=A(this).data(l),d=A(this),g=d.find(i.icon),m={initialize:function(){m.verbose("Initializing rating module",a),0===g.length&&m.setup.layout(),a.interactive&&!m.is.disabled()?m.enable():m.disable(),m.set.initialLoad(),m.set.rating(m.get.initialRating()),m.remove.initialLoad(),m.instantiate()},instantiate:function(){m.verbose("Instantiating module",a),u=m,d.data(l,m)},destroy:function(){m.verbose("Destroying previous instance",u),m.remove.events(),d.removeData(l)},refresh:function(){g=d.find(i.icon)},setup:{layout:function(){var e=m.get.maxRating(),n=m.get.icon(),e=A.fn.rating.settings.templates.icon(e,n);m.debug("Generating icon html dynamically"),d.html(e),m.refresh()}},event:{mouseenter:function(){var e=A(this);e.nextAll().removeClass(o.selected),d.addClass(o.selected),e.addClass(o.selected).prevAll().addClass(o.selected)},mouseleave:function(){d.removeClass(o.selected),g.removeClass(o.selected)},click:function(){var e=A(this),n=m.get.rating(),e=g.index(e)+1;("auto"==a.clearable?1===g.length:a.clearable)&&n==e?m.clearRating():m.set.rating(e)}},clearRating:function(){m.debug("Clearing current rating"),m.set.rating(0)},bind:{events:function(){m.verbose("Binding events"),d.on("mouseenter"+s,i.icon,m.event.mouseenter).on("mouseleave"+s,i.icon,m.event.mouseleave).on("click"+s,i.icon,m.event.click)}},remove:{events:function(){m.verbose("Removing events"),d.off(s)},initialLoad:function(){e=!1}},enable:function(){m.debug("Setting rating to interactive mode"),m.bind.events(),d.removeClass(o.disabled)},disable:function(){m.debug("Setting rating to read-only mode"),m.remove.events(),d.addClass(o.disabled)},is:{initialLoad:function(){return e},disabled:function(){return d.hasClass(o.disabled)}},get:{icon:function(){var e=d.data(t.icon);return e&&d.removeData(t.icon),e||a.icon},initialRating:function(){return d.data(t.rating)!==T?(d.removeData(t.rating),d.data(t.rating)):a.initialRating},maxRating:function(){return d.data(t.maxRating)!==T?(d.removeData(t.maxRating),d.data(t.maxRating)):a.maxRating},rating:function(){var e=g.filter("."+o.active).length;return m.verbose("Current rating retrieved",e),e}},set:{rating:function(e){var n=Math.floor(0<=e-1?e-1:0),n=g.eq(n),t=e<=1?n:n.next(),i=e%1*100;d.removeClass(o.selected),g.removeClass(o.selected).removeClass(o.active).removeClass(o.partiallyActive),0<e&&(m.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(r.filledCustomPropName,i+"%"),"transparent"===t.css("backgroundColor")&&t.removeClass(o.partiallyActive).removeClass(o.active))),m.is.initialLoad()||a.onRate.call(c,e)},initialLoad:function(){e=!0}},setting:function(e,n){if(m.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,m,e);else{if(n===T)return m[e];m[e]=n}},debug:function(){!a.silent&&a.debug&&(a.performance?m.performance.log(arguments):(m.debug=Function.prototype.bind.call(console.info,console,a.name+":"),m.debug.apply(console,arguments)))},verbose:function(){!a.silent&&a.verbose&&a.debug&&(a.performance?m.performance.log(arguments):(m.verbose=Function.prototype.bind.call(console.info,console,a.name+":"),m.verbose.apply(console,arguments)))},error:function(){a.silent||(m.error=Function.prototype.bind.call(console.error,console,a.name+":"),m.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:c,"Execution Time":t})),clearTimeout(m.performance.timer),m.performance.timer=setTimeout(m.performance.display,500)},display:function(){var e=a.name+":",t=0;h=!1,clearTimeout(m.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=u;return e=e||R,n=n||c,"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?(u===T&&m.initialize(),m.invoke(C)):(u!==T&&u.invoke("destroy"),m.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:{deQuote:function(e,n){return String(e).replace(/"/g,n?""":"")},icon:function(e,n){for(var t=1,i="",a=A.fn.rating.settings.templates.deQuote;t<=e;)i+='<i class="'+a(n)+' icon"></i>',t++;return i}}}}(jQuery,window,void document); |