-
Notifications
You must be signed in to change notification settings - Fork 8
/
try.html
234 lines (220 loc) · 6.39 KB
/
try.html
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html>
<html>
<head>
<link rel="canonical" href="https://gun.eco/try.html" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/4374976/random/phrase.js"></script>
<script src="dep/rsc/analytics.js"></script>
</head>
<body class="tutorial">
<script src="https://gunjs.herokuapp.com/gun.js"></script>
<link id="style" rel="stylesheet" href="https://yandex.st/highlightjs/8.0/styles/ir_black.min.css">
<script src="https://yandex.st/highlightjs/8.0/highlight.min.js"></script>
<style>
@import url(https://fonts.googleapis.com/css?family=Dosis|Poiret+One|Oxygen);
.tutorial {
margin: 0;
padding: 0;
he-ight: 100%;
font-family: 'Oxygen', Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif;
background: #222;
color: #eee;
overflow: auto;
}
.center {
text-align: center;
}
.lean {
font-family: 'Poiret One', Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif;
}
.clean {
font-family: 'Dosis', Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif;
}
.crisp {
font-family: 'Oxygen', Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif;
}
pre {
background-color: black;
border: 1px dashed white;
color: white;
line-height: 1.5em;
padding: .5em;
margin: 0em;
overflow: auto;
}
button {
border: none;
color: white;
background: skyblue;
padding: 1em;
cursor: pointer;
}
.hide {
display: none;
}
.show {
display: block;
}
.grid {
text-align: center;
}
.unit {
display: inline-block;
}
.main {
min-width: 250px;
max-width: 1024px;
width: 90%;
margin: 0% auto;
padding: 2% 5%;
}
div {
position: relative;
}
.left { float: left;}
.teft { text-align: left; }
.middle {
vertical-align: middle;
}
.full {
width: 100%;
}
</style>
<div class="main">
<div style="font-size: 18pt; margin: 0 0 .75em;">Try it now</div>
<div class="step show step1">
<div class="full grid">
<div class="middle unit teft">
<pre style="max-width: 30.1em; margin: 0 1em 1em 0;">var gun = Gun('https://gunjs.herokuapp.com/gun');
gun.get('<span class="your-key">example/tutorial</span>').put({hello: "world"});</pre>
</div>
<div class="middle unit teft" style="min-width: 20em; max-width: 28em; margin-bottom: 1em;">
<a href="#step2"><button class="left" style="margin-right: 1em;"><big>Run!</big></button></a>
In this <b>1 minute</b> tutorial, we will connect to a gun peer, create an object, and sync data in realtime.
</div>
</div>
</div>
<div class="step hide step2">
<div class="full grid">
<div class="middle unit teft">
<pre style="max-width: 30.1em; margin: 0 1em 1em 0;">var ref = gun.get('<span class="your-key">example/tutorial</span>');
ref.on(function(data){
$('body').text(JSON.stringify(data));
});</pre>
</div>
<div class="middle unit teft" style="min-width: 34em; max-width: 28em; margin-bottom: 1em;">
<a href="#step3"><button class="left" style="margin-right: 1em; background: MediumSpringGreen;"><big>Next</big></button></a>
Congratulations! You just referenced an object and saved data to it.
In two tabs, we'll load that reference and sync data between them.
</div>
</div>
</div>
<div class="step hide step3">
<div class="full grid">
<style>
.browser {
background: white;
border-radius: .25em;
width: 250px;
//height: 300px;
color: #222;
margin: .5em;
overflow: hidden;
}
.b-bar {
background: #EEE;
border-radius: .25em .25em 0 0;
}
.b-but {
float: left;
width: 1em;
height: 1em;
}
.browser a {
text-decoration: none;
background: white;
border-radius: .4em;
padding: 0 1em;
color: #555;
}
.browser iframe { border: none; }
</style>
<div class="browser unit teft">
<div class="b-bar">
<div class="b-but">←</div>
<div class="b-but">→</div>
<div class="b-but"><small>↻</small></div>
<small><small><span>
<a href="https://gunjs.herokuapp.com/" target="_blank">https://gunjs.herokuapp.com/</a>
</span></small></small>
<small class="center" style="position: relative; top: -.14em;">x</small>
<span class="center">≡<span>
</div>
<iframe></iframe>
</div>
<div class="browser unit teft">
<div class="b-bar">
<div class="b-but">←</div>
<div class="b-but">→</div>
<div class="b-but"><small>↻</small></div>
<small><small><span>
<a href="https://gunjs.herokuapp.com/" target="_blank">https://gunjs.herokuapp.com/</a>
</span></small></small>
<small class="center" style="position: relative; top: -.14em;">x</small>
<span class="center">≡<span>
</div>
<iframe></iframe>
</div>
</div>
<form action="#step3" onsubmit="return false;">
<style>
#step3 input {
width: 6em;
}
</style>
<div class="grid">
<div class="middle unit teft">
<pre style="max-width: 40em; margin: 0 1em 1em 0;">ref.get('<input id="try-path" value="hello">').put("<input id="try-sync" value="sync">");</pre>
</div>
<div class="middle unit teft" style="min-width: 20em; max-width: 30em; margin-bottom: 1em;">
<button type="submit" class="left" style="margin-right: 1em;"><big>Update!</big></button>
Let's update the "hello" field with a different value.
We can get any field on the object, and update it directly.
</div>
</div>
</form>
</div>
<script>
$(function(){
var gun, key = "random/" + Gun.text.random(9),
hili = function(){
$("pre").each(function(){
hljs.highlightBlock(this);
})
}
$(".your-key").text(key);
hili();
location.hash = 'step1';
$(window).on('hashchange', function(){
$('.step').removeClass('show').addClass('hide')
$(location.hash.replace('#','.')).addClass('show');
});
$(".step1").find('button').on('click', function(e){
if(gun){ return }
gun = Gun('https://gunjs.herokuapp.com/gun');
gun.get(key).put({hello: "world"});
});
$(".step2").find('button').on('click', function(e){
$(".browser").find("iframe").attr("src", "./tabs.html?key=" + key);
});
$(".step3").find('form').on('submit', function(e){
var val = $("#try-sync").val() || null;
var path = $("#try-path").val();
gun.get(key).get(path).put(val);
});
})
</script>
</div>
</body>
</html>