This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
327 lines (285 loc) · 8.46 KB
/
index.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Starlog</title>
<!-- Place favicon.ico in the `app/` directory -->
<!-- build:css styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild-->
<!-- build:js bower_components/webcomponentsjs/webcomponents-lite.min.js -->
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<!-- endbuild -->
<script src="node_modules/ipfs-api/dist/ipfsapi.js"></script>
<!-- will be replaced with elements/elements.vulcanized.html -->
<link rel="import" href="elements/elements.html">
<!-- endreplace-->
<style is="custom-style">
paper-toolbar {
height: 60px;
--paper-toolbar-background: #000;
--paper-toolbar-color: #fff;
--paper-toolbar: {
font-size: 40px;
};
}
</style>
</head>
<body unresolved class="fullbleed">
<template is="dom-bind" id="app">
<scroll-events on-bottom="onBottom"></scroll-events>
<div class="layout vertical">
<iron-pages attr-for-selected="view"
class="fit offset"
selected="{{view}}">
<section view="home">
<paper-drawer-panel
peeking="true"
id="drawer"
drawerToggleAttribute="close">
<div drawer>
<paper-material class="menu layout horizontal flex"
on-click="onCompose">
<iron-icon class="narrow" icon="add"></iron-icon>
<span class="menutext flex">New post</span>
</paper-material>
<paper-material class="menu layout horizontal">
<iron-icon icon="search"></iron-icon>
<input id="titlesearch"
class="menutext"
value="{{titlesearch}}"
on-change="searchChange"
flex>
</input>
</paper-material>
<feed-view
on-update="updateHash"
on-view="viewPost"
on-edit="editPost"
id="myfeed"
icon="{{myicon}}"
name="{{myname}}"
items="{{items}}"
status="{{status}}"
editable="true">
</feed-view>
</div>
<paper-material main class="homescreen layout vertical">
<template is="dom-if" if="{{!compose}}">
<div class="padded">
<img class="icon" src="{{myicon}}"/>
<h2>{{myname}}</h2>
<p>
<a href="{{logLink(local)}}">Link to this log</a>
</p>
<p>
<a href="{{gatewayLink(local)}}">Gateway link</a>
</p>
<p>
Select icon:
<ipfs-add-file on-add="updateIcon">
</ipfs-add-file>
</p>
</div>
</template>
<compose-message flex
hidden="{{!compose}}"
id="editor"
on-cancel="cancelCompose"
on-post="post">
</compose-message>
</paper-material>
</paper-drawer-panel>
</section>
<section view="reading">
<paper-drawer-panel id="drawer2">
<div drawer>
</div>
</paper-drawer-panel>
</section>
<section view="starlog">
<starlog-view
items="{{items}}"
on-view="viewPost"
id="starlog"
path="{{starlogpath}}"
seqnr="{{seqnr}}">
</starlog-view>
</section>
<section view="init">
<initialize-feed on-initialized="feedInitialized"></initialize-feed>
</section>
</iron-pages>
<paper-toolbar class="paper-header">
<div class="toolbar layout horizontal justified">
<div>
<template is="dom-if" if="{{!readonly}}">
<paper-tabs
selected="{{route}}"
attr-for-selected="data-route">
<paper-tab data-route="/home">Home</paper-tab>
</paper-tabs>
</template>
</div>
<iron-pages attr-for-selected="view"
selected="{{view}}">
<div class="textsearch" view="starlog">
<input
value="{{textsearch}}"
id="textsearch"
on-change="textsearchChange"></input>
<iron-icon icon="search"></iron-icon>
</div>
</iron-pages>
</div>
</paper-toolbar>
</div>
</template>
</body>
<script>
var app = document.querySelector('#app')
app.properties = {
readonly: {
type: Boolean,
value: true
},
compose: {
type: Boolean,
value: false
},
route: {
type: String,
observer: 'routeChanged'
}
}
app.routeChanged = function (a) {
if (a.newURL) {
var idx = a.newURL.indexOf('/#!') + 3
page(a.newURL.substr(idx))
}
}
app.updateHash = function (ev) {
app.local = ev.detail
app.$.myfeed.load(app.local)
}
app.post = function (env) {
app.compose = false
app.$.drawer.openDrawer()
app.$.myfeed.append(env.detail)
app.$.editor.clear()
}
app.cancelCompose = function (env) {
app.compose = false
}
app.onCompose = function () {
app.compose = true
app.$.editor.clear()
app.$.drawer.closeDrawer()
}
app.editPost = function (ev) {
app.compose = true
var el = ev.detail.element
app.$.drawer.closeDrawer()
var updates = el.updates || "#" + ev.detail.index
app.$.editor.init({ title: el.title,
body: el.body,
updates: updates })
}
app.feedInitialized = function (ev) {
app.local = ev.detail
page('/home')
}
app.updateIcon = function (ev) {
app.$.myfeed.setIcon(ev.detail)
}
app.viewPost = function (ev) {
page('/starlog/' + ev.detail.log + '/' + ev.detail.seqnr)
}
app.onBottom = function () {
if (app.view == 'starlog' && app.latest) {
app.$.starlog.loadMessages(5)
}
}
app.logLink = function (hash) {
return '/starlog/' + hash + '/latest'
}
app.gatewayLink = function (hash) {
var selfhash = window.location.pathname.split('/')[2]
return 'http://ipfs.io/ipfs/' + selfhash + '#!/starlog/' + hash + '/latest'
}
app.searchChange = function (e) {
app.$.myfeed.load(app.local,
undefined,
e.target.value ? { title: e.target.value } : {})
}
app.textsearchChange = function (e) {
app.$.starlog.load(app.loghash,
undefined,
e.target.value ? { body: e.target.value } : {})
}
app.loadMyFeed = function () {
app.readonly = false
var search = app.$.titlesearch.value
app.$.myfeed.load(app.local,
undefined,
search ? { title: search } : {})
}
app.home = function () {
app.compose = false
app.route = '/home'
app.view = 'home'
var ipfs = ipfsAPI()
if (!app.local) {
app.setup()
} else {
app.loadMyFeed()
}
}
app.init = function () {
app.view = 'init'
}
app.setup = function () {
// check if we have a local log
ipfs.id(function (err, res) {
if (err) {
// id not available, maybe on gateway.
app.readonly = true
return
}
ipfs.name.resolve(res.ID, function (err, res) {
if (err) throw err
var split = res.Path.split('/')
app.local = split[split.length - 1]
// check if it's really a starlog feed
ipfs.object.get(app.local, function (err, res) {
if (err) throw err
var type
try {
type = JSON.parse(res.Data).type
} catch (e) {}
if (type === 'starlog-feed') {
page('/home')
} else {
page('/init')
}
})
})
})
}
app.starlog = function (loghash, seqnr) {
app.view = 'starlog'
app.route = '/starlog'
app.loghash = loghash
app.latest = seqnr === 'latest'
app.seqnr = parseInt(seqnr) || undefined
var search = app.$.textsearch.value
app.$.starlog.load(app.loghash,
app.seqnr,
search ? { body: search } : {},
app.seqnr ? 1 : undefined)
}
window.addEventListener("hashchange", app.routeChanged, false)
</script>
</html>