Skip to content

Commit e699391

Browse files
looking at propertyTriage
1 parent 7ab2d4d commit e699391

2 files changed

Lines changed: 60 additions & 32 deletions

File tree

examples/buttons/index.html

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,13 @@ <h2 id="isVideo"><a href="#isVideo">isVideo</a></h2>
366366
<h2 id="linkButton"><a href="#linkButton">linkButton</a></h2>
367367
<script id="script-linkButton">
368368
window.addEventListener('DOMContentLoaded', (event) => {
369-
// const result = UI.widgets.linkButton()
370-
// $('#div-linkButton').appendChild(document.createTextNode(result))
369+
document.outlineManager = {
370+
GotoSubject: (object) => {
371+
window.alert('You told the outlineManager to go to subject ' + object.uri)
372+
}
373+
}
374+
const result = UI.widgets.linkButton(document, UI.rdf.namedNode('http://example.com/'))
375+
$('#div-linkButton').appendChild(result)
371376
})
372377
</script>
373378
<pre id="viewSource-linkButton"></pre><script>$('#viewSource-linkButton').innerHTML = $('#script-linkButton').innerText</script>
@@ -376,8 +381,15 @@ <h2 id="linkButton"><a href="#linkButton">linkButton</a></h2>
376381
<h2 id="linkIcon"><a href="#linkIcon">linkIcon</a></h2>
377382
<script id="script-linkIcon">
378383
window.addEventListener('DOMContentLoaded', (event) => {
379-
// const result = UI.widgets.linkIcon()
380-
// $('#div-linkIcon').appendChild(document.createTextNode(result))
384+
$('#div-linkIcon').appendChild(UI.widgets.linkIcon(
385+
document,
386+
UI.rdf.namedNode('https://example.com/'))
387+
)
388+
$('#div-linkIcon').appendChild(UI.widgets.linkIcon(
389+
document,
390+
UI.rdf.namedNode('https://example.org/'),
391+
'https://solidproject.org/favicon.ico')
392+
)
381393
})
382394
</script>
383395
<pre id="viewSource-linkIcon"></pre><script>$('#viewSource-linkIcon').innerHTML = $('#script-linkIcon').innerText</script>
@@ -386,8 +398,19 @@ <h2 id="linkIcon"><a href="#linkIcon">linkIcon</a></h2>
386398
<h2 id="openHrefInOutlineMode"><a href="#openHrefInOutlineMode">openHrefInOutlineMode</a></h2>
387399
<script id="script-openHrefInOutlineMode">
388400
window.addEventListener('DOMContentLoaded', (event) => {
389-
// const result = UI.widgets.openHrefInOutlineMode()
390-
// $('#div-openHrefInOutlineMode').appendChild(document.createTextNode(result))
401+
document.outlineManager = {
402+
GotoSubject: (object) => {
403+
window.alert('You told the outlineManager to go to subject ' + object.uri)
404+
}
405+
}
406+
const anchor = document.createElement('a')
407+
anchor.setAttribute('href', 'http://example.com')
408+
anchor.onclick = (e) => {
409+
UI.widgets.openHrefInOutlineMode(e)
410+
return false
411+
}
412+
anchor.appendChild(document.createTextNode('click me'))
413+
$('#div-openHrefInOutlineMode').appendChild(anchor)
391414
})
392415
</script>
393416
<pre id="viewSource-openHrefInOutlineMode"></pre><script>$('#viewSource-openHrefInOutlineMode').innerHTML = $('#script-openHrefInOutlineMode').innerText</script>
@@ -396,8 +419,9 @@ <h2 id="openHrefInOutlineMode"><a href="#openHrefInOutlineMode">openHrefInOutlin
396419
<h2 id="personTR"><a href="#personTR">personTR</a></h2>
397420
<script id="script-personTR">
398421
window.addEventListener('DOMContentLoaded', (event) => {
399-
// const result = UI.widgets.personTR()
400-
// $('#div-personTR').appendChild(document.createTextNode(result))
422+
const michiel = UI.rdf.namedNode('https://michielbdejong.inrupt.net/profile/card#me')
423+
const result = UI.widgets.personTR(document, null, michiel)
424+
$('#div-personTR').appendChild(result)
401425
})
402426
</script>
403427
<pre id="viewSource-personTR"></pre><script>$('#viewSource-personTR').innerHTML = $('#script-personTR').innerText</script>
@@ -406,8 +430,9 @@ <h2 id="personTR"><a href="#personTR">personTR</a></h2>
406430
<h2 id="propertyTriage"><a href="#propertyTriage">propertyTriage</a></h2>
407431
<script id="script-propertyTriage">
408432
window.addEventListener('DOMContentLoaded', (event) => {
409-
// const result = UI.widgets.propertyTriage()
410-
// $('#div-propertyTriage').appendChild(document.createTextNode(result))
433+
const kb = UI.rdf.graph()
434+
const result = UI.widgets.propertyTriage(kb)
435+
$('#div-propertyTriage').appendChild(document.createTextNode(JSON.stringify(result)))
411436
})
412437
</script>
413438
<pre id="viewSource-propertyTriage"></pre><script>$('#viewSource-propertyTriage').innerHTML = $('#script-propertyTriage').innerText</script>

src/widgets/buttons.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,10 @@ function askName (
586586

587587
// ////////////////////////////////////////////////////////////////
588588

589-
// A little link icon
590-
//
591-
//
592-
function linkIcon (dom, subject, iconURI?) {
589+
/**
590+
* A little link icon
591+
*/
592+
function linkIcon (dom: HTMLDocument, subject: NamedNode, iconURI?: string): HTMLElement {
593593
var anchor = dom.createElement('a')
594594
anchor.setAttribute('href', subject.uri)
595595
if (subject.uri.startsWith('http')) {
@@ -605,11 +605,12 @@ function linkIcon (dom, subject, iconURI?) {
605605
return anchor
606606
}
607607

608-
// A TR to repreent a draggable person, etc in a list
609-
//
610-
// pred is unused param at the moment
611-
//
612-
function personTR (dom, pred, obj, options) {
608+
/**
609+
* A TR to repreent a draggable person, etc in a list
610+
*
611+
* pred is unused param at the moment
612+
*/
613+
function personTR (dom: HTMLDocument, pred: NamedNode, obj: NamedNode, options: any): HTMLTableRowElement {
613614
var tr = dom.createElement('tr')
614615
options = options || {}
615616
// tr.predObj = [pred.uri, obj.uri] moved to acl-control
@@ -642,7 +643,7 @@ function personTR (dom, pred, obj, options) {
642643
dragAndDrop.makeDraggable(tr, obj)
643644
}
644645
}
645-
tr.subject = obj
646+
;(tr as any).subject = obj
646647
return tr
647648
}
648649

@@ -754,12 +755,13 @@ function attachmentList (dom: HTMLDocument, subject: NamedNode, div: HTMLElement
754755

755756
// /////////////////////////////////////////////////////////////////////////////
756757

757-
// Event Handler for links within solid apps.
758-
//
759-
// Note that native links have consraints in Firefox, they
760-
// don't work with local files for instance (2011)
761-
//
762-
function openHrefInOutlineMode (e) {
758+
/**
759+
* Event Handler for links within solid apps.
760+
*
761+
* Note that native links have constraints in Firefox, they
762+
* don't work with local files for instance (2011)
763+
*/
764+
function openHrefInOutlineMode (e: Event) {
763765
e.preventDefault()
764766
e.stopPropagation()
765767
var target = utils.getTarget(e)
@@ -839,7 +841,7 @@ function allClassURIs (): { [uri: string]: boolean } {
839841
* @param {Store} kb The quadstore to be searched.
840842
*/
841843

842-
function propertyTriage (kb) {
844+
function propertyTriage (kb: IndexedFormula): any {
843845
var possibleProperties: any = {}
844846
// if (possibleProperties === undefined) possibleProperties = {}
845847
// var kb = UI.store
@@ -848,7 +850,7 @@ function propertyTriage (kb) {
848850
var no = 0
849851
var nd = 0
850852
var nu = 0
851-
var pi = kb.predicateIndex // One entry for each pred
853+
var pi = (kb as any).predicateIndex // One entry for each pred
852854
for (var p in pi) {
853855
var object = pi[p][0].object
854856
if (object.termType === 'Literal') {
@@ -879,15 +881,16 @@ function propertyTriage (kb) {
879881
* General purpose widgets
880882
*/
881883

882-
// A button for jumping
883-
//
884-
function linkButton (dom, object) {
884+
/**
885+
* A button for jumping
886+
*/
887+
function linkButton (dom: HTMLDocument, object: NamedNode): HTMLElement {
885888
var b = dom.createElement('button')
886889
b.setAttribute('type', 'button')
887890
b.textContent = 'Goto ' + utils.label(object)
888891
b.addEventListener('click', function (_event) {
889892
// b.parentNode.removeChild(b)
890-
dom.outlineManager.GotoSubject(object, true, undefined, true, undefined)
893+
;(dom as any).outlineManager.GotoSubject(object, true, undefined, true, undefined)
891894
}, true)
892895
return b
893896
}

0 commit comments

Comments
 (0)