| 
									
										
										
										
											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> | 
					
						
							|  |  |  | <script src="wiki.js"></script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var clear = () => { | 
					
						
							|  |  |  | 	delete localStorage['wiki-data'] | 
					
						
							|  |  |  | 	delete localStorage['wiki-location'] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var reload = () => { | 
					
						
							|  |  |  | 	$('.dir').text('/' + Wiki.dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('.title').text(Wiki.title) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('.text').html(activateWikiWords(Wiki.text)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 05:27:03 +03:00
										 |  |  | // XXX add history support... | 
					
						
							| 
									
										
										
										
											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(){ | 
					
						
							|  |  |  | 			$(this).replaceWith(this.childNodes)}) | 
					
						
							|  |  |  | 	return elem | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var activateWikiWords = text =>  | 
					
						
							|  |  |  | 	text | 
					
						
							|  |  |  | 		// set new... | 
					
						
							|  |  |  | 		.replace( | 
					
						
							|  |  |  | 			RegExp('('+[ | 
					
						
							| 
									
										
										
										
											2016-07-06 17:30:51 +03:00
										 |  |  | 				'[A-Z][a-z0-9]+[A-Z\/][a-zA-Z0-9\/]*', | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 				'\\[[^\\]]+\\]', | 
					
						
							|  |  |  | 				].join('|') +')', 'g'), | 
					
						
							|  |  |  | 			'<a class="WikiWord" href="#" onclick="go($(this).text().replace(/^\\[|\\]$/g, \'\'))">$1</a>') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(() => { | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 	Wiki.location = localStorage['wiki-location'] || Wiki.location | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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') | 
					
						
							|  |  |  | 		.on('keyup', () => {  | 
					
						
							|  |  |  | 			Wiki.text = 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(() => { reload() }) | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2016-07-04 19:51:37 +03:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <body> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | <div class="dir"></div> | 
					
						
							|  |  |  | <hr> | 
					
						
							| 
									
										
										
										
											2016-07-08 01:40:59 +03:00
										 |  |  | <h1 class="title" contenteditable tabindex=0></h1> | 
					
						
							|  |  |  | <div class="text" contenteditable 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 : --> |