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

autodoc.js 2.9KB

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