solid-panes
Version:
Solid-compatible Panes: applets and views for the mashlib and databrowser
85 lines (80 loc) • 4 kB
JavaScript
;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.slideshowPane = void 0;
var UI = _interopRequireWildcard(require("solid-ui"));
var _betterSimpleSlideshow = _interopRequireDefault(require("@solid/better-simple-slideshow"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
/* slideshow Pane
**
*/
var ns = UI.ns;
var slideshowPane = exports.slideshowPane = {
icon: UI.icons.iconBase + 'noun_138712.svg',
name: 'slideshow',
audience: [ns.solid('PowerUser')],
// Does the subject deserve an slideshow pane?
label: function label(subject, context) {
var store = context.session.store;
var ns = UI.ns;
var t = store.findTypeURIs(subject);
if (t[ns.ldp('Container').uri] || t[ns.ldp('BasicContainer').uri]) {
var contents = store.each(subject, ns.ldp('contains'));
var count = 0;
contents.forEach(function (file) {
if (UI.widgets.isImage(file)) count++;
});
return count > 0 ? 'Slideshow' : null;
}
return null;
},
// See https://github.com/leemark/better-simple-slideshow
// and follow instructions there
render: function render(subject, context) {
var dom = context.dom;
var styleSheet = 'https://leemark.github.io/better-simple-slideshow/css/simple-slideshow-styles.css';
UI.widgets.addStyleSheet(dom, styleSheet);
var store = context.session.store;
var ns = UI.ns;
var div = dom.createElement('div');
div.setAttribute('class', 'bss-slides');
var t = store.findTypeURIs(subject);
var predicate;
if (t[ns.ldp('BasicContainer').uri] || t[ns.ldp('Container').uri]) {
predicate = ns.ldp('contains');
}
var images = store.each(subject, predicate); // @@ random order?
// @@ Ideally: sort by embedded time of image
images.sort(); // Sort for now by URI
var _loop = function _loop() {
if (!UI.widgets.isImage(images[i])) return 1; // continue
var figure = div.appendChild(dom.createElement('figure'));
var img = figure.appendChild(dom.createElement('img'));
// get image with authenticated fetch
store.fetcher._fetch(images[i].uri).then(function (response) {
return response.blob();
}).then(function (myBlob) {
var objectURL = URL.createObjectURL(myBlob);
img.setAttribute('src', objectURL); // w640 h480 //
});
img.setAttribute('width', '100%');
figure.appendChild(dom.createElement('figcaption'));
};
for (var i = 0; i < images.length; i++) {
if (_loop()) continue;
}
var options = {
dom: dom
};
setTimeout(function () {
(0, _betterSimpleSlideshow["default"])('.bss-slides', options);
}, 1000); // Must run after the code which called this
return div;
}
};
// ends
//# sourceMappingURL=slideshowPane.js.map