An unfinished system to manage all your paper documentation in an easy way.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

autodoc.js 3.2KB

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. }
  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. console.log(obj);
  48. var top_of_element = $(obj).offset().top;
  49. var bottom_of_element = $(obj).offset().top + $(obj).outerHeight();
  50. var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
  51. var top_of_screen = $(window).scrollTop();
  52. console.log("screen: " + top_of_screen + " " + bottom_of_screen);
  53. console.log("elem: " + top_of_element + " " + bottom_of_element);
  54. if (bottom_of_screen > top_of_element && top_of_screen < bottom_of_element) {
  55. return true;
  56. }
  57. return false;
  58. }
  59. function page_load_home() {
  60. document_load(0);
  61. }
  62. function document_load(page) {
  63. if (!page || page == 0) {
  64. $('#autodoc_home_body').html('');
  65. page = 0;
  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. page,
  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. }
  113. );
  114. // continue to load until out of browser.
  115. console.log($('#autodoc_home_body'));
  116. console.log($('#autodoc_home_body').last());
  117. console.log($('#autodoc_home_body').children());
  118. if (isvisible($.find(".autodoc_template_home_col").last())) {
  119. document_load(page + 1);
  120. }
  121. }