reader.html 7.6 KB

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