An unfinished system to manage all your paper documentation in an easy way.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

autodoc.js 3.4KB

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