wishthis/semantic/dist/components/api.min.js

11 lines
15 KiB
JavaScript
Raw Normal View History

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