forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsourcePane.js
More file actions
74 lines (50 loc) · 1.83 KB
/
sourcePane.js
File metadata and controls
74 lines (50 loc) · 1.83 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
/* View Source Pane
**
** This pane shows the raw content of formats which are normaly parsed
** normally for dignostic purposes
** @@ Syntax colouring would of course be great
** e.g. Maybe http://google-code-prettify.googlecode.com/svn/trunk/README.html
**
** Todo: finish the code
*/
module.exports = {
icon: UI.icons.iconBase + 'noun_16323.svg', // View Source
name: 'source',
label: function(subject) {
var allowed = ['application/x-javascript',
'text/n3', 'text/turtle',
// 'text/plain',
'text/html','application/xhtml+xml','text/css'];
var dispalyable = function(kb, x, displayables) {
var cts = kb.fetcher.getHeader(x, 'content-type');
if (cts) {
for (var j=0; j<cts.length; j++) {
for (var k=0; k < displayables.length; k++) {
if (cts[j].indexOf(displayables[k]) >= 0) {
return true;
}
}
}
}
return false;
};
var t = kb.findTypeURIs(subject);
if (t[ns.link('WebPage').uri]) return "view source";
if (cts.length && (cts[0].slice(0,5) === 'text/'
|| cts[0].indexOf('+xml') >= 0)
) return "view source";
if (displayable(kb, subject, allowed)) return "View source";
return null;
},
// View the data in a file in user-friendly way
render: function(subject, myDocument) {
var kb = UI.store;
var div = myDocument.createElement("div")
div.setAttribute('class', 'sourcePane');
var pre = myDocument.createElement('pre');
// @@ Now find the content @@ todo
div.appendChild(pre);
return div
}
};
//ends