mobinge
Version:
Client-heavy webcomic site display system
95 lines (83 loc) • 3.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
require("whatwg-fetch");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var PANLIB_DEFAULT_START = 1;
var PANLIB_DEFAULT_END = null;
var PANLIB_DEFAULT_RESOLUTION = "300px";
var PANLIB_DEFAULT_MANIFEST = "./manifest.json";
var PanelLibrarian = function () {
function PanelLibrarian(manifest, start, end) {
_classCallCheck(this, PanelLibrarian);
this.startAt(start === undefined ? PANLIB_DEFAULT_START : start).manifest(manifest === undefined ? PANLIB_DEFAULT_MANIFEST : manifest).endAt(end === undefined ? PANLIB_DEFAULT_END : end).panels = null;
}
_createClass(PanelLibrarian, [{
key: "startAt",
value: function startAt(start) {
if (start === undefined) {
return this.start;
}
this.start = start;
return this;
}
}, {
key: "endAt",
value: function endAt(end) {
if (end === undefined) {
return this.end;
}
this.end = end;
return this;
}
}, {
key: "manifest",
value: function manifest(_manifest) {
if (_manifest === undefined) {
return this.manifest;
}
this.manifest = _manifest;
this.getPanelData = fetch(_manifest);
return this;
}
}, {
key: "pickPanels",
value: function pickPanels(resolution) {
var _this = this;
return this.panelData.images.filter(function (panel) {
return panel.sequence >= _this.start && (_this.end === null || panel.sequence <= _this.end);
}).map(function (panel) {
return {
sequence: panel.sequence,
url: _this.panelData.path + panel.file[resolution]
};
});
}
}, {
key: "fetchPanels",
value: function fetchPanels(resolution) {
var _this2 = this;
resolution = resolution == undefined ? PANLIB_DEFAULT_RESOLUTION : resolution;
if (this.panels !== null) {
return new Promise(function () {
return _this2.pickPanels(resolution);
});
}
if (!this.getPanelData) {
throw {
'message': 'No manifest is set.'
};
}
return this.getPanelData.then(function (response) {
return response.json();
}).then(function (panelData) {
_this2.panelData = panelData;
return _this2.pickPanels(resolution);
});
}
}]);
return PanelLibrarian;
}();
exports.default = PanelLibrarian;