An unfinished system to manage all your paper documentation in an easy way.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autodoc.js 3.1KB

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