cleanup and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-09-17 19:39:39 +03:00
parent 6f73dda91e
commit 5c45fbc5c6

View File

@ -111,10 +111,15 @@ body.loading .page.spinner span {
<!--script data-main="pwiki2" src="ext-lib/require.js"></script-->
<script src="ext-lib/require.js"></script>
<script>
//---------------------------------------------------------------------
var DEBUG = true
//---------------------------------------------------------------------
// Module loading...
var makeFallbacks =
function(paths, search=['lib']){
return Object.entries(paths)
@ -135,7 +140,7 @@ function(paths, search=['lib']){
res[key] = value
return res }, {}) }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
require.config({
paths: {
...makeFallbacks({
@ -164,11 +169,47 @@ require.config({
})
document.pwikiloaded = new Event('pwikiloaded')
//---------------------------------------------------------------------
// Editor -- save changes...
// XXX versioning??
var SAVE_TIMEOUT = 5000
var SAVE_QUEUE = {}
var saveContent =
function(path, text){
SAVE_QUEUE[path] = text
// clear editor page cache...
pwiki.cache = null }
var saveNow =
function(){
var queue = Object.entries(SAVE_QUEUE)
SAVE_QUEUE = {}
queue
.forEach(function([path, text]){
console.log('saving changes to:', path)
pwiki.get(path).raw = text }) }
setInterval(saveNow, 5000)
//---------------------------------------------------------------------
// Spinner/loading...
// loading spinner...
window.startSpinner = function(){
document.body.classList.add('loading') }
window.stopSpinner = function(){
document.body.classList.remove('loading') }
//---------------------------------------------------------------------
// General setup...
REFRESH_DELAY = 20
// helper...
document.pwikiloaded = new Event('pwikiloaded')
var logTime = async function(promise, msg=''){
var t = Date.now()
var res = await promise
@ -181,9 +222,11 @@ var logTime = async function(promise, msg=''){
} (${t}ms)`)
return res }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// start loading pWiki...
require(['./browser'], function(browser){
pwiki = window.pwiki = browser.pwiki
var pwiki = window.pwiki = browser.pwiki
pwiki.dom = document.querySelector('#pWiki')
// handle location.hash/history (both directions)
@ -249,30 +292,9 @@ require(['./browser'], function(browser){
pwiki.location = decodeURI(location.hash).slice(1) }) })
// XXX versioning??
var SAVE_TIMEOUT = 5000
var SAVE_QUEUE = {}
var saveContent =
function(path, text){
SAVE_QUEUE[path] = text
// clear editor page cache...
pwiki.cache = null }
var saveNow =
function(){
var queue = Object.entries(SAVE_QUEUE)
SAVE_QUEUE = {}
queue
.forEach(function([path, text]){
console.log('saving changes to:', path)
pwiki.get(path).raw = text }) }
setInterval(saveNow, 5000)
// loading spinner...
window.startSpinner = function(){
document.body.classList.add('loading') }
window.stopSpinner = function(){
document.body.classList.remove('loading') }
//---------------------------------------------------------------------
// Export...
// XXX
var exportData = async function(){
@ -290,7 +312,7 @@ var exportData = async function(){
//---------------------------------------------------------------------
</script>
<body>