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.

autodoc.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. console.log("add " + curhash);
  32. $(obj)
  33. .parent()
  34. .addClass("active");
  35. $("#autodoc_tab_" + curhash).removeClass("d-none");
  36. } else {
  37. console.log("remove " + curhash);
  38. $(obj)
  39. .parent()
  40. .removeClass("active");
  41. $("#autodoc_tab_" + curhash).addClass("d-none");
  42. }
  43. });
  44. if (conf.pageinit[hash]) {
  45. eval(conf.pageinit[hash]);
  46. }
  47. }
  48. function page_load_home() {
  49. document_load(0);
  50. }
  51. function document_load(page) {
  52. if (!page) {
  53. page = 0;
  54. }
  55. var tmpl = $("#autodoc_template_home");
  56. var row = $(tmpl)
  57. .find(".autodoc_template_home_row")
  58. .clone();
  59. $.getJSON(
  60. conf.openapi + "/documents?pageSize=" + conf.home.width + "&pageIndex=" + page + "&maxWidth=" + Math.floor(1000/conf.home.width),
  61. null,
  62. function (data, textStatus, jqXHR) {
  63. $.each(data, function (id, doc) {
  64. var col = $(tmpl)
  65. .find(".autodoc_template_home_col")
  66. .clone();
  67. $(col).find(".autodoc_template_home_img").attr('src', conf.openapi + '/documents/' + doc.id + '/image');
  68. $(col)
  69. .find(".autodoc_template_home_owner")
  70. .html(doc.owner);
  71. $(col)
  72. .find(".autodoc_template_home_created")
  73. .html(doc.created);
  74. $.each(doc.tags, function (id, tag) {
  75. $(col)
  76. .find(".autodoc_template_home_tag")
  77. .after(
  78. $(col)
  79. .find(".autodoc_template_home_tag")
  80. .clone()
  81. .html(tag)
  82. );
  83. });
  84. $(row).append(col);
  85. });
  86. $('#autodoc_home_body').append(row);
  87. }
  88. );
  89. }