forked from humphd/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhosted.html
More file actions
114 lines (97 loc) · 4.11 KB
/
Copy pathhosted.html
File metadata and controls
114 lines (97 loc) · 4.11 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
107
108
109
110
111
112
113
114
<!doctype html>
<!--
Bramble must be hosted in an iframe vs. loaded directly.
This page is a helper for local development.
-->
<html spellcheck="false">
<head>
<meta charset="utf-8">
<title>Framed Bramble</title>
<style>
body {
margin: 0;
}
.full {
height: 100vh;
overflow: hidden;
}
</style>
</head>
<body>
<div id="bramble" class="full"></div>
<script src="thirdparty/require.min.js"></script>
<script>
require.config({
baseUrl: './'
});
require(["bramble/client/main"], function(Bramble) {
Bramble.load("#bramble",{
url: "index.html",
useLocationSearch: true
});
// Event listeners
Bramble.on("ready", function(bramble) {
console.log("Bramble ready");
// For debugging, attach to window.
window.bramble = bramble;
});
Bramble.on("error", function(e, err) {
console.log("Bramble error", err);
})
Bramble.on("readyStateChange", function(previous, current) {
console.log("Bramble readyStateChange", previous, current);
});
function writeFile(path, data, callback) {
fs.writeFile(path, data, function(err) {
if(err) throw err;
callback();
});
}
// Setup the filesystem while Bramble is loading
var fs = Bramble.getFileSystem();
sh = new fs.Shell();
// Simulate a more complex root, like Thimble does
sh.mkdirp("/7/projects/30", function(err) {
// If we run this multiple times, the dir will exist
if (err && err.code !== "EEXIST") {
throw err;
}
// Default filesystem content
var index = "<html>\n" +
" <head>\n" +
" <title>Bramble</title>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is the main page.</p>\n" +
" </body>\n" +
"</html>";
var tutorial = "<html>\n" +
" <head>\n" +
" <title>Tutorial</title>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is the tutorial.</p>\n" +
" </body>\n" +
"</html>";
var css = "p {\n" +
" color: purple;\n" +
"}";
var script = "function add(a, b) {\n" +
" return a|0 + b|0;\n" +
"}";
writeFile("/7/projects/30/script.js", script, function() {
writeFile("/7/projects/30/style.css", css, function() {
writeFile("/7/projects/30/index.html", index, function() {
writeFile("/7/projects/30/tutorial.html", tutorial, function() {
// Now that fs is setup, tell Bramble which root dir to mount
// and which file within that root to open on startup.
Bramble.mount("/7/projects/30");
});
});
});
});
});
});
</script>
</body>
</html>