Skip to content

Commit 159ed34

Browse files
author
Tim Berners-Lee
committed
Add function to test for audio, video, image resources and remove cheating with file extensions
1 parent ef893a8 commit 159ed34

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

lib/acl-control.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,12 @@ UI.aclControl.ACLControlBox5 = function (subject, dom, noun, kb, callback) {
396396

397397
UI.acl.getACLorDefault(doc, function (ok, p2, targetDoc, targetACLDoc, defaultHolder, defaultACLDoc) {
398398
var defa = !p2
399-
box.isContainer = targetDoc.uri.slice(-1) === '/' // Give default for all directories
400399
// @@ Could also set from classes ldp:Container etc etc
401400
if (!ok) {
402401
statusBlock.textContent += 'Error reading ' + (defa ? ' default ' : '') + 'ACL.' +
403402
' status ' + targetDoc + ': ' + targetACLDoc
404403
} else {
404+
box.isContainer = targetDoc.uri.slice(-1) === '/' // Give default for all directories
405405
if (defa) {
406406
var defaults = kb.each(undefined, ACL('defaultForNew'), defaultHolder, defaultACLDoc)
407407
if (!defaults.length) {

lib/icons/noun_289243.svg

Lines changed: 1 addition & 0 deletions
Loading

lib/icons/noun_534313.svg

Lines changed: 1 addition & 0 deletions
Loading

lib/widgets.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,12 +2004,26 @@ UI.widgets.addStyleSheet = function(dom, href) {
20042004
dom.getElementsByTagName("head")[0].appendChild(link)
20052005
}
20062006

2007-
// Figure (or guess) whether this is an immage
2008-
// In future, containers may give content type information about contents too.
2007+
// Figure (or guess) whether this is an image, etc
20092008
//
2010-
UI.widgets.isImage = function(file){
2011-
var imageExtensions = {'jpg': 1, 'png':1, 'jpeg':1, 'gif':1}
2012-
return (UI.ns.dct('Image') in UI.store.findTypeURIs(file)
2013-
|| file.uri.split('.').slice(-1)[0].toLowerCase() in imageExtensions) // @@cheating
2009+
UI.widgets.isAudio = function(file){
2010+
return UI.widgets.isImage(file, 'audio')
2011+
}
2012+
UI.widgets.isVideo = function(file){
2013+
return UI.widgets.isImage(file, 'video')
2014+
}
2015+
UI.widgets.isImage = function(file, kind){
2016+
var dcCLasses = { 'audio': 'http://purl.org/dc/dcmitype/Sound',
2017+
'image': 'http://purl.org/dc/dcmitype/Image',
2018+
'video': 'http://purl.org/dc/dcmitype/MovingImage'
2019+
}
2020+
var what = kind || 'image'
2021+
var typeURIs = UI.store.findTypeURIs(file)
2022+
var prefix = $rdf.Util.mediaTypeClass( what + '/*').uri.split('*')[0]
2023+
for (var t in typeURIs) {
2024+
if (t.startsWith(prefix)) return true
2025+
}
2026+
if (dcCLasses[what] in typeURIs) return true
2027+
return false
20142028
}
20152029
// ends

0 commit comments

Comments
 (0)