forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslideshowPane.js
More file actions
74 lines (62 loc) · 2.27 KB
/
Copy pathslideshowPane.js
File metadata and controls
74 lines (62 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* slideshow Pane
**
*/
const UI = require('solid-ui')
const ns = UI.ns
// tabulator.loadScript("js/panes/slideshow/better-simple-slideshow/js/better-simple-slideshow.js")
const makeBSS = require('@solid/better-simple-slideshow')
// load also js/panes/slideshow/better-simple-slideshow/css/simple-slideshow-styles.css
module.exports = {
icon: UI.icons.iconBase + 'noun_138712.svg',
name: 'slideshow',
audience: [ns.solid('PowerUser')],
// Does the subject deserve an slideshow pane?
label: function (subject, context) {
const kb = context.session.store
const ns = UI.ns
const t = kb.findTypeURIs(subject)
if (t[ns.ldp('Container').uri] || t[ns.ldp('BasicContainer').uri]) {
const contents = kb.each(subject, ns.ldp('contains'))
let 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 (subject, context) {
const dom = context.dom
const styleSheet =
'https://leemark.github.io/better-simple-slideshow/css/simple-slideshow-styles.css'
UI.widgets.addStyleSheet(dom, styleSheet)
const kb = context.session.store
const ns = UI.ns
const div = dom.createElement('div')
div.setAttribute('class', 'bss-slides')
const t = kb.findTypeURIs(subject)
let predicate
if (t[ns.ldp('BasicContainer').uri] || t[ns.ldp('Container').uri]) {
predicate = ns.ldp('contains')
}
const images = kb.each(subject, predicate) // @@ random order?
// @@ Ideally: sort by embedded time of image
images.sort() // Sort for now by URI
for (let i = 0; i < images.length; i++) {
if (!UI.widgets.isImage(images[i])) continue
const figure = div.appendChild(dom.createElement('figure'))
const img = figure.appendChild(dom.createElement('img'))
img.setAttribute('src', images[i].uri)
img.setAttribute('width', '100%')
figure.appendChild(dom.createElement('figcaption'))
}
const options = { dom: dom }
setTimeout(function () {
makeBSS('.bss-slides', options)
}, 1000) // Must run after the code which called this
return div
}
}
// ends