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.

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