| 
									
										
										
										
											2016-07-04 19:51:37 +03:00
										 |  |  | <!DOCTYPE html> | 
					
						
							|  |  |  | <html> | 
					
						
							| 
									
										
										
										
											2016-07-07 05:27:03 +03:00
										 |  |  | <head> | 
					
						
							|  |  |  | <title>pWiki</title> | 
					
						
							|  |  |  | </head> | 
					
						
							| 
									
										
										
										
											2016-07-04 19:51:37 +03:00
										 |  |  | <style> | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script src="ext-lib/jquery.js"></script> | 
					
						
							| 
									
										
										
										
											2016-07-12 03:22:06 +03:00
										 |  |  | <script src="ext-lib/pouchdb.min.js"></script> | 
					
						
							| 
									
										
										
										
											2016-07-04 19:51:37 +03:00
										 |  |  | <script src="wiki.js"></script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var clear = () => { | 
					
						
							|  |  |  | 	delete localStorage['wiki-data'] | 
					
						
							|  |  |  | 	delete localStorage['wiki-location'] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 04:32:56 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | var reload = () => { | 
					
						
							| 
									
										
										
										
											2016-07-11 18:41:23 +03:00
										 |  |  | 	$('.path').text('/' + Wiki.path) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	$('.title').text(Wiki.title) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 	// process text... | 
					
						
							|  |  |  | 	var text = Wiki.text | 
					
						
							| 
									
										
										
										
											2016-07-10 05:14:36 +03:00
										 |  |  | 	var editing = $('.text').prop('contenteditable') != 'true' | 
					
						
							|  |  |  | 	var filters = [] | 
					
						
							| 
									
										
										
										
											2016-07-11 04:32:56 +03:00
										 |  |  | 	var slots = {} | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// expand macros... | 
					
						
							| 
									
										
										
										
											2016-07-10 05:14:36 +03:00
										 |  |  | 	if(editing){ | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 		text = text | 
					
						
							|  |  |  | 			// Syntax: | 
					
						
							|  |  |  | 			//		@<macro>( <args> ) | 
					
						
							|  |  |  | 			.replace(/@([a-zA-Z-_]+)\(([^)]*)\)/g, function(_, macro, args){ | 
					
						
							|  |  |  | 				args = $('<div>') | 
					
						
							|  |  |  | 					.html(args) | 
					
						
							|  |  |  | 					.text() | 
					
						
							|  |  |  | 						.trim() | 
					
						
							|  |  |  | 						.split(/\s+/g) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				//console.log('>>>>>', macro, args) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 04:30:52 +03:00
										 |  |  | 				if(macro == 'filter' && args.length == 1){ | 
					
						
							| 
									
										
										
										
											2016-07-10 05:14:36 +03:00
										 |  |  | 					filters.push(args[0]) | 
					
						
							| 
									
										
										
										
											2016-07-10 04:30:52 +03:00
										 |  |  | 					return '' | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 				if(macro == 'include' && args.length == 1){ | 
					
						
							|  |  |  | 					w = Object.create(Wiki) | 
					
						
							|  |  |  | 					w.location = args[0] | 
					
						
							|  |  |  | 					return w.text | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 03:29:53 +03:00
										 |  |  | 				if(macro == 'attr'  | 
					
						
							|  |  |  | 						&& args.length == 1 | 
					
						
							|  |  |  | 						&& ['title', 'path', 'location', 'dir'].indexOf(args[0]) >= 0){ | 
					
						
							|  |  |  | 					return Wiki[args[0]] | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 				return _ | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			// html-like macro syntax... | 
					
						
							|  |  |  | 			.replace(/\<[a-zA-Z-_:]+.*?\/?\>/g, function(t){ | 
					
						
							|  |  |  | 				var elem = $($('<div>').html(t).text()) | 
					
						
							|  |  |  | 				var macro = elem.prop('tagName').toLowerCase() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var args = {} | 
					
						
							|  |  |  | 				var a = elem.prop('attributes') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				for(var i=0; i<a.length; i++){ | 
					
						
							|  |  |  | 					args[a[i].name] = a[i].value | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				//console.log('>>>>>', macro, args)  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 04:30:52 +03:00
										 |  |  | 				if(macro == 'filter' && args.name != null){ | 
					
						
							|  |  |  | 					console.log('FILTER:', args.name) | 
					
						
							|  |  |  | 					// XXX | 
					
						
							|  |  |  | 					return '' | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 				if(macro == 'include' && args.src != null){ | 
					
						
							|  |  |  | 					w = Object.create(Wiki) | 
					
						
							|  |  |  | 					w.location = args.src | 
					
						
							|  |  |  | 					return w.text | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 04:32:56 +03:00
										 |  |  | 				// XXX need content... | 
					
						
							|  |  |  | 				// 		Procedure: | 
					
						
							|  |  |  | 				//			- if new slot | 
					
						
							|  |  |  | 				//				- add to list | 
					
						
							|  |  |  | 				//				- fill | 
					
						
							|  |  |  | 				//			- if slot exists | 
					
						
							|  |  |  | 				//				- fill original | 
					
						
							|  |  |  | 				if(macro == 'slot' && args.name != null){ | 
					
						
							|  |  |  | 					slots[args.name] = '' | 
					
						
							|  |  |  | 					return t | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 03:29:53 +03:00
										 |  |  | 				if(macro == 'attr'  | 
					
						
							|  |  |  | 						&& args.name != null | 
					
						
							|  |  |  | 						&& ['title', 'path', 'location', 'dir'].indexOf(args.name) >= 0){ | 
					
						
							|  |  |  | 					return Wiki[args.name] | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				return t | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 05:14:36 +03:00
										 |  |  | 	$('.text').html(activateWikiWords(text, filters.indexOf('show_link_brackets') < 0 && editing)) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// XXX save... | 
					
						
							|  |  |  | 	localStorage['wiki-data'] = JSON.stringify(Wiki.__wiki_data) | 
					
						
							|  |  |  | 	localStorage['wiki-location'] = Wiki.location | 
					
						
							| 
									
										
										
										
											2016-07-07 05:27:03 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	$('title').text(Wiki.location) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var go = (path) => { | 
					
						
							| 
									
										
										
										
											2016-07-07 05:27:03 +03:00
										 |  |  | 	history.pushState({ | 
					
						
							|  |  |  | 			wikipath: path | 
					
						
							|  |  |  | 		},  | 
					
						
							|  |  |  | 		Wiki.title,  | 
					
						
							|  |  |  | 		window.location) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 	Wiki.location = path | 
					
						
							|  |  |  | 	reload() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var clearWikiWords = elem => { | 
					
						
							|  |  |  | 	// clear existing... | 
					
						
							|  |  |  | 	elem.find('.WikiWord').each(function(){ | 
					
						
							| 
									
										
										
										
											2016-07-10 05:14:36 +03:00
										 |  |  | 		$(this).attr('braced') == 'yes' ?  | 
					
						
							|  |  |  | 			$(this).replaceWith(['['].concat(this.childNodes, [']'])) | 
					
						
							|  |  |  | 			: $(this).replaceWith(this.childNodes) | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 	return elem | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 05:14:36 +03:00
										 |  |  | var activateWikiWords = (text, show_brackets) =>  | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 	text | 
					
						
							|  |  |  | 		// set new... | 
					
						
							|  |  |  | 		.replace( | 
					
						
							| 
									
										
										
										
											2016-07-09 19:16:25 +03:00
										 |  |  | 			Wiki.__wiki_link__, | 
					
						
							| 
									
										
										
										
											2016-07-10 05:14:36 +03:00
										 |  |  | 			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>' | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(() => { | 
					
						
							| 
									
										
										
										
											2016-07-07 05:27:03 +03:00
										 |  |  | 	$(window).on('popstate', function(evt){ | 
					
						
							|  |  |  | 		event.state  | 
					
						
							|  |  |  | 			&& event.state.wikipath  | 
					
						
							|  |  |  | 			&& go(event.state.wikipath) | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 	// load stored data... | 
					
						
							|  |  |  | 	Wiki.__wiki_data = localStorage['wiki-data'] ? | 
					
						
							|  |  |  | 		JSON.parse(localStorage['wiki-data'])  | 
					
						
							|  |  |  | 		: data | 
					
						
							| 
									
										
										
										
											2016-07-11 19:22:00 +03:00
										 |  |  | 	Wiki.__wiki_data.__proto__ = data | 
					
						
							| 
									
										
										
										
											2016-07-09 21:40:48 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 	Wiki.location = localStorage['wiki-location'] || Wiki.location | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-09 21:40:48 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 	reload() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-08 01:40:59 +03:00
										 |  |  | 	// XXX make this update on enter... | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 	$('.title') | 
					
						
							| 
									
										
										
										
											2016-07-08 01:40:59 +03:00
										 |  |  | 		.on('blur', () => {  | 
					
						
							|  |  |  | 			Wiki.title = $('.title').text()  | 
					
						
							|  |  |  | 			reload() | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// live update text... | 
					
						
							|  |  |  | 	// XXX is this the right way to go for large documents??? | 
					
						
							|  |  |  | 	$('.text') | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 		.focus(() => { | 
					
						
							|  |  |  | 			$('.text').prop('contenteditable', $('.text').prop('contenteditable') != 'true') | 
					
						
							|  |  |  | 			reload() | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 		.on('keyup', () => {  | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 			if($('.text').prop('contenteditable') == 'true'){ | 
					
						
							| 
									
										
										
										
											2016-07-12 03:22:06 +03:00
										 |  |  | 				Wiki.raw = clearWikiWords($('.text').clone()).html()  | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 		// XXX do this live, but on a timeout after user input... | 
					
						
							|  |  |  | 		// XXX need to place the cursor in the same position... | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | 		.blur(() => {  | 
					
						
							|  |  |  | 			$('.text').prop('contenteditable', false) | 
					
						
							|  |  |  | 			reload()  | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2016-07-04 19:51:37 +03:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <body> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 18:41:23 +03:00
										 |  |  | <div class="path"></div> | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | <hr> | 
					
						
							| 
									
										
										
										
											2016-07-08 01:40:59 +03:00
										 |  |  | <h1 class="title" contenteditable tabindex=0></h1> | 
					
						
							| 
									
										
										
										
											2016-07-10 02:41:31 +03:00
										 |  |  | <div class="text" tabindex=0></div> | 
					
						
							| 
									
										
										
										
											2016-07-04 19:51:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | </body> | 
					
						
							|  |  |  | </html> | 
					
						
							| 
									
										
										
										
											2016-07-05 03:25:47 +03:00
										 |  |  | <!-- vim:set sw=4 ts=4 : --> |