forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaylistPane.js
More file actions
161 lines (137 loc) · 4.12 KB
/
playlistPane.js
File metadata and controls
161 lines (137 loc) · 4.12 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* Playlist Pane
**
** This pane allows playlists and playlists slots to be viewed
** seeAlso: http://smiy.sourceforge.net/pbo/spec/playbackontology.html
*/
const UI = require('solid-ui')
const $rdf = require('rdflib')
const ns = UI.ns
module.exports = {
icon: UI.icons.iconBase + 'noun_1619.svg',
name: 'playlistSlot',
audience: [ns.solid('PowerUser')],
label: function (subject, context) {
const kb = context.session.store
if (
!kb.anyStatementMatching(
subject,
UI.ns.rdf('type'),
kb.sym('http://purl.org/ontology/pbo/core#PlaylistSlot')
)
) {
return null
}
return 'playlist slot'
},
render: function (subject, context) {
const myDocument = context.dom
function isVideo (src, _index) {
if (!src) {
return {
html5: true
}
}
const youtube = src.match(
/\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-_%]+)/i
)
const vimeo = src.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i)
const dailymotion = src.match(/\/\/(?:www\.)?dai.ly\/([0-9a-z\-_]+)/i)
const vk = src.match(
/\/\/(?:www\.)?(?:vk\.com|vkontakte\.ru)\/(?:video_ext\.php\?)(.*)/i
)
if (youtube) {
return {
youtube: youtube
}
} else if (vimeo) {
return {
vimeo: vimeo
}
} else if (dailymotion) {
return {
dailymotion: dailymotion
}
} else if (vk) {
return {
vk: vk
}
}
}
const link = function (contents, uri) {
if (!uri) return contents
const a = myDocument.createElement('a')
a.setAttribute('href', uri)
a.appendChild(contents)
a.addEventListener('click', UI.widgets.openHrefInOutlineMode, true)
return a
}
const text = function (str) {
return myDocument.createTextNode(str)
}
const kb = context.session.store
const obj = kb.any(
subject,
$rdf.sym('http://purl.org/ontology/pbo/core#playlist_item')
)
let index = kb.any(
subject,
$rdf.sym('http://purl.org/ontology/olo/core#index')
)
let uri = obj.uri
const video = isVideo(uri)
const div = myDocument.createElement('div')
let img
if (video && video.youtube) {
uri = uri.replace('watch?v=', 'embed/')
div.setAttribute('class', 'imageView')
img = myDocument.createElement('IFRAME')
img.setAttribute('src', uri)
img.setAttribute('width', 560)
img.setAttribute('height', 315)
img.setAttribute('frameborder', 0)
img.setAttribute('style', 'max-width: 850px; max-height: 100%;')
img.setAttribute('allowfullscreen', 'true')
} else {
div.setAttribute('class', 'imageView')
img = myDocument.createElement('IMG')
img.setAttribute('src', obj.value)
img.setAttribute('width', 560)
img.setAttribute('height', 315)
img.setAttribute('style', 'max-width: 560; max-height: 315;')
}
let descDiv
if (index) {
const sl = kb.statementsMatching(
null,
$rdf.sym('http://purl.org/ontology/olo/core#index')
)
const slots = []
for (let i = 0; i < sl.length; i++) {
if (sl[i]) {
slots.push(parseInt(sl[i].object.value, 10))
}
}
index = parseInt(index.value, 10)
descDiv = myDocument.createElement('div')
const pIndex =
slots[(slots.indexOf(index) - 1 + slots.length) % slots.length]
const nIndex =
slots[(slots.indexOf(index) + 1 + slots.length) % slots.length]
const prev = link(text('<<'), subject.uri.split('#')[0] + '#' + pIndex)
descDiv.appendChild(prev)
const indexDiv = myDocument.createElement('span')
indexDiv.innerHTML = ' Playlist slot : ' + index + ' '
descDiv.appendChild(indexDiv)
const next = link(text('>>'), subject.uri.split('#')[0] + '#' + nIndex)
descDiv.appendChild(next)
}
const tr = myDocument.createElement('TR') // why need tr?
tr.appendChild(img)
if (descDiv) {
tr.appendChild(descDiv)
}
div.appendChild(tr)
return div
}
}
// ends