An unfinished system to manage all your paper documentation in an easy way.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

autodoc.js 4.0KB

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