forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicPanes.js
More file actions
106 lines (94 loc) · 3.85 KB
/
dynamicPanes.js
File metadata and controls
106 lines (94 loc) · 3.85 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
/* Dynamic loading of panes from metadata
**
** This outline pane shows an external sanboxed viewer for the subject
** according to metadata
*/
var UI = require('solid-ui')
// @@ todo: move this function elsewhere generic
var panesFromData = function(subject){
var ns = UI.ns, kb = UI.store
var apps = kb.each(undefined, ns.rdf('type'), ns.solid('ApplicationRegistration'))
var t = kb.findTypeURIs(subject)
for (var i=0; i<apps.length; i++){
var app = apps[i]
try {
var icon = kb.any(app, ns.foaf('img')).value // @@ check doap voab
var label = kb.any(app, ns.rdfs('label')).value
var URITemplate = kb.any(app, ns.solid('URITemplate')).value
var appPage = kb.any(app, ns.solid('appPage')).uri
var matches, types = kb.each(app, ns.solid('forClass'))
} catch(e) {
console.log("Error getting app details " + app + ": " + e)
continue;
}
for (var j=0; j< types.length; j++){
if (t[types[j].uri]) {
matches = true; break;
}
}
var render = function(subject, dom, template){
var div = myDocument.createElement("div");
div.setAttribute('class', 'docView')
var iframe = myDocument.createElement("IFRAME")
iframe.setAttribute('src', subject.uri) // allow-same-origin
iframe.setAttribute('class', 'doc')
iframe.setAttribute('sandbox', 'allow-same-origin allow-forms'); // allow-scripts ?? no documents should be static
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
iframe.setAttribute('style', 'resize = both; height: 120em; width:80em;')
// iframe.setAttribute('height', '480')
// iframe.setAttribute('width', '640')
var tr = myDocument.createElement('TR')
tr.appendChild(iframe)
div.appendChild(tr)
return div
}
if (matches){
var pane = { icon: icon, label: function(){return label}}
}
}
}
// Andrei's 'warp' file manager as a pane
// black rocket not ongh-pages: js/panes/common/icons/noun_113198.svg
// red rocket: js/panes/warp/icons/warp-icon.png
module.exports = {
icon: UI.icons.iconBase + 'noun_113198.svg',
name: 'warp',
// same as classInstancePane
label: function(subject, myDocument) {
var n = UI.store.each(
undefined, UI.ns.rdf( 'type'), subject).length;
if (n > 0) return "List (" + n + ")"; // Show how many in hover text
n = UI.store.each(
subject, UI.ns.ldp( 'contains')).length;
if (n > 0) {
return "Contents (" + n + ")" // Show how many in hover text
}
return null; // Suppress pane otherwise
},
render: function(subject, myDocument) {
var div = myDocument.createElement("div")
// @@ When we can, use CSP to turn off scripts within the iframe
div.setAttribute('class', 'warp')
var iframe = myDocument.createElement("IFRAME")
iframe.setAttribute('src', subject.uri) // allow-same-origin
iframe.setAttribute('class', 'doc')
iframe.setAttribute('sandbox', 'allow-same-origin allow-forms allow-scripts'); // allow-scripts ?? no documents should be static
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
// Like https://linkeddata.github.io/warp/#/list/http/localhost:3080/timbl/Public/Test/Warp/
var warpURI = 'https://linkeddata.github.io/warp/#/list/http'
var p = subject.uri.indexOf('//')
if (subject.uri.slice(0,6) === 'https:') {
warpURI += 's'
}
warpURI += subject.uri.slice(p + 1)
iframe.setAttribute('src', warpURI)
iframe.setAttribute('style', 'resize = both; height: 120em; width:80em;')
// iframe.setAttribute('height', '480')
// iframe.setAttribute('width', '640')
var tr = myDocument.createElement('TR')
tr.appendChild(iframe)
div.appendChild(tr)
return div
}
}
//ends