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

autodoc.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. $(document).ready(function() {
  15. change_page();
  16. $(document).scroll(function() {
  17. page_home_scroll();
  18. });
  19. $('#autodoc_upload_zone').change(function() {
  20. console.log(this);
  21. });
  22. });
  23. $(window).bind("hashchange", function() {
  24. change_page();
  25. });
  26. function change_page() {
  27. var hash = document.location.hash.substr(1) || conf.default_hash;
  28. if (!$("#autodoc_tab_" + hash).length) {
  29. hash = conf.default_hash;
  30. }
  31. /* change menu highlights and content visibility */
  32. $("#autodoc_navbar")
  33. .find("a")
  34. .each(function(id, obj) {
  35. var curhash = $(obj)
  36. .attr("href")
  37. .substr(1);
  38. if (curhash == hash) {
  39. $(obj)
  40. .parent()
  41. .addClass("active");
  42. $("#autodoc_tab_" + curhash).removeClass("d-none");
  43. } else {
  44. $(obj)
  45. .parent()
  46. .removeClass("active");
  47. $("#autodoc_tab_" + curhash).addClass("d-none");
  48. }
  49. });
  50. if (conf.pageinit[hash]) {
  51. eval(conf.pageinit[hash]);
  52. }
  53. }
  54. function isvisible(obj) {
  55. var top_of_element = $(obj).offset().top;
  56. var bottom_of_element = $(obj).offset().top + $(obj).outerHeight();
  57. var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
  58. var top_of_screen = $(window).scrollTop();
  59. if (bottom_of_screen > top_of_element && top_of_screen < bottom_of_element) {
  60. return true;
  61. }
  62. return false;
  63. }
  64. function page_load_home() {
  65. document_load();
  66. }
  67. function document_load() {
  68. if (conf.home.curpage == 0) {
  69. $("#autodoc_home_body").html("");
  70. }
  71. var tmpl = $("#autodoc_template_home");
  72. var row = $(tmpl)
  73. .find(".autodoc_template_home_row")
  74. .clone();
  75. $.getJSON(
  76. conf.openapi +
  77. "/documents?pageSize=" +
  78. conf.home.width +
  79. "&pageIndex=" +
  80. conf.home.curpage,
  81. null,
  82. function(data, textStatus, jqXHR) {
  83. // last document was loaded, stop scrolling
  84. if (data.length < conf.home.width) {
  85. conf.home.end = 1;
  86. }
  87. $.each(data, function(id, doc) {
  88. var col = $(tmpl)
  89. .find(".autodoc_template_home_col")
  90. .clone();
  91. $(col)
  92. .find(".autodoc_template_home_img")
  93. .attr(
  94. "src",
  95. conf.openapi +
  96. "/documents/" +
  97. doc.id +
  98. "/image?maxWidth=" +
  99. Math.floor(1000 / conf.home.width)
  100. );
  101. $(col)
  102. .find(".autodoc_template_home_owner")
  103. .html(doc.owner);
  104. $(col)
  105. .find(".autodoc_template_home_created")
  106. .html(doc.created);
  107. $(col)
  108. .find(".autodoc_template_home_name")
  109. .html(doc.name);
  110. $.each(doc.tags, function(id, tag) {
  111. $(col)
  112. .find(".autodoc_template_home_tag")
  113. .after(
  114. $(col)
  115. .find(".autodoc_template_home_tag")
  116. .clone()
  117. .html(tag)
  118. );
  119. });
  120. $(row).append(col);
  121. });
  122. $("#autodoc_home_body").append(row);
  123. // continue to load until out of browser.
  124. page_home_scroll();
  125. }
  126. );
  127. }
  128. function page_home_scroll() {
  129. // don't scroll if we've loaded the last document
  130. if (conf.home.end) {
  131. return;
  132. }
  133. if (isvisible($(".autodoc_template_home_col").last())) {
  134. console.log("scroll to page " + conf.home.curpage);
  135. conf.home.curpage++;
  136. document_load();
  137. }
  138. }
  139. function file_upload() {
  140. console.log(this.files);
  141. }