From 82d9cb4d8a052429b0a818c374e177c7dd748b44 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 22 Jul 2016 23:42:34 +0300 Subject: [PATCH] tweaking... Signed-off-by: Alex A. Naanou --- index.html | 41 ++++++++++++++++++++++------------------- wiki.js | 39 +++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/index.html b/index.html index c3efff3..2fdb382 100755 --- a/index.html +++ b/index.html @@ -21,7 +21,8 @@ var clear = () => { var reload = () => { $('.wiki') - .html(Wiki.get('./_view').text) + .html(Wiki.title[0] == '_' ? Wiki.text : Wiki.get('./_view').text) + .ready(update_editor) // XXX save... localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data) @@ -34,28 +35,33 @@ var update_editor = function(){ // XXX make this update on enter... $('.title') .on('blur', () => { - Wiki.title = $('.title').text() - reload() + //Wiki.title = $('.title').text() + //reload() }) // live update text... // XXX is this the right way to go for large documents??? $('.text') - .focus(() => { - console.log('EDITING...') - $('.text').prop('contenteditable', $('.text').prop('contenteditable') != 'true') - reload() + .focus(function(){ + console.log('EDITING:', Wiki.path) + + $(this) + .prop('contenteditable', 'true') + .html(Wiki.raw) + + //reload() }) .on('keyup', () => { - if($('.text').prop('contenteditable') == 'true'){ - Wiki.raw = clearWikiWords($('.text').clone()).html() - } + console.log('SAVING:', Wiki.path) + //if($(this).prop('contenteditable') == 'true'){ + // Wiki.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(() => { - $('.text').prop('contenteditable', false) - reload() + $(this).removeAttr('contenteditable') + //reload() }) } @@ -65,13 +71,14 @@ var go = (path) => { path = path.trim() path = path[0] == '[' ? path.slice(1, -1) : path + Wiki.location = path + history.pushState({ - wikipath: path + wikipath: Wiki.location }, Wiki.title, window.location) - Wiki.location = path reload() } @@ -95,6 +102,7 @@ $(() => { //update_editor() + // XXX need to resolve relative hashes... $(window).on('hashchange', function(evt){ evt.preventDefault() @@ -116,11 +124,6 @@ $(() => {
- - diff --git a/wiki.js b/wiki.js index c29ef16..d312ed5 100755 --- a/wiki.js +++ b/wiki.js @@ -45,20 +45,18 @@ var setWikiWords = function(text, show_brackets, skip){ var path = l[0] == '[' ? l.slice(1, -1) : l var i = [].slice.call(arguments).slice(-2)[0] - /* // XXX HACK check if we are inside a tag... var rest = text.slice(i+1) if(rest.indexOf('>') < rest.indexOf('<')){ return l } - //*/ return skip.indexOf(l) < 0 ? ('' + (!!show_brackets ? path : l) +'') @@ -442,34 +440,43 @@ var BaseData = { // XXX add .json support... var data = { 'Templates/EmptyPage': { - text: 'Page @include(./path) is empty.' +'

' - +'Links to this page:' +'
' - +'@include(./links)' +'

' - +'---' +'
' - +'WikiHome', + text: '' + +'\n' + +'\n' + +'Page @include(./path) is empty.' +'

\n' + +'\n' + +'Links to this page:' +'
\n' + +'@include(./links)' +'

\n' + +'\n', }, + 'Templates/_raw': { + text: '@source(..)', + }, 'Templates/_view': { text: '\n' - +'
@include(../path) ([../_edit])
\n' + +'\n' + +'\n' + +'
/@include(../path) (edit)
\n' +'
\n' +'

@include(../title)

\n' +'
\n' +'
@include(..)
\n' - +'\n' + +'
\n' + +'home\n' +'\n', }, 'Templates/_edit': { text: '\n' - +'
/@include(../path) ([../_view])
\n' + +'\n' + +'\n' + +'
/@include(../path) (view)
\n' +'
\n' - +'

@include(../title)

\n' + +'

@include(../title)

\n' +'
\n' - +'
@include(../raw)
\n' + +'
@source(../raw)
\n' +'\n' +'', },