Skip to content

Commit b35df8c

Browse files
up to findImage
1 parent d6e7e23 commit b35df8c

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

examples/buttons/index.html

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</script>
1010
</head>
1111
<body>
12-
<h2 id="addStyleSheet"><a href="#addStyleSheet">addStyleSheet</a></h2>
12+
<!-- <h2 id="addStyleSheet"><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2FJavaScriptSolidServer%2Fsolid-ui%2Fcommit%2Fb35df8c30e85427e84d18c14fe8b0857bc2c776e%23addStyleSheet">addStyleSheet</a></h2>
1313
<script id="script-addStyleSheet">
1414
window.addEventListener('DOMContentLoaded', (event) => {
1515
UI.widgets.addStyleSheet(document, 'https://linkeddata.github.io/tabulator-firefox/content/tabbedtab.css')
@@ -203,23 +203,43 @@ <h2 id="fileUploadButtonDiv"><a href="#fileUploadButtonDiv"><a href="#fileUpload
203203
})
204204
</script>
205205
<pre id="viewSource-fileUploadButtonDiv"></pre><script>$('#viewSource-fileUploadButtonDiv').innerHTML = $('#script-fileUploadButtonDiv').innerText</script>
206-
<div id="div-fileUploadButtonDiv"></div>
206+
<div id="div-fileUploadButtonDiv"></div> -->
207207

208208
<h2 id="findImage"><a href="#findImage">findImage</a></h2>
209209
<script id="script-findImage">
210+
// FIXME: not sure why agentNode.sameTerm(UI.ns.foaf('Agent')) is false
211+
function displayFindImageResult(url) {
212+
const node = UI.rdf.namedNode(url)
213+
const result = UI.widgets.findImage(node)
214+
const image = document.createElement('img')
215+
image.setAttribute('src', result)
216+
image.setAttribute('style', 'width: 100px; height: 100px;')
217+
$('#div-findImage').appendChild(image)
218+
}
210219
window.addEventListener('DOMContentLoaded', (event) => {
211-
// const result = UI.widgets.findImage()
212-
// $('#div-findImage').appendChild(document.createTextNode(result))
220+
const agentNode = UI.rdf.namedNode('https://example.com/#agent')
221+
UI.store.add(agentNode, UI.ns.rdf('type'), UI.ns.foaf('Agent'))
222+
displayFindImageResult(agentNode)
213223
})
214224
</script>
215225
<pre id="viewSource-findImage"></pre><script>$('#viewSource-findImage').innerHTML = $('#script-findImage').innerText</script>
216226
<div id="div-findImage"></div>
217227

218228
<h2 id="findImageFromURI"><a href="#findImageFromURI">findImageFromURI</a></h2>
219229
<script id="script-findImageFromURI">
220-
window.addEventListener('DOMContentLoaded', (event) => {
221-
// const result = UI.widgets.findImageFromURI()
222-
// $('#div-findImageFromURI').appendChild(document.createTextNode(result))
230+
function displayFindImageFromURIResult(url) {
231+
const node = UI.rdf.namedNode(url)
232+
const result = UI.widgets.findImageFromURI(node)
233+
const image = document.createElement('img')
234+
image.setAttribute('src', result)
235+
image.setAttribute('style', 'width: 100px; height: 100px;')
236+
$('#div-findImageFromURI').appendChild(image)
237+
}
238+
window.addEventListener('DOMContentLoaded', (event) => {
239+
displayFindImageFromURIResult('https://example.com/')
240+
displayFindImageFromURIResult('https://solidproject.org/some/file.html')
241+
displayFindImageFromURIResult('mid:asdf')
242+
displayFindImageFromURIResult('mailto:user@example.com')
223243
})
224244
</script>
225245
<pre id="viewSource-findImageFromURI"></pre><script>$('#viewSource-findImageFromURI').innerHTML = $('#script-findImageFromURI').innerText</script>

src/widgets/buttons.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function tempSite (x) {
242242
/**
243243
* Find an image for this thing as a class
244244
*/
245-
function findImageFromURI (x) {
245+
function findImageFromURI (x: NamedNode): string | null {
246246
const iconDir = UI.icons.iconBase
247247

248248
// Special cases from URI scheme:
@@ -256,7 +256,7 @@ function findImageFromURI (x) {
256256
}
257257
// Non-HTTP URI types imply types
258258
if (x.uri.startsWith('message:') || x.uri.startsWith('mid:')) {
259-
// message: is aapple bug-- should be mid:
259+
// message: is apple bug-- should be mid:
260260
return iconDir + 'noun_480183.svg' // envelope noun_567486
261261
}
262262
if (x.uri.startsWith('mailto:')) {
@@ -265,8 +265,8 @@ function findImageFromURI (x) {
265265
// For HTTP(s) documents, we could look at the MIME type if we know it.
266266
if (x.uri.startsWith('https:') && x.uri.indexOf('#') < 0) {
267267
return tempSite(x) + 'favicon.ico' // was x.site().uri + ...
268-
// Todo: make the docuent icon a fallback for if the favicon does not exist
269-
// todo: pick up a possible favicon for the web page istelf from a link
268+
// Todo: make the document icon a fallback for if the favicon does not exist
269+
// todo: pick up a possible favicon for the web page itself from a link
270270
// was: return iconDir + 'noun_681601.svg' // document - under solid assumptions
271271
}
272272
return null
@@ -275,9 +275,10 @@ function findImageFromURI (x) {
275275
return iconDir + 'noun_10636_grey.svg' // Grey Circle - some thing
276276
}
277277

278-
/* Find something we have as explict image data for the thing
279-
*/
280-
function findImage (thing) {
278+
/**
279+
* Find something we have as explicit image data for the thing
280+
*/
281+
function findImage (thing: NamedNode) {
281282
const kb = UI.store
282283
const ns = UI.ns
283284
const iconDir = UI.icons.iconBase

0 commit comments

Comments
 (0)