!function(e,t){"use strict";var i=function(e){if("object"!=typeof e.document)throw new Error("response-monitor.js requires a `window` with a `document` object");var t=function(t,i){var o=this;this.trigger=t,this.downloadTimer=null,this._validateTrigger(),this._validateURL(),"undefined"==typeof i&&(i=this._configDefaultSpinner(i));var n=function(){};this.options={timeout:120,onRequest:n,onMonitor:n,onTimeout:n,onResponse:n,cookiePrefix:"response-monitor"},"undefined"==typeof i.timeout&&"undefined"!=typeof this.hash&&(i.timeout=parseInt(this.hash.split("#")[1]));for(var r in i)this.options[r]=i[r];this.monitor=function(){var t=o._getCookie();if("undefined"!=typeof t)e.setTimeout(function(){o.options.onResponse(t)},0),o._terminate();else if(o.countdown<0)return o._terminate(),void e.setTimeout(o.options.onTimeout,0);o.options.onMonitor(o.countdown--)}};return t.prototype._configDefaultSpinner=function(e){var t=this;try{this.spinner=new Spinner}catch(i){var o=require("spin");this.spinner=new o}var n=function(e){t.spinner.stop(),0===e&&console.log("error")};return{onRequest:function(){t.spinner.spin(),"undefined"!=typeof t.trigger.nodeName?t.trigger.appendChild(t.spinner.el):document.body.appendChild(t.spinner.el)},onResponse:n,onTimeout:function(){n(),console.log("timeout")}}},t.prototype.execute=function(t){if(!this.downloadTimer){"undefined"!=typeof this.trigger.href&&(this.trigger.href="javascript:void(0);"),this.countdown=this.options.timeout,"undefined"!=typeof t&&t.preventDefault();var i=new Date,o=i.getTime();this.cookie={name:this.options.cookiePrefix+"_"+o,value:o},this._createIframe();var n=-1!==this.url.indexOf("?")?"&":"?",r=this.url+n+this.options.cookiePrefix+"="+o;"undefined"!=typeof this.form?this._submitForm(r):this.iframe.src=r,this.options.onRequest(this.cookie.name),this.monitor(),this.downloadTimer=e.setInterval(this.monitor,1e3)}},t.prototype._terminate=function(){"undefined"!=typeof this.trigger.href&&(this.trigger.href=this.url+this.hash),"undefined"!=typeof this.form&&"GET"==this.form.ACTION&&this.form.removeChild(this.hiddenInput),e.clearInterval(this.downloadTimer),this.downloadTimer=null,this._expireCookie(this.cookie.name),this._removeIframe()},t.prototype._getCookie=function(){var e=document.cookie.split(this.cookie.name+"=");return 2==e.length?e.pop().split(";").shift():void 0},t.prototype._expireCookie=function(e){document.cookie=encodeURIComponent(e)+"=deleted; expires="+new Date(0).toUTCString()},t.prototype._submitForm=function(e){this.form.target=this.iframe.name,"GET"==this.form.method.toUpperCase()&&null===document.getElementById(this.options.cookiePrefix)?(this.hiddenInput=document.createElement("input"),this.hiddenInput.type="hidden",this.hiddenInput.name=this.options.cookiePrefix,this.hiddenInput.value=this.cookie.value,this.form.appendChild(this.hiddenInput),this.form.submit()):(this.form.action=e,this.form.submit())},t.prototype._createIframe=function(){this.iframe=document.createElement("iframe"),this.iframe.id=this.options.cookiePrefix+"_iframe_"+this.cookie.value,this.iframe.name=this.iframe.id,this.iframe.style.display="none",document.body.appendChild(this.iframe)},t.prototype._removeIframe=function(){if(this.countdown<0)try{"Microsoft Internet Explorer"==navigator.appName?this.iframe.contentWindow.document.execCommand("Stop"):this.iframe.contentWindow.stop()}catch(e){}document.body.removeChild(this.iframe)},t.prototype._invalidTriggerError=function(){return new Error("Invalid request trigger: '"+this.trigger+"'\nValid request triggers are HTML anchors, forms and URLs as strings.")},t.prototype._validateTrigger=function(){var e=this;if("undefined"==typeof this.trigger||null===this.trigger)throw this._invalidTriggerError();if("undefined"!=typeof this.trigger.href&&"A"==this.trigger.nodeName)this.trigger.onclick=function(t){e.execute(t)},this.url=this.trigger.href;else if("undefined"!=typeof this.trigger.action&&"FORM"==this.trigger.nodeName)this.trigger.onsubmit=function(t){e.execute(t)},this.form=this.trigger,this.url=this.trigger.action;else{if("undefined"!=typeof this.trigger.nodeName)throw this._invalidTriggerError();this.url=this.trigger}},t.prototype._validateURL=function(){var e=document.createElement("a");return e.href=this.url,""!==e.hostname&&-1!==e.protocol.indexOf("http")?(this.url=e.href.replace(e.hash,""),this.hash=e.hash,!0):!1},t.register=function(e,i){var o;o="undefined"!=typeof e.nodeName?new Array(e):e;for(var n=0;n