reader.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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>ArOZ Online System 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. <script src="showdown.min.js"></script>
  14. <style>
  15. .specialpadding{
  16. margin-top:0px !important;
  17. padding-left:20px;
  18. }
  19. .rightPadded{
  20. position:absolute !important;
  21. right:10px;
  22. width:55px;
  23. }
  24. img{
  25. max-width:100%;
  26. }
  27. .selectable{
  28. cursor:pointer;
  29. padding:5px;
  30. padding-left:10px !important;
  31. margin:0px !important;
  32. }
  33. .selectable:hover{
  34. background-color:#f2f2f2;
  35. }
  36. pre{
  37. background-color: #1c1c1c;
  38. color: white;
  39. padding: 10px;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div class="ts demo left sidebar" style="width:400px !important;">
  45. <div class="ts header">
  46. ArOZ Online System Documentation
  47. <div id="lang" class="sub header" href="index.html"></div>
  48. </div>
  49. <div class="ts top attached tabbed menu">
  50. <a id="doclist" class="active item" onClick="toggleMode('doclist');"><i class="bookmark icon"></i></a>
  51. <a id="starlist" class="item" onClick="toggleMode('stars');"><i class="star icon"></i></a>
  52. </div>
  53. <div id="pageContent" class="ts active bottom attached tab segment">
  54. </div>
  55. <div style="width:100%;" align="right">
  56. <a href="index.html">Exit <i class="log out icon"></i></a>
  57. </div>
  58. </div>
  59. <div class="pusher">
  60. <br><br>
  61. <div class="ts container">
  62. <div class="ts segment">
  63. <div class="ts icon buttons">
  64. <button id="backbtn" class="ts button" onClick="lastPage();"><i class="arrow left icon"></i></button>
  65. <button id="nextbtn" class="ts button" onClick="reloadAllDocs();"><i class="refresh icon"></i></button>
  66. <button id="nextbtn" class="ts button" onClick="nextPage();"><i class="arrow right icon"></i></button>
  67. <button id="nextbtn" class="ts button" onClick="toggleList();"><i class="content icon"></i></button>
  68. <div class="ts specialpadding header"><i class="bookmark icon"></i><span id="readerTitle">Welcome to ArOZ Online Documentation Reader</span></div>
  69. </div>
  70. <button id="starBtn" class="ts rightPadded button" onClick="starThisPage();"><i class="empty star icon"></i></button>
  71. </div>
  72. <div id="docLoader" class="ts segment">
  73. </div>
  74. <div class="ts segment">
  75. ArOZ Documentation Reader v1.0
  76. </div>
  77. <br><br><br><br>
  78. </div>
  79. </div>
  80. <script>
  81. var currentRenderPage = 0;
  82. var searchingPage = 0;
  83. var lang = window.location.hash.replace("#",""); //get lang id
  84. var docs = []; //All documents will be loaded into memory as the reader loads, but not rendered yet
  85. var docsTitles = [];
  86. var baseFolder = "lang/" + lang + "/";
  87. var sidebarMode = "index"; //Either index or stars
  88. var staredPages = [];
  89. initLoad();
  90. $("#lang").text("Language: " + lang);
  91. //Check if there are stared pages. If yes, load them
  92. if (localStorage.getItem(lang) !== null) {
  93. staredPages = JSON.parse(localStorage.getItem(lang));
  94. }
  95. function starThisPage(){
  96. for (var i =0; i < staredPages.length; i++){
  97. if (staredPages[i][0] == currentRenderPage){
  98. //This page is already started. Remove the star
  99. staredPages.splice(i,1);
  100. $("#starBtn").find("i").addClass("empty");
  101. $("#starBtn").removeClass("primary");
  102. localStorage.setItem(lang,JSON.stringify(staredPages));
  103. if (sidebarMode == "stars"){
  104. renderStarList();
  105. }
  106. return;
  107. }
  108. }
  109. //This page is not stared yet. Add it to list
  110. staredPages.push([currentRenderPage,docsTitles[currentRenderPage]]);
  111. console.log("[Page Saved] " + staredPages);
  112. $("#starBtn").find("i").removeClass("empty");
  113. $("#starBtn").addClass("primary");
  114. localStorage.setItem(lang,JSON.stringify(staredPages));
  115. if (sidebarMode == "stars"){
  116. renderStarList();
  117. }
  118. }
  119. function updateStartedIcon(){
  120. for (var i =0; i < staredPages.length; i++){
  121. if (staredPages[i][0] == currentRenderPage){
  122. $("#starBtn").find("i").removeClass("empty");
  123. $("#starBtn").addClass("primary");
  124. return;
  125. }
  126. }
  127. $("#starBtn").find("i").addClass("empty");
  128. $("#starBtn").removeClass("primary");
  129. }
  130. function toggleMode(mode){
  131. if (mode == "stars"){
  132. $("#doclist").removeClass("active");
  133. $("#starlist").addClass("active");
  134. renderStarList();
  135. sidebarMode = "stars";
  136. }else{
  137. $("#starlist").removeClass("active");
  138. $("#doclist").addClass("active");
  139. renderDocsList();
  140. sidebarMode = "index";
  141. }
  142. }
  143. function renderStarList(){
  144. $("#pageContent").html("");
  145. for (var i = 0; i < staredPages.length; i++){
  146. var page = staredPages[i][0];
  147. var title = staredPages[i][1];
  148. $("#pageContent").append('<p class="selectable" onClick="redirectDoc(' + page + ');"><i class="bookmark icon"></i> ' + title + '</p>');
  149. }
  150. if (staredPages.length == 0){
  151. $("#pageContent").append('<p class=""><i class="remove icon"></i> No bookmark</p>');
  152. }
  153. }
  154. function toggleList(){
  155. ts('.left.sidebar:not(.inverted)').sidebar({
  156. dimPage: true,
  157. scrollLock: true
  158. }).sidebar('toggle');
  159. }
  160. function redirectDoc(indexID){
  161. currentRenderPage = indexID;
  162. readDoc();
  163. toggleList();
  164. }
  165. function renderDocsList(){
  166. $("#pageContent").html("");
  167. for (var i =0; i < docsTitles.length; i++){
  168. $("#pageContent").append('<p class="selectable" onClick="redirectDoc(' + i + ');"><i class="book icon"></i> ' + docsTitles[i] + '</p>');
  169. }
  170. }
  171. function reloadAllDocs(){
  172. docs = [];
  173. searchingPage = 0;
  174. initLoad();
  175. docsTitles=[];
  176. }
  177. function loadAllDocs(){
  178. $.ajax({
  179. type: 'get',
  180. timeout: 5000,
  181. url: baseFolder + searchingPage + ".md",
  182. success: function(data, textStatus, XMLHttpRequest){
  183. data = data.split("\r\n").join("\n");
  184. docs.push(data.split("\n"));
  185. //console.log(data.split("\n"));
  186. searchingPage++;
  187. loadAllDocs();
  188. },
  189. error:function (xhr, ajaxOptions, thrownError){
  190. //End of documentation
  191. //console.log(docs);
  192. readDoc(); //Start rendering
  193. parseDocList(); //Update the doc list
  194. renderDocsList(); //Render the documentation list
  195. }
  196. });
  197. }
  198. function nextPage(){
  199. currentRenderPage = currentRenderPage + 1;
  200. if (currentRenderPage >= docs.length){
  201. //No more pages
  202. currentRenderPage = currentRenderPage - 1;
  203. return;
  204. }
  205. readDoc();
  206. }
  207. function lastPage(){
  208. currentRenderPage = currentRenderPage - 1;
  209. if (currentRenderPage < 0){
  210. //No more pages
  211. currentRenderPage = currentRenderPage + 1;
  212. return;
  213. }
  214. readDoc();
  215. }
  216. function readDoc(){
  217. let pageInfo = Array.from(docs[currentRenderPage]);
  218. var metaTag = JSON.parse(pageInfo.shift());
  219. document.title = metaTag[0];
  220. $("#readerTitle").text(metaTag[0]);
  221. $("#docLoader").html("");
  222. pageInfo = pageInfo.join("\n");
  223. $("#docLoader").append(md2html(pageInfo));
  224. updateStartedIcon();
  225. }
  226. function parseDocList(){
  227. for (var i =0; i < docs.length; i++){
  228. let pageInfo = Array.from(docs[i]);
  229. var metaTag = JSON.parse(pageInfo.shift());
  230. docsTitles.push(metaTag[0]);
  231. }
  232. }
  233. function md2html(input){
  234. var converter = new showdown.Converter();
  235. return converter.makeHtml(input);
  236. }
  237. //Initiate the loading interface
  238. function initLoad(){
  239. $("#docLoader").html('<div align="center" style="width:100%;">\
  240. <br><br>\
  241. <i class="big spinner loading icon stillLoading"></i><br>\
  242. <p class="loadFailMsg">Loading...</p>\
  243. <br><br>\
  244. </div>');
  245. setTimeout(chkLoadFail,15000);
  246. loadAllDocs();
  247. }
  248. //Check if the load failed using setTimeout
  249. function chkLoadFail(){
  250. if ($(".stillLoading").length > 0){
  251. //Something screwed up during loading of JSON based documentation. Ask for refresh
  252. $(".stillLoading").removeClass("spinner").removeClass("loading").addClass("remove");
  253. $(".loadFailMsg").text("Seems something went wrong. Try refreshing the page?");
  254. }
  255. }
  256. </script>
  257. </body>
  258. </html>