An unfinished system to manage all your paper documentation in an easy way.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

autodoc.js 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* AutoDoc Javascript */
  2. var conf = {
  3. default_hash: "home",
  4. openapi: "/v1",
  5. pageinit: {
  6. home: "page_load_home()"
  7. },
  8. home: {
  9. width: 4,
  10. curpage: 0,
  11. end: 0
  12. }
  13. };
  14. var temp = {
  15. upload: [],
  16. documentid: null
  17. };
  18. $(document).ready(function () {
  19. change_page();
  20. upload_zone_init();
  21. $(document).scroll(function () {
  22. page_home_scroll();
  23. });
  24. });
  25. $(window).bind("hashchange", function () {
  26. change_page();
  27. });
  28. function change_page() {
  29. var hash = document.location.hash.substr(1) || conf.default_hash;
  30. if (!$("#autodoc_tab_" + hash).length) {
  31. hash = conf.default_hash;
  32. }
  33. /* change menu highlights and content visibility */
  34. $("#autodoc_navbar")
  35. .find("a")
  36. .each(function (id, obj) {
  37. var curhash = $(obj)
  38. .attr("href")
  39. .substr(1);
  40. if (curhash == hash) {
  41. $(obj)
  42. .parent()
  43. .addClass("active");
  44. $("#autodoc_tab_" + curhash).removeClass("d-none");
  45. } else {
  46. $(obj)
  47. .parent()
  48. .removeClass("active");
  49. $("#autodoc_tab_" + curhash).addClass("d-none");
  50. }
  51. });
  52. if (conf.pageinit[hash]) {
  53. eval(conf.pageinit[hash]);
  54. }
  55. }
  56. function isvisible(obj) {
  57. var top_of_fileent = $(obj).offset().top;
  58. var bottom_of_fileent = $(obj).offset().top + $(obj).outerHeight();
  59. var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
  60. var top_of_screen = $(window).scrollTop();
  61. if (bottom_of_screen > top_of_fileent && top_of_screen < bottom_of_fileent) {
  62. return true;
  63. }
  64. return false;
  65. }
  66. function page_load_home() {
  67. document_load();
  68. }
  69. function document_load() {
  70. if (conf.home.curpage == 0) {
  71. $("#autodoc_home_body").html("");
  72. }
  73. var tmpl = $("#autodoc_template_home");
  74. var row = $(tmpl)
  75. .find(".autodoc_template_home_row")
  76. .clone();
  77. $.getJSON(
  78. conf.openapi +
  79. "/documents?pageSize=" +
  80. conf.home.width +
  81. "&pageIndex=" +
  82. conf.home.curpage,
  83. null,
  84. function (data, textStatus, jqXHR) {
  85. // last document was loaded, stop scrolling
  86. if (data.length < conf.home.width) {
  87. conf.home.end = 1;
  88. }
  89. $.each(data, function (id, doc) {
  90. var col = $(tmpl)
  91. .find(".autodoc_template_home_col")
  92. .clone();
  93. $(col)
  94. .find(".autodoc_template_home_img")
  95. .attr(
  96. "src",
  97. conf.openapi +
  98. "/documents/" +
  99. doc.id +
  100. "/image?maxWidth=" +
  101. Math.floor(1000 / conf.home.width)
  102. );
  103. $(col)
  104. .find(".autodoc_template_home_owner")
  105. .html(doc.owner);
  106. $(col)
  107. .find(".autodoc_template_home_created")
  108. .html(doc.created);
  109. $(col)
  110. .find(".autodoc_template_home_name")
  111. .html(doc.name);
  112. $.each(doc.tags, function (id, tag) {
  113. $(col)
  114. .find(".autodoc_template_home_tag")
  115. .after(
  116. $(col)
  117. .find(".autodoc_template_home_tag")
  118. .clone()
  119. .html(tag)
  120. );
  121. });
  122. $(row).append(col);
  123. });
  124. $("#autodoc_home_body").append(row);
  125. // continue to load until out of browser.
  126. page_home_scroll();
  127. }
  128. );
  129. }
  130. function page_home_scroll() {
  131. // don't scroll if we've loaded the last document
  132. if (conf.home.end) {
  133. return;
  134. }
  135. if (isvisible($(".autodoc_template_home_col").last())) {
  136. console.log("scroll to page " + conf.home.curpage);
  137. conf.home.curpage++;
  138. document_load();
  139. }
  140. }
  141. function upload_zone_init() {
  142. $(window).on("dragover dragleave drop", function (e) { e.preventDefault() });
  143. $('.autodoc_upload_zone').on({
  144. dragenter: upload_zone_highlight,
  145. dragleave: upload_zone_normal,
  146. dragover: upload_zone_over,
  147. drop: upload_zone_drop
  148. });
  149. }
  150. function upload_zone_highlight(e) {
  151. $(e.target).addClass('autodoc_upload_zone_hover');
  152. }
  153. function upload_zone_over(e) {
  154. return true;
  155. }
  156. function upload_zone_normal(e) {
  157. $(e.target).removeClass('autodoc_upload_zone_hover');
  158. }
  159. function upload_zone_drop(e) {
  160. var ev = e.originalEvent;
  161. $.each(ev.dataTransfer.files, function (id, file) {
  162. console.log(file);
  163. var fileid = temp.upload.length;
  164. temp.upload.push({
  165. progress: 0,
  166. error: null,
  167. obj: file
  168. });
  169. });
  170. upload_handler();
  171. }
  172. function upload_handler() {
  173. if (temp.documentid == null) {
  174. $.post(conf.openapi + "/documents", {}, function (data) {
  175. temp.documentid = data.id;
  176. });
  177. }
  178. else {
  179. for(var id=0; id<temp.upload.length; id++) {
  180. var file = temp.upload[id];
  181. if ( file.progress != 100 ) {
  182. if ( file.progress == 0 ) {
  183. if (file.obj.type != 'application/pdf' && file.obj.type != 'image/png' && file.obj.type != 'image/jpeg') {
  184. file['progress'] = 100;
  185. file['error'] = 'invalid file type';
  186. }
  187. else {
  188. var reader = new FileReader();
  189. file['progress'] = 1;
  190. $(reader).on({
  191. loadstart: upload_read_event,
  192. load: upload_read_event,
  193. loadend: upload_read_event,
  194. progress: upload_read_event,
  195. error: upload_read_event,
  196. abort: upload_read_event
  197. });
  198. reader.readAsArrayBuffer(file.obj);
  199. }
  200. }
  201. break;
  202. }
  203. }
  204. }
  205. setTimeout(upload_handler, 1000);
  206. }
  207. function upload_read_event(e) {
  208. console.log(e);
  209. }
  210. function upload_status() {
  211. $.each(temp.upload, function (id, file) {
  212. if (!$('.autodoc_upload_status_' + id)) {
  213. var obj = $(".autodoc_template_progress").children().clone();
  214. $('.autodoc_upload_status').append(obj);
  215. }
  216. var obj = $('.autodoc_upload_status_' + id).children();
  217. if (file.error != null) {
  218. $(obj).html(file.obj.name + ': ' + file.error);
  219. $(obj).css('width', '100%');
  220. $(obj).addClass('bg-danger');
  221. $(obj).removeClass("progress-bar-animated");
  222. }
  223. else if (file.progress == 100) {
  224. $(obj).html(file.obj.name);
  225. $(obj).addClass('bg-success');
  226. $(obj).removeClass('progress-bar-animated');
  227. $(obj).css('width', '100%');
  228. }
  229. else if (file.progress < 50) {
  230. $(obj).html(file.obj.name + ': ' + 'reading file');
  231. $(obj).css('width', file.progress + '%');
  232. }
  233. else {
  234. $(obj).html(file.obj.name + ': ' + 'sending file');
  235. $(obj).css('width', file.progress + '%');
  236. }
  237. });
  238. setTimeout(upload_status, 1000);
  239. }