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-02-23 21:46:34 +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,p,i=P.isPlainObject(R)?P.extend(!0,{},P.fn.api.settings,R):P.extend({},P.fn.api.settings),t=i.namespace,o=i.metadata,m=i.selector,a=i.error,b=i.className,v="."+t,h="module-"+t,u=P(this),y=u.closest(m.form),c=i.stateContext?P(i.stateContext):u,d=this,l=c[0],f=u.data(h),g={initialize:function(){T||g.bind.events(),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),f=g,u.data(h,f)},destroy:function(){g.verbose("Destroying previous module for",d),u.removeData(h).off(v)},bind:{events:function(){var e=g.get.event();e?(g.verbose("Attaching API events to element",e),u.on(e+v,g.event.trigger)):"now"==i.on&&(g.debug("Querying API endpoint immediately"),g.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),g.debug("Using cached response",e,t),g.decode.json(t);g.error(a.noStorage)}},write:{cachedResponse:function(e,t){t&&""===t?g.debug("Response empty, not caching",t):j.Storage!==O?(P.isPlainObject(t)&&(t=JSON.stringify(t)),sessionStorage.setItem(e,t),g.verbose("Storing cached response for url",e,t)):g.error(a.noStorage)}},query:function(){if(g.is.disabled())g.debug("Element is disabled API request aborted");else{if(g.is.loading()){if(!i.interruptRequests)return void g.debug("Cancelling request, previous request is still pending");g.debug("Interrupting previous request"),g.abort()}if(i.defaultData&&P.extend(!0,i.urlData,g.get.defaultData()),i.serializeForm&&(i.data=g.add.formData(i.data)),!1===(n=g.get.settings()))return g.cancelled=!0,void g.error(a.beforeSend);if(g.cancelled=!1,(r=g.get.templatedURL())||g.is.mocked()){if((r=g.add.urlData(r))||g.is.mocked()){if(n.url=i.base+r,s=P.extend(!0,{},i,{type:i.method||i.type,data:e,url:i.base+r,beforeSend:i.beforeXHR,success:function(){},failure:function(){},complete:function(){}}),g.debug("Querying URL",s.url),g.verbose("Using AJAX settings",s),"local"===i.cache&&g.read.cachedResponse(r))return g.debug("Response returned from local cache"),g.request=g.create.request(),void g.request.resolveWith(l,[g.read.cachedResponse(r)]);i.throttle?i.throttleFirstRequest||g.timer?(g.debug("Throttling request",i.throttle),clearTimeout(g.timer),g.timer=setTimeout(function(){g.timer&&delete g.timer,g.debug("Sending throttled request",e,s.method),g.send.request()},i.throttle)):(g.debug("Sending request",e,s.method),g.send.request(),g.timer=setTimeout(function(){},i.throttle)):(g.debug("Sending request",e,s.method),g.send.request())}}else g.error(a.missingURL)}},should:{removeError:function(){return!0===i.hideError||"auto"===i.hideError&&!g.is.form()}},is:{disabled:function(){return 0<u.filter(m.disabled).length},expectingJSON:function(){return"json"===i.dataType||"jsonp"===i.dataType},form:function(){return u.is("form")||c.is("form")},mocked:function(){return i.mockResponse||i.mockResponseAsync||i.response||i.responseAsync},input:function(){return u.is("input")},loading:function(){return!!g.request&&"pending"==g.request.state()},abortedRequest:function(e){return e&&e.readyState!==O&&0===e.readyState?(g.verbose("XHR request determined to be aborted"),!0):(g.verbose("XHR request was not aborted"),!1)},validResponse:function(e){return g.is.expectingJSON()&&P.isFunction(i.successTest)?(g.debug("Checking JSON returned success",i.successTest,e),i.successTest(e)?(g.debug("Response passed success test",e),!0):(g.debug("Response failed success test",e),!1)):(g.verbose("Response is not JSON, skipping validation",i.successTest,e),!0)}},was:{cancelled:function(){return g.cancelled||!1},succesful:function(){return g.verbose('This behavior will be deleted