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

11 lines
16 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
* # Fomantic UI - 2.9.3
2022-01-13 13:00:31 +00:00
* https://github.com/fomantic/Fomantic-UI
2023-08-17 09:47:40 +00:00
* https://fomantic-ui.com/
2022-01-13 13:00:31 +00:00
*
2023-08-17 09:47:40 +00:00
* Copyright 2023 Contributors
2022-01-13 13:00:31 +00:00
* Released under the MIT license
2023-08-17 09:47:40 +00:00
* https://opensource.org/licenses/MIT
2022-01-13 13:00:31 +00:00
*
*/
!function(P,j,n){"use strict";function C(e){return null!==e&&e===e.window}function E(e){return"function"==typeof e&&"number"!=typeof e.nodeType}j=void 0!==j&&j.Math===Math?j:globalThis,P.fn.api=function(x){var A,e=E(this)?P(j):P(this),k=Date.now(),S=[],T=x,w="string"==typeof T,D=[].slice.call(arguments,1),O=function(e,t){var r;return 0<=[j,n].indexOf(e)?r=P(e):0===(r=P(t.document).find(e)).length&&(r=t.frameElement?O(e,t.parent):j),r};return e.each(function(){var a,n,r,e,i,o,s=P.isPlainObject(x)?P.extend(!0,{},P.fn.api.settings,x):P.extend({},P.fn.api.settings),f=s.regExp,t=s.namespace,u=s.metadata,c=s.selector,d=s.error,l=s.className,p="."+t,g="module-"+t,m=P(this),v=m.closest(c.form),b=s.stateContext?O(s.stateContext,j):m,h=this,y=b[0],R=m.data(g),q={initialize:function(){w||(o=s.data,q.bind.events()),q.instantiate()},instantiate:function(){q.verbose("Storing instance of module",q),R=q,m.data(g,R)},destroy:function(){q.verbose("Destroying previous module for",h),m.removeData(g).off(p)},bind:{events:function(){var e=q.get.event();e?(q.verbose("Attaching API events to element",e),m.on(e+p,q.event.trigger)):"now"===s.on&&(q.debug("Querying API endpoint immediately"),q.query())}},decode:{json:function(e){if(void 0!==e&&"string"==typeof e)try{e=JSON.parse(e)}catch(e){}return e}},read:{cachedResponse:function(e){var t;if(void 0!==j.Storage)return t=sessionStorage.getItem(e+q.get.normalizedData()),q.debug("Using cached response",e,s.data,t),q.decode.json(t);q.error(d.noStorage)}},write:{cachedResponse:function(e,t){void 0===j.Storage?q.error(d.noStorage):(P.isPlainObject(t)&&(t=JSON.stringify(t)),sessionStorage.setItem(e+q.get.normalizedData(),t),q.verbose("Storing cached response for url",e,s.data,t))}},query:function(){if(q.is.disabled())q.debug("Element is disabled API request aborted");else{if(q.is.loading()){if(!s.interruptRequests)return void q.debug("Cancelling request, previous request is still pending");q.debug("Interrupting previous request"),q.abort()}if(s.defaultData&&P.extend(!0,s.urlData,q.get.defaultData()),s.serializeForm&&(s.data=q.add.formData(o||s.data)),!1===(n=q.get.settings()))return q.cancelled=!0,void q.error(d.beforeSend);if(q.cancelled=!1,(r=q.get.templatedURL())||q.is.mocked()){if((r=q.add.urlData(r))||q.is.mocked()){if(n.url=s.base+r,a=P.extend(!0,{},s,{type:s.method||s.type,data:e,url:s.base+r,beforeSend:s.beforeXHR,success:function(){},failure:function(){},complete:function(){}}),q.debug("Querying URL",a.url),q.verbose("Using AJAX settings",a),"local"===s.cache&&q.read.cachedResponse(r))return q.debug("Response returned from local cache"),q.request=q.create.request(),void q.request.resolveWith(y,[q.read.cachedResponse(r)]);s.throttle?s.throttleFirstRequest||q.timer?(q.debug("Throttling request",s.throttle),clearTimeout(q.timer),q.timer=setTimeout(function(){q.timer&&delete q.timer,q.debug("Sending throttled request",e,a.method),q.send.request()},s.throttle)):(q.debug("Sending request",e,a.method),q.send.request(),q.timer=setTimeout(function(){},s.throttle)):(q.debug("Sending request",e,a.method),q.send.request())}}else q.error(d.missingURL)}},should:{removeError:function(){return!0===s.hideError||"auto"===s.hideError&&!q.is.form()}},is:{disabled:function(){return 0<m.filter(c.disabled).length},expectingJSON:function(){return"json"===s.dataType||"jsonp"===s.dataType},form:function(){return m.is("form")||b.is("form")},mocked:function(){return s.mockResponse||s.mockResponseAsync||s.response||s.responseAsync},input:function(){return m.is("input")},loading:function(){return!!q.request&&"pending"===q.request.state()},abortedRequest:function(e){return e&&void 0!==e.readyState&&0===e.readyState?(q.verbose("XHR request determined to be aborted"),!0):(q.verbose("XHR request was not aborted"),!1)},validResponse:function(e){return q.is.expectingJSON()&&E(s.successTest)?(q.debug("Checking JSON returned success",s.successTest,e),s.successTest(e)?(q.debug("Response passed success test",e),!0):(q.debug("Response failed success test",e),!1)):(q.verbose("Response is not JSON, skipping validation",s.successTest,e)