{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./build/scripts/shared.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","default","object","property","prototype","hasOwnProperty","p","s","./build/scripts/shared.js","e","window","qanda","shared","_request","method","url","options","callback","body","headers","onSuccess","onFail","httpRequest","XMLHttpRequest","console","log","onreadystatechange","readyState","DONE","response","JSON","parse","responseText","success","error","open","setRequestHeader","header","stringify","send","blockerListener","preventDefault","_authRequest","refresh","Authorization","localStorage","getItem","status","setItem","token","id","clear","location","replace","_blockedRequest","requestFn","buttonEl","originalListener","classList","add","removeEventListener","addEventListener","setTimeout","remove","request","blockedRequest","authRequest","blockedAuthRequest","getUrlParam","results","RegExp","exec","search","decodeURIComponent"],"mappings":"aACA,IAAAA,KAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,IACAG,EAAAH,EACAI,KACAH,YAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,KAGAF,EAAAD,QAKAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,GAA0CK,cAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAAb,EAAAiB,OAAAC,aAAwDC,MAAA,WAExDP,OAAAC,eAAAb,EAAA,cAAiDmB,YAQjDrB,EAAAsB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAArB,EAAAqB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,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AUK,OAAO,YACxB,QAWL,OACCC,QAASnD,EACToD,eAzE+B,SAAST,EAAUC,EAAkB3C,EAAQC,EAAKC,EAASC,GAC1FqC,EAAgBzC,EAAU2C,EAAUC,EAAkB3C,EAAQC,EAAKC,EAASC,IAyE5EiD,YAAaxB,EACbyB,mBAhC2B,SAASX,EAAUC,EAAkB3C,EAAQC,EAAKC,EAASC,GACtFqC,EAAgBZ,EAAcc,EAAUC,EAAkB3C,EAAQC,EAAKC,EAASC,IAgChFmD,YAZoB,SAACtF,GACrBA,EAAOA,EAAKuE,QAAQ,OAAQ,OAAOA,QAAQ,OAAQ,OACnD,IACIgB,EADQ,IAAIC,OAAO,SAAWxF,EAAO,aACrByF,KAAKnB,SAASoB,QAClC,OAAmB,OAAZH,EAAmB,GAAKI,mBAAmBJ,EAAQ,GAAGhB,QAAQ,MAAO,QAjHvD","file":"dist/shared.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./build/scripts/shared.js\");\n","window.qanda = (window.qanda || {});\n\nwindow.qanda.shared = (function() {\n\tconst _request = function(method, url, options, callback) {\n\t\toptions = (options || {});\n\t\toptions = {\n\t\t\tbody: (options.body || null),\n\t\t\theaders: (options.headers || null),\n\t\t\tonSuccess: (options.onSuccess || null),\n\t\t\tonFail: (options.onFail || null),\n\t\t};\n\n\t\tconst httpRequest = new XMLHttpRequest();\n\t\tif (!httpRequest) {\n\t\t\tconsole.log('Giving up. Cannot create an XMLHTTP instance.');\n\t\t\treturn false;\n\t\t}\n\n\t\thttpRequest.onreadystatechange = function() {\n\t\t\tif (httpRequest.readyState === XMLHttpRequest.DONE) {\n\t\t\t\tif (callback) callback(httpRequest);\n\n\t\t\t\tif (options.onSuccess || options.onFail) {\n\t\t\t\t\tconst response = JSON.parse(httpRequest.responseText);\n\t\t\t\t\tif (options.onSuccess && response.success) options.onSuccess(response);\n\t\t\t\t\tif (options.onFail && !response.success) options.onFail(response.error);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\thttpRequest.open(method, url);\n\t\thttpRequest.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');\n\n\t\tif (options.headers) {\n\t\t\tfor (header in options.headers) {\n\t\t\t\thttpRequest.setRequestHeader(header, options.headers[header]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tbody = (options.body ? JSON.stringify(options.body) : null);\n\t\thttpRequest.send(body);\n\t};\n\n\tconst blockerListener = function(e) {\n\t\te.preventDefault();\n\t};\n\n\tconst _blockedStandardRequest = function(buttonEl, originalListener, method, url, options, callback) {\n\t\t_blockedRequest(_request, buttonEl, originalListener, method, url, options, callback);\n\t};\n\n\tconst _authRequest = function(method, url, options, callback, refresh) {\n\t\toptions = (options || {});\n\t\toptions.headers = (options.headers || {});\n\t\toptions.headers['Authorization'] = ('Bearer ' + window.localStorage.getItem('token'));\n\t\trefresh = (refresh === false ? false : true);\n\n\t\t_request(method, url, options, function(httpRequest) {\n\t\t\tif (httpRequest.status === 401) {\n\t\t\t\t// Token expired. Refresh.\n\t\t\t\tconsole.log('Token expired');\n\n\t\t\t\tif (refresh) {\n\t\t\t\t\tconsole.log('Refreshing token');\n\t\t\t\t\n\t\t\t\t\t_authRequest('PUT', 'https://iaq3hhok0d.execute-api.us-west-2.amazonaws.com/prod/tokens', null, function(httpRequest) {\n\t\t\t\t\t\tif (httpRequest.status === 200) {\n\t\t\t\t\t\t\tvar response = JSON.parse(httpRequest.responseText);\n\t\t\t\t\t\t\twindow.localStorage.setItem('token', response.token.id);\n\n\t\t\t\t\t\t\t// Retry request.\n\t\t\t\t\t\t\tconsole.log('Retrying request');\n\t\t\t\t\t\t\t_authRequest(method, url, options, callback, false);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconsole.log('Error occurred during token refresh', httpRequest);\n\t\t\t\t\t\t\twindow.localStorage.clear();\n\t\t\t\t\t\t\twindow.location.replace('/');\n\t\t\t\t\t\t}\n\t\t\t\t\t}, false);\n\t\t\t\t} else {\n\t\t\t\t\tconsole.log('Unable to refresh token', httpRequest);\n\t\t\t\t\twindow.localStorage.clear();\n\t\t\t\t\twindow.location.replace('/');\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (callback) callback(httpRequest);\n\t\t\t}\n\t\t});\n\t};\n\n\tconst _blockedAuthRequest = function(buttonEl, originalListener, method, url, options, callback) {\n\t\t_blockedRequest(_authRequest, buttonEl, originalListener, method, url, options, callback);\n\t};\n\n\tconst _blockedRequest = function(requestFn, buttonEl, originalListener, method, url, options, callback) {\n\t\tbuttonEl.classList.add('loading');\n\t\tbuttonEl.removeEventListener('click', originalListener);\n\t\tbuttonEl.addEventListener('click', blockerListener);\n\t\t\n\t\trequestFn(method, url, options, function(httpRequest) {\n\t\t\tif (callback) callback(httpRequest);\n\t\t\t\n\t\t\tbuttonEl.addEventListener('click', originalListener);\n\t\t\tbuttonEl.removeEventListener('click', blockerListener);\n\t\t\t\n\t\t\tsetTimeout(function() {\n\t\t\t\tbuttonEl.classList.remove('loading');\n\t\t\t}, 1000);\n\t\t});\n\t};\n\n\tconst _getUrlParam = (name) => {\n\t\tname = name.replace(/[\\[]/, '\\\\[').replace(/[\\]]/, '\\\\]');\n\t\tvar regex = new RegExp('[\\\\?&]' + name + '=([^&#]*)');\n\t\tvar results = regex.exec(location.search);\n\t\treturn results === null ? '' : decodeURIComponent(results[1].replace(/\\+/g, ' '));\n\t};\n\n\treturn {\n\t\trequest: _request,\n\t\tblockedRequest: _blockedStandardRequest,\n\t\tauthRequest: _authRequest,\n\t\tblockedAuthRequest: _blockedAuthRequest,\n\t\tgetUrlParam: _getUrlParam,\n\t};\n})();"],"sourceRoot":""}