PageRenderTime 34ms CodeModel.GetById 24ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/assets/wiki.html

https://bitbucket.org/saibotd/bitbeaker/
HTML | 87 lines | 80 code | 6 blank | 1 comment | 0 complexity | bee71616642b4b3b32c07f72a3b3a421 MD5 | raw file
 1<!DOCTYPE html>
 2<html>
 3<head>
 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 5<title>Wiki</title>
 6<script type="text/javascript" src="file:///android_asset/creole.js"></script>
 7<script type="text/javascript" src="file:///android_asset/markdown.js"></script>
 8<script type="text/javascript" src="file:///android_asset/textile.js"></script>
 9</head>
10<body>
11<select id="markup">
12	<option value="plain">Plain text</option>
13	<option value="markdown">Markdown</option>
14	<option value="creole">Creole</option>
15	<!--<option value="rest">reStructuredText</option>-->
16	<option value="textile">Textile</option>
17</select>
18<a id="home" href="">Wiki Home</a>
19<div id="wiki"></div>
20<pre id="wiki_plain"></pre>
21<script language="javascript">
22	var data = bitbeaker.getData();
23	var markup = document.getElementById("markup");
24	markup.addEventListener('change', changeMarkup, false);
25
26	var div = document.getElementById('wiki');
27	var pre = document.getElementById('wiki_plain');
28
29	document.getElementById('home').href = bitbeaker.getWikiHomeUrl();
30
31	// called from WikiActivity when page has finished loading
32	function updateDropdownMenu() {
33		var tmp = bitbeaker.getMarkup();
34		if (tmp == "markdown" || tmp == "creole" /*|| tmp == "rest" */|| tmp == "textile")
35			markup.value = tmp;
36		else markup.value = "plain";
37
38		// trigger change event manually, http://stackoverflow.com/a/2856602/262462
39		var evt = document.createEvent("HTMLEvents");
40		evt.initEvent("change", false, true);
41		markup.dispatchEvent(evt);
42	}
43
44	function changeMarkup() {
45		if (markup.value == "plain") {
46			pre.innerHTML = data;
47			div.innerHTML = "";
48		}
49		else if (markup.value == "markdown") {
50			pre.innerHTML = "";
51			div.innerHTML = markdown.toHTML(data);
52			fixLinks();
53		}
54		else if (markup.value == "creole") {
55			pre.innerHTML = "";
56			div.innerHTML = "";
57			var creole = new Parse.Simple.Creole();
58			creole.parse(div, data);
59			fixLinks();
60		}
61		/*else if (markup.value == "rest") {
62			//TODO
63		}*/
64		else if (markup.value == "textile") {
65			pre.innerHTML = "";
66			div.innerHTML = textile(data);
67			fixLinks();
68		}
69	}
70
71	function fixLinks() {
72		var links = div.getElementsByTagName("a");
73		for (i=0; i<links.length; i++) {
74			// add prefix to local URLs (not starting with "http")
75			// but leave anchor links as is
76			if (links[i].href.substring(0,4) != "http" &&
77				links[i].href.substring(0,32) != "file:///android_asset/wiki.html#") {
78					links[i].href = bitbeaker.getWikiHomeUrl() + links[i].href.replace("file:///android_asset/","");
79			}
80			if (links[i].href.substring(0,25) == "https://bitbucket.org/api") {
81				links[i].href = links[i].href.replace(/%20/g,"_");
82			}
83		}
84	}
85</script>
86</body>
87</html>