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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. page = 0;
  62. }
  63. var tmpl = $("#autodoc_template_home");
  64. var row = $(tmpl)
  65. .find(".autodoc_template_home_row")
  66. .clone();
  67. $.getJSON(
  68. conf.openapi +
  69. "/documents?pageSize=" +
  70. conf.home.width +
  71. "&pageIndex=" +
  72. page,
  73. null,
  74. function(data, textStatus, jqXHR) {
  75. $.each(data, function(id, doc) {
  76. var col = $(tmpl)
  77. .find(".autodoc_template_home_col")
  78. .clone();
  79. $(col)
  80. .find(".autodoc_template_home_img")
  81. .attr(
  82. "src",
  83. conf.openapi +
  84. "/documents/" +
  85. doc.id +
  86. "/image?maxWidth=" +
  87. Math.floor(1000 / conf.home.width)
  88. );
  89. $(col)
  90. .find(".autodoc_template_home_owner")
  91. .html(doc.owner);
  92. $(col)
  93. .find(".autodoc_template_home_created")
  94. .html(doc.created);
  95. $.each(doc.tags, function(id, tag) {
  96. $(col)
  97. .find(".autodoc_template_home_tag")
  98. .after(
  99. $(col)
  100. .find(".autodoc_template_home_tag")
  101. .clone()
  102. .html(tag)
  103. );
  104. });
  105. $(row).append(col);
  106. });
  107. $("#autodoc_home_body").append(row);
  108. }
  109. );
  110. // continue to load until out of browser.
  111. var obj = $("#autodoc_home_body")
  112. .children()
  113. .last();
  114. console.log($('#autodoc_home_body'));
  115. console.log($('#autodoc_home_body').children());
  116. console.log($('#autodoc_home_body').find('.autodoc_template_home_row').last());
  117. if (isvisible(obj)) {
  118. document_load(page + 1);
  119. }
  120. }