| 
									
										
										
										
											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-22 21:46:23 +03:00
										 |  |  | <script src="ext-lib/peer.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'] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var reload = () => { | 
					
						
							| 
									
										
										
										
											2016-07-20 05:47:37 +03:00
										 |  |  | 	$('.wiki') | 
					
						
							| 
									
										
										
										
											2016-07-22 23:42:34 +03:00
										 |  |  | 		.html(Wiki.title[0] == '_' ? Wiki.text : Wiki.get('./_view').text) | 
					
						
							|  |  |  | 		.ready(update_editor) | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 05:47:37 +03:00
										 |  |  | var update_editor = function(){ | 
					
						
							|  |  |  | 	// XXX make this update on enter... | 
					
						
							|  |  |  | 	$('.title') | 
					
						
							|  |  |  | 		.on('blur', () => {  | 
					
						
							| 
									
										
										
										
											2016-07-22 23:42:34 +03:00
										 |  |  | 			//Wiki.title = $('.title').text()  | 
					
						
							|  |  |  | 			//reload() | 
					
						
							| 
									
										
										
										
											2016-07-20 05:47:37 +03:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// live update text... | 
					
						
							|  |  |  | 	// XXX is this the right way to go for large documents??? | 
					
						
							|  |  |  | 	$('.text') | 
					
						
							| 
									
										
										
										
											2016-07-22 23:42:34 +03:00
										 |  |  | 		.focus(function(){ | 
					
						
							|  |  |  | 			console.log('EDITING:', Wiki.path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$(this) | 
					
						
							|  |  |  | 				.prop('contenteditable', 'true') | 
					
						
							|  |  |  | 				.html(Wiki.raw) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//reload() | 
					
						
							| 
									
										
										
										
											2016-07-20 05:47:37 +03:00
										 |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2016-07-23 05:04:38 +03:00
										 |  |  | 		.on('keyup', function(){  | 
					
						
							|  |  |  | 			if($(this).prop('contenteditable') == 'true'){ | 
					
						
							|  |  |  | 				var to = $(this).attr('saveto') || '.' | 
					
						
							|  |  |  | 				console.log('SAVING:', Wiki.get(to).path) | 
					
						
							| 
									
										
										
										
											2016-07-23 16:14:12 +03:00
										 |  |  | 				Wiki.get(to).raw = clearWikiWords($('.text').clone()).html()  | 
					
						
							| 
									
										
										
										
											2016-07-23 05:04:38 +03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-07-20 05:47:37 +03:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 		// XXX do this live, but on a timeout after user input... | 
					
						
							|  |  |  | 		// XXX need to place the cursor in the same position... | 
					
						
							|  |  |  | 		.blur(() => {  | 
					
						
							| 
									
										
										
										
											2016-07-23 05:04:38 +03:00
										 |  |  | 			$(this) | 
					
						
							|  |  |  | 				.removeAttr('contenteditable') | 
					
						
							|  |  |  | 			reload()  | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('.raw') | 
					
						
							|  |  |  | 		.focus(function(){ | 
					
						
							|  |  |  | 			var to = $(this).attr('saveto') || '.' | 
					
						
							|  |  |  | 			console.log('EDITING:', Wiki.get(to).path) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		.on('keyup', function(){  | 
					
						
							|  |  |  | 			var to = Wiki.get($(this).attr('saveto') || '.').path | 
					
						
							|  |  |  | 			console.log('SAVING:', to) | 
					
						
							|  |  |  | 			Wiki.get(to).raw = $(this).text() | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		// 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-20 05:47:37 +03:00
										 |  |  | 		}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | var go = (path) => { | 
					
						
							| 
									
										
										
										
											2016-07-20 05:47:37 +03:00
										 |  |  | 	console.log('GO:', path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-19 23:13:51 +03:00
										 |  |  | 	path = path.trim() | 
					
						
							|  |  |  | 	path = path[0] == '[' ? path.slice(1, -1) : path | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-22 23:42:34 +03:00
										 |  |  | 	Wiki.location = path | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-07 05:27:03 +03:00
										 |  |  | 	history.pushState({ | 
					
						
							| 
									
										
										
										
											2016-07-22 23:42:34 +03:00
										 |  |  | 			wikipath: Wiki.location | 
					
						
							| 
									
										
										
										
											2016-07-07 05:27:03 +03:00
										 |  |  | 		},  | 
					
						
							|  |  |  | 		Wiki.title,  | 
					
						
							|  |  |  | 		window.location) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | 	reload() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(() => { | 
					
						
							| 
									
										
										
										
											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-20 05:47:37 +03:00
										 |  |  | 	//update_editor() | 
					
						
							| 
									
										
										
										
											2016-07-22 21:46:23 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-22 23:42:34 +03:00
										 |  |  | 	// XXX need to resolve relative hashes... | 
					
						
							| 
									
										
										
										
											2016-07-22 21:46:23 +03:00
										 |  |  | 	$(window).on('hashchange', function(evt){ | 
					
						
							|  |  |  | 		evt.preventDefault() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var path = location.hash.slice(1) | 
					
						
							|  |  |  | 		var hash = path.split('#') | 
					
						
							|  |  |  | 		path = hash.shift() | 
					
						
							|  |  |  | 		hash = hash.pop() || '' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-23 05:04:38 +03:00
										 |  |  | 		// expand the path... | 
					
						
							|  |  |  | 		if(Wiki.get(path).path != path){ | 
					
						
							|  |  |  | 			location.hash = Wiki.get(path).path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// open page... | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			go(path) | 
					
						
							| 
									
										
										
										
											2016-07-22 21:46:23 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-23 05:04:38 +03:00
										 |  |  | 			if(hash.length > 0){ | 
					
						
							|  |  |  | 				// XXX focus anchor... | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-07-22 21:46:23 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2016-07-05 03:14:00 +03:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2016-07-04 19:51:37 +03:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <body> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 05:47:37 +03:00
										 |  |  | <div class="wiki"></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 : --> |