tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-07-10 05:14:36 +03:00
parent e10bdf83b0
commit 6539a7e949

View File

@ -23,9 +23,11 @@ var reload = () => {
// process text... // process text...
var text = Wiki.text var text = Wiki.text
var editing = $('.text').prop('contenteditable') != 'true'
var filters = []
// expand macros... // expand macros...
if($('.text').prop('contenteditable') != 'true'){ if(editing){
text = text text = text
// Syntax: // Syntax:
// @<macro>( <args> ) // @<macro>( <args> )
@ -39,8 +41,7 @@ var reload = () => {
//console.log('>>>>>', macro, args) //console.log('>>>>>', macro, args)
if(macro == 'filter' && args.length == 1){ if(macro == 'filter' && args.length == 1){
console.log('FILTER:', args[0]) filters.push(args[0])
// XXX
return '' return ''
} }
@ -94,7 +95,7 @@ var reload = () => {
}) })
} }
$('.text').html(activateWikiWords(text)) $('.text').html(activateWikiWords(text, filters.indexOf('show_link_brackets') < 0 && editing))
// XXX save... // XXX save...
localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data) localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data)
@ -103,7 +104,6 @@ var reload = () => {
$('title').text(Wiki.location) $('title').text(Wiki.location)
} }
// XXX add history support...
var go = (path) => { var go = (path) => {
history.pushState({ history.pushState({
wikipath: path wikipath: path
@ -118,16 +118,27 @@ var go = (path) => {
var clearWikiWords = elem => { var clearWikiWords = elem => {
// clear existing... // clear existing...
elem.find('.WikiWord').each(function(){ elem.find('.WikiWord').each(function(){
$(this).replaceWith(this.childNodes)}) $(this).attr('braced') == 'yes' ?
$(this).replaceWith(['['].concat(this.childNodes, [']']))
: $(this).replaceWith(this.childNodes)
})
return elem return elem
} }
var activateWikiWords = text => var activateWikiWords = (text, show_brackets) =>
text text
// set new... // set new...
.replace( .replace(
Wiki.__wiki_link__, Wiki.__wiki_link__,
'<a class="WikiWord" href="#" onclick="go($(this).text().replace(/^\\[|\\]$/g, \'\'))">$1</a>') function(l){
return '<a '
+'class="WikiWord" '
+'href="#" '
+'braced="'+ (show_brackets && l[0] == '[' ? 'yes' : 'no') +'"'
+'onclick="go($(this).text().replace(/^\\[|\\]$/g, \'\'))">'
+ (show_brackets && l[0] == '[' ? l.slice(1, -1) : l)
+'</a>'
})
$(() => { $(() => {