wishthis/node_modules/fomantic-ui/dist/components/nag.min.js

11 lines
No EOL
6.9 KiB
JavaScript

/*
* # Fomantic UI - 2.9.3
* https://github.com/fomantic/Fomantic-UI
* https://fomantic-ui.com/
*
* Copyright 2023 Contributors
* Released under the MIT license
* https://opensource.org/licenses/MIT
*
*/
!function(w,S,D){"use strict";S=void 0!==S&&S.Math===Math?S:globalThis,w.fn.nag=function(g){var p,e=w(this),m=w("body"),f=Date.now(),h=[],v=g,b="string"==typeof v,y=[].slice.call(arguments,1),x=function(e,n){var o;return 0<=[S,D].indexOf(e)?o=w(e):0===(o=w(n.document).find(e)).length&&(o=n.frameElement?x(e,n.parent):m),o};return e.each(function(){var t,i=w.isPlainObject(g)?w.extend(!0,{},w.fn.nag.settings,g):w.extend({},w.fn.nag.settings),e=i.selector,c=i.error,n=i.namespace,o="."+n,a=n+"-module",r=w(this),s=i.context?x(i.context,S):m,l=this,d=r.data(a),u={initialize:function(){u.verbose("Initializing element"),"string"!=typeof i.value&&(i.value=JSON.stringify(i.value)),t=u.get.storage(),r.on("click"+o,e.close,u.dismiss).data(a,u),i.detachable&&r.parent()[0]!==s[0]&&r.detach().prependTo(s),0<i.displayTime&&setTimeout(function(){u.hide()},i.displayTime),u.show()},destroy:function(){u.verbose("Destroying instance"),r.removeData(a).off(o)},show:function(){if(u.should.show()&&!r.is(":visible")){if(!1===i.onShow.call(l))return u.debug("onShow callback returned false, cancelling nag animation"),!1;u.debug("Showing nag",i.animation.show),"fade"===i.animation.show?r.fadeIn(i.duration,i.easing,i.onVisible):r.slideDown(i.duration,i.easing,i.onVisible)}},hide:function(){if(!1===i.onHide.call(l))return u.debug("onHide callback returned false, cancelling nag animation"),!1;u.debug("Hiding nag",i.animation.hide),"fade"===i.animation.hide?r.fadeOut(i.duration,i.easing,i.onHidden):r.slideUp(i.duration,i.easing,i.onHidden)},dismiss:function(e){!1!==u.hide()&&i.storageMethod&&(u.debug("Dismissing nag",i.storageMethod,i.key,i.value,i.expires),u.storage.set(i.key,i.value)),e.stopImmediatePropagation(),e.preventDefault()},should:{show:function(){return i.persist?(u.debug("Persistent nag is set, can show nag"),!0):u.storage.get(i.key)!=i.value.toString()?(u.debug("Stored value is not set, can show nag",u.storage.get(i.key)),!0):(u.debug("Stored value is set, cannot show nag",u.storage.get(i.key)),!1)}},get:{expirationDate:function(e){if((e="number"==typeof e?new Date(Date.now()+864e5*e):e)instanceof Date&&e.getTime())return e.toUTCString();u.error(c.expiresFormat)},storage:function(){return"localstorage"===i.storageMethod&&void 0!==S.localStorage?(u.debug("Using local storage"),S.localStorage):"sessionstorage"===i.storageMethod&&void 0!==S.sessionStorage?(u.debug("Using session storage"),S.sessionStorage):"cookie"in D?(u.debug("Using cookie"),{setItem:function(e,n,o){e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),n=encodeURIComponent(n).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[B-D])/g,decodeURIComponent);var t,i="";for(t in o)Object.prototype.hasOwnProperty.call(o,t)&&(i+="; "+t,"string"==typeof o[t]&&(i+="="+o[t].split(";")[0]));D.cookie=e+"="+n+i},getItem:function(e){for(var n=D.cookie.split("; "),o=0,t=n.length;o<t;o++){var i=n[o].split("=");if(e===i[0].replace(/(%[\da-f]{2})+/gi,decodeURIComponent))return i[1]||""}},removeItem:function(e,n){t.setItem(e,"",n)}}):void u.error(c.noStorage)},storageOptions:function(){var e={};return i.expires&&(e.expires=u.get.expirationDate(i.expires)),i.domain&&(e.domain=i.domain),i.path&&(e.path=i.path),i.secure&&(e.secure=i.secure),i.samesite&&(e.samesite=i.samesite),e}},clear:function(){u.storage.remove(i.key)},storage:{set:function(e,n){var o=u.get.storageOptions();t===S.localStorage&&o.expires&&(u.debug("Storing expiration value in localStorage",e,o.expires),t.setItem(e+i.expirationKey,o.expires)),u.debug("Value stored",e,n);try{t.setItem(e,n,o)}catch(e){u.error(c.setItem,e)}},get:function(e){var n,o=t.getItem(e);return t===S.localStorage&&null!=(n=t.getItem(e+i.expirationKey))&&new Date(n)<new Date&&(u.debug("Value in localStorage has expired. Deleting key",e),u.storage.remove(e),o=null),o="undefined"!==o&&"null"!==o&&null!=o?o:void 0},remove:function(e){var n=u.get.storageOptions();n.expires=u.get.expirationDate(-1),t===S.localStorage&&t.removeItem(e+i.expirationKey),t.removeItem(e,n)}},setting:function(e,n){if(u.debug("Changing setting",e,n),w.isPlainObject(e))w.extend(!0,i,e);else{if(void 0===n)return i[e];w.isPlainObject(i[e])?w.extend(!0,i[e],n):i[e]=n}},internal:function(e,n){if(w.isPlainObject(e))w.extend(!0,u,e);else{if(void 0===n)return u[e];u[e]=n}},debug:function(){!i.silent&&i.debug&&(i.performance?u.performance.log(arguments):(u.debug=Function.prototype.bind.call(console.info,console,i.name+":"),u.debug.apply(console,arguments)))},verbose:function(){!i.silent&&i.verbose&&i.debug&&(i.performance?u.performance.log(arguments):(u.verbose=Function.prototype.bind.call(console.info,console,i.name+":"),u.verbose.apply(console,arguments)))},error:function(){i.silent||(u.error=Function.prototype.bind.call(console.error,console,i.name+":"),u.error.apply(console,arguments))},performance:{log:function(e){var n,o;i.performance&&(o=(n=Date.now())-(f||n),f=n,h.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:l,"Execution Time":o})),clearTimeout(u.performance.timer),u.performance.timer=setTimeout(function(){u.performance.display()},500)},display:function(){var e=i.name+":",o=0;f=!1,clearTimeout(u.performance.timer),w.each(h,function(e,n){o+=n["Execution Time"]}),e+=" "+o+"ms",0<h.length&&(console.groupCollapsed(e),console.table?console.table(h):w.each(h,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),h=[]}},invoke:function(t,e,n){var i,a,o,r,s=d;return e=e||y,n=n||l,"string"==typeof t&&void 0!==s&&(t=t.split(/[ .]/),i=t.length-1,w.each(t,function(e,n){var o=e!==i?n+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(w.isPlainObject(s[o])&&e!==i)s=s[o];else{if(void 0!==s[o])return a=s[o],!1;{if(!w.isPlainObject(s[n])||e===i)return void 0!==s[n]?a=s[n]:u.error(c.method,t),!1;s=s[n]}}})),"function"==typeof(r=a)&&"number"!=typeof r.nodeType?o=a.apply(n,e):void 0!==a&&(o=a),Array.isArray(p)?p.push(o):void 0!==p?p=[p,o]:void 0!==o&&(p=o),a}};b?(void 0===d&&u.initialize(),u.invoke(v)):(void 0!==d&&d.invoke("destroy"),u.initialize())}),void 0!==p?p:this},w.fn.nag.settings={name:"Nag",silent:!1,debug:!1,verbose:!1,performance:!0,namespace:"Nag",persist:!1,displayTime:0,animation:{show:"slide",hide:"slide"},context:!1,detachable:!1,expires:30,domain:!1,path:"/",secure:!1,samesite:!1,storageMethod:"cookie",key:"nag",value:"dismiss",expirationKey:"ExpirationDate",error:{noStorage:"Unsupported storage method",method:"The method you called is not defined.",setItem:"Unexpected error while setting value",expiresFormat:'"expires" must be a number of days or a Date Object'},className:{bottom:"bottom",fixed:"fixed"},selector:{close:"> .close.icon"},duration:500,easing:"easeOutQuad",onShow:function(){},onVisible:function(){},onHide:function(){},onHidden:function(){}},w.extend(w.easing,{easeOutQuad:function(e){return 1-(1-e)*(1-e)}})}(jQuery,window,document);