Skip to content

Commit 7955d0c

Browse files
hm
1 parent f25297e commit 7955d0c

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

examples/buttons/index.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,9 @@ <h2 id="twoLineWidgetForClass"><a href="#twoLineWidgetForClass">twoLineWidgetFor
333333
<h2 id="isAudio"><a href="#isAudio">isAudio</a></h2>
334334
<script id="script-isAudio">
335335
window.addEventListener('DOMContentLoaded', (event) => {
336-
// const result = UI.widgets.isAudio()
337-
// $('#div-isAudio').appendChild(document.createTextNode(result))
336+
UI.store.add(UI.rdf.namedNode('http://example.com/audio.mpeg'), UI.ns.rdf('type'), UI.rdf.namedNode('http://www.w3.org/ns/iana/media-types/audio'))
337+
const result = UI.widgets.isAudio(UI.rdf.namedNode('http://example.com/audio.mpeg'))
338+
$('#div-isAudio').appendChild(document.createTextNode(result))
338339
})
339340
</script>
340341
<pre id="viewSource-isAudio"></pre><script>$('#viewSource-isAudio').innerHTML = $('#script-isAudio').innerText</script>
@@ -343,8 +344,9 @@ <h2 id="isAudio"><a href="#isAudio">isAudio</a></h2>
343344
<h2 id="isImage"><a href="#isImage">isImage</a></h2>
344345
<script id="script-isImage">
345346
window.addEventListener('DOMContentLoaded', (event) => {
346-
// const result = UI.widgets.isImage()
347-
// $('#div-isImage').appendChild(document.createTextNode(result))
347+
UI.store.add(UI.rdf.namedNode('http://example.com/image.jpeg'), UI.ns.rdf('type'), UI.rdf.namedNode('http://www.w3.org/ns/iana/media-types/image'))
348+
const result = UI.widgets.isImage(UI.rdf.namedNode('http://example.com/image.jpeg'))
349+
$('#div-isImage').appendChild(document.createTextNode(result))
348350
})
349351
</script>
350352
<pre id="viewSource-isImage"></pre><script>$('#viewSource-isImage').innerHTML = $('#script-isImage').innerText</script>
@@ -353,8 +355,9 @@ <h2 id="isImage"><a href="#isImage">isImage</a></h2>
353355
<h2 id="isVideo"><a href="#isVideo">isVideo</a></h2>
354356
<script id="script-isVideo">
355357
window.addEventListener('DOMContentLoaded', (event) => {
356-
// const result = UI.widgets.isVideo()
357-
// $('#div-isVideo').appendChild(document.createTextNode(result))
358+
UI.store.add(UI.rdf.namedNode('http://example.com/video.mov'), UI.ns.rdf('type'), UI.rdf.namedNode('http://www.w3.org/ns/iana/media-types/video'))
359+
const result = UI.widgets.isImage(UI.rdf.namedNode('http://example.com/video.mov'))
360+
$('#div-isVideo').appendChild(document.createTextNode(result))
358361
})
359362
</script>
360363
<pre id="viewSource-isVideo"></pre><script>$('#viewSource-isVideo').innerHTML = $('#script-isVideo').innerText</script>

src/widgets/buttons.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,24 +1167,28 @@ function addStyleSheet (dom: HTMLDocument, href: string): void {
11671167

11681168
// Figure (or guess) whether this is an image, etc
11691169
//
1170-
function isAudio (file: string) {
1170+
function isAudio (file: NamedNode) {
11711171
return isImage(file, 'audio')
11721172
}
1173-
function isVideo (file: string) {
1173+
function isVideo (file: NamedNode) {
11741174
return isImage(file, 'video')
11751175
}
11761176
/**
11771177
*
11781178
*/
1179-
function isImage (file: string, kind: string): boolean {
1179+
function isImage (file: NamedNode, kind: string | undefined): boolean {
11801180
var dcCLasses = {
11811181
audio: 'http://purl.org/dc/dcmitype/Sound',
11821182
image: 'http://purl.org/dc/dcmitype/Image',
11831183
video: 'http://purl.org/dc/dcmitype/MovingImage'
11841184
}
11851185
var what = kind || 'image'
1186+
// See https://github.com/linkeddata/rdflib.js/blob/e367d5088c/src/formula.ts#L554
1187+
//
11861188
var typeURIs = UI.store.findTypeURIs(file)
1187-
var prefix = $rdf.Util.mediaTypeClass(what + '/*').uri.split('*')[0]
1189+
// See https://github.com/linkeddata/rdflib.js/blob/d5000f/src/utils-js.js#L14
1190+
// e.g.'http://www.w3.org/ns/iana/media-types/audio'
1191+
var prefix: string = $rdf.Util.mediaTypeClass(what + '/*').uri.split('*')[0]
11881192
for (var t in typeURIs) {
11891193
if (t.startsWith(prefix)) return true
11901194
}

0 commit comments

Comments
 (0)