pWiki/pwiki2.html
Alex A. Naanou 617dac9ce3 reworked .paths(), now it will search subpaths too...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2022-08-06 11:09:25 +03:00

150 lines
3.8 KiB
HTML
Executable File

<!DOCTYPE html>
<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>
<!-- XXX do we need this??? -->
<script src="bootstrap.js"></script>
<!--script data-main="pwiki2" src="ext-lib/require.js"></script-->
<script src="ext-lib/require.js"></script>
<script>
var makeFallbacks =
function(paths, search=['lib']){
return Object.entries(paths)
.map(function([key, path]){
// package...
if(path.endsWith('/')){
return [key, path] }
return [
key,
[
path,
...search
.map(function(base){
return base +'/'+ path.split(/[\\\/]+/g).pop() }),
]
] })
.reduce(function(res, [key, value]){
res[key] = value
return res }, {}) }
require.config({
paths: {
...makeFallbacks({
'ig-doc': 'node_modules/ig-doc/doc',
'ig-stoppable': 'node_modules/ig-stoppable/stoppable',
'object-run': 'node_modules/object-run/run',
'ig-object': 'node_modules/ig-object/object',
}),
// packages...
'ig-types': [
'node_modules/ig-types',
'lib/types',
],
// external stuff...
...makeFallbacks({
'jszip': 'node_modules/jszip/dist/jszip',
'pouchdb': 'node_modules/pouchdb/dist/pouchdb',
'showdown': 'node_modules/showdown/dist/showdown',
}, ['ext-lib']),
},
packages: [
'ig-types',
]
})
document.pwikiloaded = new Event('pwikiloaded')
// start loading pWiki...
require(['./browser'], function(m){
window.pwiki = m.pwiki
// XXX make a pWikiDom page to manage this...
pwiki.dom = document.querySelector('#pWiki')
// handle location.hash (both directions)
var _debounceHashChange = false
pwiki.onNavigate(async function(){
// update location.hash without retriggering...
_debounceHashChange = true
location.hash = this.path
setTimeout(function(){
_debounceHashChange = false }, 0)
// render...
pwiki.dom.innerHTML = await this.text
// pwiki page loaded event...
// XXX do we need to use a MutationObserver here to trigger this
// after the above is done loading???
// (see: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
pwiki.dom.dispatchEvent(document.pwikiloaded) })
window.addEventListener('hashchange', function(evt){
evt.preventDefault()
if(_debounceHashChange){
return }
var [path, hash] = location.hash.slice(1).split('#')
path = path.trim() == '' ?
'/'
: path
pwiki.path = path
// XXX when loaded us <elem>.scrollIntoView() to get to hash...
// ...would also be nice to keep hash within location.hash...
})
// XXX use a pwiki.onLoad event...
pwiki.dom.addEventListener('pwikiloaded', function(evt){
console.log('pWiki loaded')
// XXX scroll
})
// show current page...
pwiki.path = location.hash.slice(1)
})
</script>
<body>
<div id="pWiki" />
</body>
</html>
<!-- vim:set sw=4 ts=4 : -->