An unfinished system to manage all your paper documentation in an easy way.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

autodoc.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. $.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. console.log(obj);
  52. var top_of_element = $(obj).offset().top;
  53. var bottom_of_element = $(obj).offset().top + $(obj).outerHeight();
  54. var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
  55. var top_of_screen = $(window).scrollTop();
  56. console.log("screen: " + top_of_screen + " " + bottom_of_screen);
  57. console.log("elem: " + top_of_element + " " + bottom_of_element);
  58. if (bottom_of_screen > top_of_element && top_of_screen < bottom_of_element) {
  59. return true;
  60. }
  61. return false;
  62. }
  63. function page_load_home() {
  64. document_load();
  65. }
  66. function document_load() {
  67. if (conf.home.curpage == 0) {
  68. $("#autodoc_home_body").html("");
  69. }
  70. var tmpl = $("#autodoc_template_home");
  71. var row = $(tmpl)
  72. .find(".autodoc_template_home_row")
  73. .clone();
  74. $.getJSON(
  75. conf.openapi +
  76. "/documents?pageSize=" +
  77. conf.home.width +
  78. "&pageIndex=" +
  79. conf.home.curpage,
  80. null,
  81. function(data, textStatus, jqXHR) {
  82. $.each(data, function(id, doc) {
  83. var col = $(tmpl)
  84. .find(".autodoc_template_home_col")
  85. .clone();
  86. $(col)
  87. .find(".autodoc_template_home_img")
  88. .attr(
  89. "src",
  90. conf.openapi +
  91. "/documents/" +
  92. doc.id +
  93. "/image?maxWidth=" +
  94. Math.floor(1000 / conf.home.width)
  95. );
  96. $(col)
  97. .find(".autodoc_template_home_owner")
  98. .html(doc.owner);
  99. $(col)
  100. .find(".autodoc_template_home_created")
  101. .html(doc.created);
  102. $.each(doc.tags, function(id, tag) {
  103. $(col)
  104. .find(".autodoc_template_home_tag")
  105. .after(
  106. $(col)
  107. .find(".autodoc_template_home_tag")
  108. .clone()
  109. .html(tag)
  110. );
  111. });
  112. $(row).append(col);
  113. });
  114. $("#autodoc_home_body").append(row);
  115. // continue to load until out of browser.
  116. page_home_scroll();
  117. }
  118. );
  119. }
  120. function page_home_scroll() {
  121. if (isvisible($(".autodoc_template_home_col").last())) {
  122. conf.home.curpage++;
  123. document_load();
  124. }
  125. }