wishthis/node_modules/fomantic-ui/dist/components/rating.min.js
2023-08-17 11:47:40 +02:00

11 lines
No EOL
6 KiB
JavaScript

/*
* # Fomantic UI - 2.9.2
* https://github.com/fomantic/Fomantic-UI
* https://fomantic-ui.com/
*
* Copyright 2023 Contributors
* Released under the MIT license
* https://opensource.org/licenses/MIT
*
*/
!function(T,e){"use strict";e=void 0!==e&&e.Math===Math?e:globalThis,T.fn.rating=function(f){var p,b=T(this),h=b.selector||"",y=Date.now(),C=[],x=f,R="string"==typeof x,A=[].slice.call(arguments,1);return b.each(function(){var e,a=T.isPlainObject(f)?T.extend(!0,{},T.fn.rating.settings,f):T.extend({},T.fn.rating.settings),n=a.namespace,o=a.className,l=a.error,t=a.metadata,i=a.selector,r=a.cssVars,s="."+n,c="module-"+n,d=this,u=T(this).data(c),g=T(this),v=g.find(i.icon),m={initialize:function(){m.verbose("Initializing rating module",a),0===v.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,g.data(c,m)},destroy:function(){m.verbose("Destroying previous instance",u),m.remove.events(),g.removeData(c)},refresh:function(){v=g.find(i.icon)},setup:{layout:function(){var e=m.get.maxRating(),n=m.get.icon(),e=T.fn.rating.settings.templates.icon(e,n);m.debug("Generating icon html dynamically"),g.html(e),m.refresh()}},event:{mouseenter:function(){var e=T(this);e.nextAll().removeClass(o.selected),g.addClass(o.selected),e.addClass(o.selected).prevAll().addClass(o.selected)},mouseleave:function(){g.removeClass(o.selected),v.removeClass(o.selected)},click:function(){var e=T(this),n=m.get.rating(),e=v.index(e)+1;("auto"===a.clearable?1===v.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"),g.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"),g.off(s)},initialLoad:function(){e=!1}},enable:function(){m.debug("Setting rating to interactive mode"),m.bind.events(),g.removeClass(o.disabled)},disable:function(){m.debug("Setting rating to read-only mode"),m.remove.events(),g.addClass(o.disabled)},is:{initialLoad:function(){return e},disabled:function(){return g.hasClass(o.disabled)}},get:{icon:function(){var e=g.data(t.icon);return e&&g.removeData(t.icon),e||a.icon},initialRating:function(){return void 0!==g.data(t.rating)?(g.removeData(t.rating),g.data(t.rating)):a.initialRating},maxRating:function(){return void 0!==g.data(t.maxRating)?(g.removeData(t.maxRating),g.data(t.maxRating)):a.maxRating},rating:function(){var e=v.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=v.eq(n),t=e<=1?n:n.next(),i=e%1*100;g.removeClass(o.selected),v.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(d,e)},initialLoad:function(){e=!0}},setting:function(e,n){if(m.debug("Changing setting",e,n),T.isPlainObject(e))T.extend(!0,a,e);else{if(void 0===n)return a[e];T.isPlainObject(a[e])?T.extend(!0,a[e],n):a[e]=n}},internal:function(e,n){if(T.isPlainObject(e))T.extend(!0,m,e);else{if(void 0===n)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=Date.now())-(y||n),y=n,C.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:d,"Execution Time":t})),clearTimeout(m.performance.timer),m.performance.timer=setTimeout(m.performance.display,500)},display:function(){var e=a.name+":",t=0;y=!1,clearTimeout(m.performance.timer),T.each(C,function(e,n){t+=n["Execution Time"]}),e+=" "+t+"ms",h&&(e+=" '"+h+"'"),1<b.length&&(e+=" ("+b.length+")"),0<C.length&&(console.groupCollapsed(e),console.table?console.table(C):T.each(C,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),C=[]}},invoke:function(i,e,n){var a,o,t,r,s=u;return e=e||A,n=n||d,"string"==typeof i&&void 0!==s&&(i=i.split(/[ .]/),a=i.length-1,T.each(i,function(e,n){var t=e!==a?n+i[e+1].charAt(0).toUpperCase()+i[e+1].slice(1):i;if(T.isPlainObject(s[t])&&e!==a)s=s[t];else{if(void 0!==s[t])return o=s[t],!1;{if(!T.isPlainObject(s[n])||e===a)return void 0!==s[n]?o=s[n]:m.error(l.method,i),!1;s=s[n]}}})),"function"==typeof(r=o)&&"number"!=typeof r.nodeType?t=o.apply(n,e):void 0!==o&&(t=o),Array.isArray(p)?p.push(t):void 0!==p?p=[p,t]:void 0!==t&&(p=t),o}};R?(void 0===u&&m.initialize(),m.invoke(x)):(void 0!==u&&u.invoke("destroy"),m.initialize())}),void 0!==p?p:this},T.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"},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?"&quot;":"")},icon:function(e,n){for(var t=1,i="",a=T.fn.rating.settings.templates.deQuote;t<=e;)i+='<i class="'+a(n)+' icon"></i>',t++;return i}}}}(jQuery,window,document);