!function(e,t,r,n){"use strict";e.api=e.fn.api=function(r){varo,s=e(e.isFunction(this)?t:this),a=s.selector||"",i=(newDate).getTime(),u=[],c=arguments[0],d="string"==typeofc,l=[].slice.call(arguments,1);returns.each(function(){vars,g,f,p,m,b,v=e.isPlainObject(r)?e.extend(!0,{},e.fn.api.settings,r):e.extend({},e.fn.api.settings),h=v.namespace,y=v.metadata,q=v.selector,R=v.error,x=v.className,A="."+h,T="module-"+h,S=e(this),k=S.closest(q.form),j=v.stateContext?e(v.stateContext):S,P=this,w=j[0],D=S.data(T);b={initialize:function(){d||b.bind.events(),b.instantiate()},instantiate:function(){b.verbose("Storing instance of module",b),D=b,S.data(T,D)},destroy:function(){b.verbose("Destroying previous module for",P),S.removeData(T).off(A)},bind:{events:function(){vare=b.get.event();e?(b.verbose("Attaching API events to element",e),S.on(e+A,b.event.trigger)):"now"==v.on&&(b.debug("Querying API endpoint immediately"),b.query())}},decode:{json:function(e){if(e!==n&&"string"==typeofe)try{e=JSON.parse(e)}catch(t){}returne}},read:{cachedResponse:function(e){varr;returnt.Storage===n?voidb.error(R.noStorage):(r=sessionStorage.getItem(e),b.debug("Using cached response",e,r),r=b.decode.json(r),!1)}},write:{cachedResponse:function(r,o){returno&&""===o?voidb.debug("Response empty, not caching",o):t.Storage===n?voidb.error(R.noStorage):(e.isPlainObject(o)&&(o=JSON.stringify(o)),sessionStorage.setItem(r,o),voidb.verbose("Storing cached response for url",r,o))}},query:function(){if(b.is.disabled())returnvoidb.debug("Element is disabled API request aborted");if(b.is.loading()){if(!v.interruptRequests)returnvoidb.debug("Cancelling request, previous request is still pending");b.debug("Interrupting previous request"),b.abort()}returnv.defaultData&&e.extend(!0,v.urlData,b.get.defaultData()),v.serializeForm&&(v.data=b.add.formData(v.data)),g=b.get.settings(),g===!1?(b.cancelled=!0,voidb.error(R.beforeSend)):(b.cancelled=!1,f=b.get.templatedURL(),f||b.is.mocked()?(f=b.add.urlData(f),f||b.is.mocked()?(g.url=v.base+f,s=e.extend(!0,{},v,{type:v.method||v.type,data:p,url:v.base+f,beforeSend:v.beforeXHR,success:function(){},failure:function(){},complete:function(){}}),b.debug("Querying URL",s.url),b.verbose("Using AJAX settings",s),"local"===v.cache&&b.read.cachedResponse(f)?(b.debug("Response returned from local cache"),b.request=b.create.request(),voidb.request.resolveWith(w,[b.read.cachedResponse(f)])):void(v.throttle?v.throttleFirstRequest||b.timer?(b.debug("Throttling request",v.throttle),clearTimeout(b.timer),b.timer=setTimeout(function(){b.timer&&deleteb.timer,b.debug("Sending throttled request",p,s.method),b.send.request()},v.throttle)):(b.debug("Sending request",p,s.method),b.send.request(),b.timer=setTimeout(function(){},v.throttle)):(b.debug("Sending request",p,s.method),b.send.request()))):void0):voidb.error(R.missingURL))},should:{removeError:function(){returnv.hideError===!0||"auto"===v.hideError&&!b.is.form()}},is:{disabled:function(){returnS.filter(q.disabled).length>0},form:function(){returnS.is("form")||j.is("form")},mocked:function(){returnv.mockResponse||v.mockResponseAsync||v.response||v.responseAsync},input:function(){returnS.is("input")},loading:function(){returnb.request&&"pending"==b.request.state()},abortedRequest:function(e){returne&&e.readyState!==n&&0===e.readyState?(b.verbose("XHR request determined to be aborted"),!0):(b.verbose("XHR request was not aborted"),!1)},validResponse:function(t){return"json"!==v.dataType&&"jsonp"!==v.dataType||!e.isFunction(v.successTest)?(b.verbose("Response is not JSON, skipping validation",v.successTest,t),!0):(b.debug("Checking JSON returned success",v.successTest,t),v.successTest(t)?(b.debug("Response passed success test",t),!0):(b.debug("Response failed success test",t),!1))}},was:{cancelled:function(){returnb.cancelled||!1},succesful:function(){returnb.request&&"resolved"==b.request.state()},failure:function(){returnb.request&&"rejected"==b.request.state()},complete:function(){returnb.request&&("resolved"==b.request.state()||"rejected"==b.request.state())