reader.html 7.8 KB

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