reader.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <!DOCTYPE html>
  2. <meta name="apple-mobile-web-app-capable" content="yes" />
  3. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=0.8, maximum-scale=0.8"/>
  4. <html>
  5. <head>
  6. <meta charset="utf-8">
  7. <title>arozos Documentation</title>
  8. <!-- Tocas UI:CSS 與元件 -->
  9. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.css">
  10. <!-- Tocas JS:模塊與 JavaScript 函式 -->
  11. <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  12. <script src="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.js"></script>
  13. <link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
  14. <script src="../../showdown.min.js"></script>
  15. <style>
  16. p,div,span,h1,h2,h3,h4,h5{
  17. font-family: 'Raleway', sans-serif;
  18. }
  19. .specialpadding{
  20. margin-top:0px !important;
  21. padding-left:20px;
  22. }
  23. .rightPadded{
  24. position:absolute !important;
  25. right:10px;
  26. width:55px;
  27. }
  28. img{
  29. max-width:100%;
  30. }
  31. .selectable{
  32. cursor:pointer;
  33. padding:5px;
  34. padding-left:10px !important;
  35. margin:0px !important;
  36. }
  37. .selectable:hover{
  38. background-color:#f2f2f2;
  39. }
  40. pre{
  41. background-color: #1c1c1c;
  42. color: white;
  43. padding: 10px;
  44. overflow-x: auto;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <div class="ts demo left sidebar" style="width:400px !important;">
  50. <div class="ts header">
  51. ArozOS Documentation
  52. <div id="lang" class="sub header" href="index.html"></div>
  53. </div>
  54. <div class="ts top attached tabbed menu">
  55. <a id="doclist" class="active item" onClick="toggleMode('doclist');"><i class="bookmark icon"></i></a>
  56. <a id="starlist" class="item" onClick="toggleMode('stars');"><i class="star icon"></i></a>
  57. </div>
  58. <div id="pageContent" class="ts active bottom attached tab segment">
  59. </div>
  60. <div style="width:100%;" align="right">
  61. <a href="../../index.html">Exit <i class="log out icon"></i></a>
  62. </div>
  63. </div>
  64. <div class="pusher">
  65. <br><br>
  66. <div class="ts container">
  67. <div class="ts basic segment">
  68. <div class="ts icon buttons">
  69. <button id="backbtn" class="ts basic button" onClick="lastPage();"><i class="arrow left icon"></i></button>
  70. <button id="nextbtn" class="ts basic button" onClick="reloadAllDocs();"><i class="refresh icon"></i></button>
  71. <button id="nextbtn" class="ts basic button" onClick="nextPage();"><i class="arrow right icon"></i></button>
  72. <button id="nextbtn" class="ts basic button" onClick="toggleList();"><i class="content icon"></i></button>
  73. <div class="ts specialpadding header"><i class="bookmark icon"></i><span id="readerTitle">Welcome to ArOZ Online Documentation Reader</span></div>
  74. </div>
  75. <button id="starBtn" class="ts rightPadded warning button" onClick="starThisPage();" title="Save this page"><i class="empty star icon"></i></button>
  76. </div>
  77. <div class="ts divider"></div>
  78. <div id="docLoader" class="ts basic segment">
  79. </div>
  80. <div class="ts divider"></div>
  81. <div class="ts basic segment">
  82. ArOZ Documentation Reader v1.2
  83. </div>
  84. <br><br><br><br>
  85. </div>
  86. </div>
  87. <script>
  88. var currentRenderPage = 0;
  89. var searchingPage = 0;
  90. var state; //get lang id
  91. var docs = []; //All documents will be loaded into memory as the reader loads, but not rendered yet
  92. var docsTitles = [];
  93. var rootFolder = "../../chapter/";
  94. var baseFolder = rootFolder + "default/";
  95. var sidebarMode = "index"; //Either index or stars
  96. var staredPages = [];
  97. //Parse the system state from hash
  98. if (window.location.hash.length > 1){
  99. try{
  100. state = JSON.parse(decodeURIComponent(window.location.hash.substr(1)));
  101. baseFolder = rootFolder + state.chapter + "/";
  102. let targetPageNumber = state.page;
  103. initLoad(function(){
  104. //Callback after all document loaded.
  105. if (targetPageNumber != undefined){
  106. currentRenderPage = state.page;
  107. readDoc();
  108. }
  109. });
  110. $("#lang").text("Chapter: " + state.chapter);
  111. //Check if there are stared pages. If yes, load them
  112. if (localStorage.getItem(state.chapter) !== null) {
  113. staredPages = JSON.parse(localStorage.getItem(state.chapter));
  114. }
  115. }catch(ex){
  116. alert("Failed to parse chapter information")
  117. }
  118. }
  119. function starThisPage(){
  120. for (var i =0; i < staredPages.length; i++){
  121. if (staredPages[i][0] == currentRenderPage){
  122. //This page is already started. Remove the star
  123. staredPages.splice(i,1);
  124. $("#starBtn").find("i").addClass("empty");
  125. $("#starBtn").removeClass("primary");
  126. localStorage.setItem(lang,JSON.stringify(staredPages));
  127. if (sidebarMode == "stars"){
  128. renderStarList();
  129. }
  130. return;
  131. }
  132. }
  133. //This page is not stared yet. Add it to list
  134. staredPages.push([currentRenderPage,docsTitles[currentRenderPage]]);
  135. console.log("[Page Saved] " + staredPages);
  136. $("#starBtn").find("i").removeClass("empty");
  137. $("#starBtn").addClass("primary");
  138. localStorage.setItem(lang,JSON.stringify(staredPages));
  139. if (sidebarMode == "stars"){
  140. renderStarList();
  141. }
  142. }
  143. function updateStartedIcon(){
  144. for (var i =0; i < staredPages.length; i++){
  145. if (staredPages[i][0] == currentRenderPage){
  146. $("#starBtn").find("i").removeClass("empty");
  147. $("#starBtn").addClass("primary");
  148. return;
  149. }
  150. }
  151. $("#starBtn").find("i").addClass("empty");
  152. $("#starBtn").removeClass("primary");
  153. }
  154. function toggleMode(mode){
  155. if (mode == "stars"){
  156. $("#doclist").removeClass("active");
  157. $("#starlist").addClass("active");
  158. renderStarList();
  159. sidebarMode = "stars";
  160. }else{
  161. $("#starlist").removeClass("active");
  162. $("#doclist").addClass("active");
  163. renderDocsList();
  164. sidebarMode = "index";
  165. }
  166. }
  167. function renderStarList(){
  168. $("#pageContent").html("");
  169. for (var i = 0; i < staredPages.length; i++){
  170. var page = staredPages[i][0];
  171. var title = staredPages[i][1];
  172. $("#pageContent").append('<p class="selectable" onClick="redirectDoc(' + page + ');"><i class="bookmark icon"></i> ' + title + '</p>');
  173. }
  174. if (staredPages.length == 0){
  175. $("#pageContent").append('<p class=""><i class="remove icon"></i> No bookmark</p>');
  176. }
  177. }
  178. function toggleList(){
  179. ts('.left.sidebar:not(.inverted)').sidebar({
  180. dimPage: true,
  181. scrollLock: true
  182. }).sidebar('toggle');
  183. }
  184. function redirectDoc(indexID){
  185. currentRenderPage = indexID;
  186. readDoc(true);
  187. toggleList();
  188. }
  189. function renderDocsList(){
  190. $("#pageContent").html("");
  191. for (var i =0; i < docsTitles.length; i++){
  192. $("#pageContent").append('<p class="selectable" onClick="redirectDoc(' + i + ');"><i class="book icon"></i> ' + docsTitles[i] + '</p>');
  193. }
  194. }
  195. function reloadAllDocs(){
  196. docs = [];
  197. searchingPage = 0;
  198. initLoad();
  199. docsTitles=[];
  200. }
  201. function loadAllDocs(callback=undefined){
  202. $.ajax({
  203. type: 'get',
  204. timeout: 5000,
  205. url: baseFolder + searchingPage + ".md",
  206. success: function(data, textStatus, XMLHttpRequest){
  207. data = data.split("\r\n").join("\n");
  208. docs.push(data.split("\n"));
  209. //console.log(data.split("\n"));
  210. searchingPage++;
  211. loadAllDocs(callback);
  212. },
  213. error:function (xhr, ajaxOptions, thrownError){
  214. //End of documentation
  215. //console.log(docs);
  216. readDoc(); //Start rendering
  217. parseDocList(); //Update the doc list
  218. renderDocsList(); //Render the documentation list
  219. if (callback != undefined){
  220. callback();
  221. }
  222. }
  223. });
  224. }
  225. function nextPage(){
  226. currentRenderPage = currentRenderPage + 1;
  227. if (currentRenderPage >= docs.length){
  228. //No more pages
  229. currentRenderPage = currentRenderPage - 1;
  230. return;
  231. }
  232. readDoc(true);
  233. }
  234. function lastPage(){
  235. currentRenderPage = currentRenderPage - 1;
  236. if (currentRenderPage < 0){
  237. //No more pages
  238. currentRenderPage = currentRenderPage + 1;
  239. return;
  240. }
  241. readDoc(true);
  242. }
  243. function readDoc(rememberState=false){
  244. let pageInfo = Array.from(docs[currentRenderPage]);
  245. var metaTag = JSON.parse(pageInfo.shift());
  246. document.title = metaTag[0];
  247. $("#readerTitle").text(metaTag[0]);
  248. $("#docLoader").html("");
  249. pageInfo = pageInfo.join("\n");
  250. $("#docLoader").append(md2html(pageInfo));
  251. updateStartedIcon();
  252. if (rememberState){
  253. updateWindowHash();
  254. }
  255. }
  256. function updateWindowHash(){
  257. state["page"] = currentRenderPage;
  258. window.location.hash = encodeURIComponent(JSON.stringify(state))
  259. }
  260. function parseDocList(){
  261. for (var i =0; i < docs.length; i++){
  262. let pageInfo = Array.from(docs[i]);
  263. var metaTag = JSON.parse(pageInfo.shift());
  264. docsTitles.push(metaTag[0]);
  265. }
  266. }
  267. function md2html(input){
  268. var converter = new showdown.Converter({
  269. tables: true,
  270. });
  271. return converter.makeHtml(input);
  272. }
  273. //Initiate the loading interface
  274. function initLoad(callback){
  275. $("#docLoader").html('<div align="center" style="width:100%;">\
  276. <br><br>\
  277. <i class="big spinner loading icon stillLoading"></i><br>\
  278. <p class="loadFailMsg">Loading...</p>\
  279. <br><br>\
  280. </div>');
  281. setTimeout(chkLoadFail,15000);
  282. loadAllDocs(callback);
  283. }
  284. //Check if the load failed using setTimeout
  285. function chkLoadFail(){
  286. if ($(".stillLoading").length > 0){
  287. //Something screwed up during loading of JSON based documentation. Ask for refresh
  288. $(".stillLoading").removeClass("spinner").removeClass("loading").addClass("remove");
  289. $(".loadFailMsg").text("Seems something went wrong. Try refreshing the page?");
  290. }
  291. }
  292. </script>
  293. </body>
  294. </html>