Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ajax.js « plugins « droplab « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf30c3b403dfcb600bfbaecb7ae6568da0b35859 (plain)
1
!function(n){function e(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return n[a].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var t={};e.m=n,e.c=t,e.i=function(n){return n},e.d=function(n,t,a){e.o(n,t)||Object.defineProperty(n,t,{configurable:!1,enumerable:!0,get:a})},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},e.p="",e(e.s=10)}({10:function(module,exports,__webpack_require__){"use strict";eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true\n});\nfunction droplabAjaxException(message) {\n  this.message = message;\n}\n\nvar droplabAjax = {\n  _loadUrlData: function _loadUrlData(url) {\n    var self = this;\n    return new Promise(function (resolve, reject) {\n      var xhr = new XMLHttpRequest();\n      xhr.open('GET', url, true);\n      xhr.onreadystatechange = function () {\n        if (xhr.readyState === XMLHttpRequest.DONE) {\n          if (xhr.status === 200) {\n            var data = JSON.parse(xhr.responseText);\n            self.cache[url] = data;\n            return resolve(data);\n          } else {\n            return reject([xhr.responseText, xhr.status]);\n          }\n        }\n      };\n      xhr.send();\n    });\n  },\n  _loadData: function _loadData(data, config, self) {\n    if (config.loadingTemplate) {\n      var dataLoadingTemplate = self.hook.list.list.querySelector('[data-loading-template]');\n      if (dataLoadingTemplate) {\n        dataLoadingTemplate.outerHTML = self.listTemplate;\n      }\n    }\n    self.hook.list[config.method].call(self.hook.list, data);\n  },\n  init: function init(hook) {\n    var self = this;\n    self.cache = self.cache || {};\n    var config = hook.config.droplabAjax;\n    this.hook = hook;\n    if (!config || !config.endpoint || !config.method) {\n      return;\n    }\n    if (config.method !== 'setData' && config.method !== 'addData') {\n      return;\n    }\n    if (config.loadingTemplate) {\n      var dynamicList = hook.list.list.querySelector('[data-dynamic]');\n      var loadingTemplate = document.createElement('div');\n      loadingTemplate.innerHTML = config.loadingTemplate;\n      loadingTemplate.setAttribute('data-loading-template', '');\n      this.listTemplate = dynamicList.outerHTML;\n      dynamicList.outerHTML = loadingTemplate.outerHTML;\n    }\n    if (self.cache[config.endpoint]) {\n      self._loadData(self.cache[config.endpoint], config, self);\n    } else {\n      this._loadUrlData(config.endpoint).then(function (d) {\n        self._loadData(d, config, self);\n      }).catch(function (e) {\n        throw new droplabAjaxException(e.message || e);\n      });\n    }\n  },\n  destroy: function destroy() {\n    var dynamicList = this.hook.list.list.querySelector('[data-dynamic]');\n    if (this.listTemplate && dynamicList) {\n      dynamicList.outerHTML = this.listTemplate;\n    }\n  }\n};\n\nwindow.droplabAjax = droplabAjax;\n\nexports.default = droplabAjax;\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/plugins/ajax.js\n// module id = 10\n// module chunks = 3\n\n//# sourceURL=webpack:///./src/plugins/ajax.js?")}});