pWiki/index.html
Alex A. Naanou 5172666b45 reworked macros and re-did base teplate pages...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2016-07-28 09:07:46 +03:00

179 lines
3.5 KiB
HTML
Executable File

<!DOCTYPE html>
<html>
<head>
<title>pWiki</title>
</head>
<style>
.raw,
.text
{
display: block;
}
</style>
<script src="ext-lib/jquery.js"></script>
<script src="ext-lib/showdown.min.js"></script>
<script src="ext-lib/pouchdb.min.js"></script>
<script src="ext-lib/peer.min.js"></script>
<script src="wiki.js"></script>
<script>
var clear = () => {
delete localStorage['wiki-data']
delete localStorage['wiki-location']
}
var reload = () => {
$('.wiki')
.html(Wiki.title[0] == '_' ? Wiki.text : Wiki.get('./_view').text)
.ready(update_editor)
// XXX save...
localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data)
localStorage['wiki-location'] = Wiki.location
$('title').text(Wiki.location)
}
var update_editor = function(){
// XXX make this update on enter...
$('.title')
.on('blur', () => {
Wiki.title = $('.title').text()
reload()
})
// live update text...
// XXX is this the right way to go for large documents???
var text = $('.text')
.focus(function(){
console.log('EDITING:', Wiki.path)
$(this)
.prop('contenteditable', 'true')
.html(Wiki.raw)
//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()
}
})
// 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)
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()
})
// 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)
}
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()
}
$(() => {
$(window).on('popstate', function(evt){
event.state
&& event.state.wikipath
&& go(event.state.wikipath)
})
// load stored data...
Wiki.__wiki_data = localStorage['wiki-data'] ?
JSON.parse(localStorage['wiki-data'])
: data
Wiki.__wiki_data.__proto__ = data
Wiki.location = localStorage['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"></div>
</body>
</html>
<!-- vim:set sw=4 ts=4 : -->