-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
executable file
·317 lines (251 loc) · 7.85 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
<!DOCTYPE html>
<html manifest="pwiki.appcache">
<head>
<title>pWiki</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="manifest" href="manifest.json">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-Bold.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-BoldItalic.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-ExtraBold.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-ExtraBoldItalic.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-Italic.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-Light.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-LightItalic.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-Regular.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-Semibold.ttf">
<link rel="prefetch" href="css/fonts/Open_Sans/OpenSans-SemiboldItalic.ttf">
<link rel="stylesheet" href="css/fonts.css">
</head>
<style>
</style>
<script src="ext-lib/jquery.js"></script>
<script src="ext-lib/jquery-ui.min.js"></script>
<script src="ext-lib/jquery.ui.touch.js"></script>
<script src="ext-lib/showdown.min.js"></script>
<script src="ext-lib/FileSaver.js"></script>
<script src="ext-lib/jszip.min.js"></script>
<script src="ext-lib/pouchdb.min.js"></script>
<script src="ext-lib/peer.min.js"></script>
<!--script data-main="ui" src="ext-lib/require.js"></script-->
<script src="bootstrap.js"></script>
<script src="wiki.js"></script>
<script>
// XXX experiment: save individual pages in localStorage...
// clear the localStorage...
var clearStorage = function(){
delete localStorage['store-persistently']
delete localStorage['wiki-data']
delete localStorage['wiki-location'] }
var getStorage = function(){
return localStorage['store-persistently'] ?
localStorage
: sessionStorage }
var save = () => {
var storage = getStorage()
// XXX save...
storage['wiki-data'] = JSON.stringify(Wiki.__wiki_data)
storage['wiki-location'] = Wiki.location }
var reload = () => {
// load the page...
$('.wiki')
.html(Wiki.title[0] == '_' ?
Wiki.text
: Wiki.get('./_view').text)
.ready(update_editor)
save()
// checkbox state...
// XXX move this to post-filters...
$('input[type="checkbox"].state')
// initial state...
.each(function(){
var path = $(this).attr('saveto')
var value = !!Wiki.get(path).attr('checked')
$(this)
.prop('checked', value)
.parents('.item').first()
[value ?
'addClass'
: 'removeClass']('checked') })
// handle clicks...
.click(function(){
var path = $(this).attr('saveto')
var value = $(this).prop('checked')
Wiki.get(path).attr('checked', value)
$(this)
.parents('.item').first()
[value ?
'addClass'
: 'removeClass']('checked')
// XXX
save() }) }
var update_editor = function(){
// XXX move this to post-filters...
$('.sortable')
.sortable({
handle: ".sort-handle",
placeholder: "sort-placeholder",
forcePlaceholderSize: true,
axis: 'y',
})
.addTouch()
// XXX make this update on enter...
// XXX account for title of edited page...
// XXX move this to post-filters...
$('.title')
.focus(function(){
var to = $(this).attr('saveto') || '.'
$(this).text(Wiki.get(to).title) })
.blur(function(){
var to = $(this).attr('saveto') || '.'
var text = $(this).text().trim()
var page = Wiki.get(to)
if(text[0] == '/'){
page.path = text
} else {
page.title = text }
// XXX need to account for changed path sufixes...
Wiki.path = page.path
reload() })
/*
// live update text...
// XXX is this the right way to go for large documents???
// XXX move this to post-filters...
var text = $('.text')
.focus(function(){
console.log('EDITING:', Wiki.path)
$(this)
.prop('contenteditable', 'true')
.html(Wiki.raw.replace(/\n/gm, '<br class="tmp-br"/>\n'))
//reload()
})
.on('keyup', function(){
if($(this).prop('contenteditable') == 'true'){
var to = $(this).attr('saveto') || '.'
console.log('SAVING:', Wiki.get(to).path)
//Wiki.get(to).raw = clearWikiWords(
// $('.text').clone())
// .html()
// show \n in the inline editor...
//Wiki.get(to).raw = clearWikiWords(
// $('.text').clone()
// .find('.tmp-br')
// .remove()
// .end())
// .html()
} })
// XXX do this live, but on a timeout after user input...
// XXX need to place the cursor in the same position...
.blur(() => {
$(this)
.removeAttr('contenteditable')
reload() })
//*/
//text.html(Wiki.get(text.attr('saveto')).text)
// XXX move this to post-filters...
var raw = $('.raw')
.focus(function(){
var to = $(this).attr('saveto') || '.'
console.log('EDITING:', Wiki.get(to).path) })
.on('keyup', function(){
var to = Wiki.get($(this).attr('saveto') || '.').path
console.log('SAVING:', to)
//Wiki.get(to).raw = $(this).text()
Wiki.get(to).raw = $(this)[0].innerText })
// XXX do this live, but on a timeout after user input...
// XXX need to place the cursor in the same position...
.blur(() => {
reload() })
//.text($('.raw').html())
//raw.text(Wiki.get(raw.attr('saveto')).raw)
/*
$('include')
.attr('tabindex', 0)
.click(function(){
event.stopPropagation() })
.focus(function(){
var to = $(this).attr('src') || '.'
var page = Wiki.get(to)
console.log('EDITING:', page.path)
// XXX select editor based on filters...
$(this)
//.html(page.text)
.html($('<pre>')
.text(page.raw)) })
.on('keyup', function(){
var to = Wiki.get($(this).attr('src') || '.').path
console.log('SAVING:', to)
//Wiki.get(to).raw = $(this).text()
//Wiki.get(to).raw = $(this)[0].innerText
})
// XXX do this live, but on a timeout after user input...
// XXX need to place the cursor in the same position...
.blur(() => {
reload() })
//*/
}
var go = (path) => {
console.log('GO:', path)
path = path.trim()
path = path[0] == '[' ? path.slice(1, -1) : path
// history stuff...
if(path == 'History/back'){
return history.back()
} else if(path == 'History/forward'){
return history.forward() }
Wiki.location = path
history.pushState({
wikipath: Wiki.location
},
Wiki.title,
window.location)
reload() }
var exportZip = function(){
var zip = new JSZip()
var pwiki = zip.folder("pWiki")
pwiki.file("data.json", JSON.stringify(Wiki.__wiki_data))
zip.generateAsync({type:"blob"})
.then(function(content) {
// see FileSaver.js
saveAs(content, "pWiki.zip") }) }
$(() => {
$(window).on('popstate', function(evt){
event.state
&& event.state.wikipath
&& go(event.state.wikipath) })
// load bootstrap data...
if(window.Bootstrap){
Bootstrap.__proto__ = BaseData
data = Wiki.__wiki_data = Bootstrap }
var storage = getStorage()
// load stored data...
Wiki.__wiki_data = storage['wiki-data'] ?
JSON.parse(storage['wiki-data'])
: data
if(Wiki.__wiki_data !== data){
Wiki.__wiki_data.__proto__ = data }
Wiki.location = storage['wiki-location'] || Wiki.location
reload()
//update_editor()
// XXX need to resolve relative hashes...
$(window).on('hashchange', function(evt){
evt.preventDefault()
var path = location.hash.slice(1)
var hash = path.split('#')
path = hash.shift()
hash = hash.pop() || ''
// expand the path...
if(Wiki.get(path).path != path){
location.hash = Wiki.get(path).path
// open page...
} else {
go(path)
if(hash.length > 0){
// XXX focus anchor...
} } }) })
</script>
<body>
<div class="wiki" />
</body>
</html>
<!-- vim:set sw=4 ts=4 : -->