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