123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /* AutoDoc Javascript */
-
- var conf = {
- default_hash: "home",
- openapi: "/v1",
- pageinit: {
- home: "page_load_home()"
- },
- home: {
- width: 4
- }
- };
-
- $(document).ready(function() {
- change_page();
- });
-
- $(window).bind("hashchange", function() {
- change_page();
- });
-
- function change_page() {
- var hash = document.location.hash.substr(1) || conf.default_hash;
-
- if (!$("#autodoc_tab_" + hash).length) {
- hash = conf.default_hash;
- }
-
- /* change menu highlights and content visibility */
- $("#autodoc_navbar")
- .find("a")
- .each(function(id, obj) {
- var curhash = $(obj)
- .attr("href")
- .substr(1);
- if (curhash == hash) {
- $(obj)
- .parent()
- .addClass("active");
- $("#autodoc_tab_" + curhash).removeClass("d-none");
- } else {
- $(obj)
- .parent()
- .removeClass("active");
- $("#autodoc_tab_" + curhash).addClass("d-none");
- }
- });
-
- if (conf.pageinit[hash]) {
- eval(conf.pageinit[hash]);
- }
- }
-
- function isvisible(obj) {
- console.log(obj);
- var top_of_element = $(obj).offset().top;
- var bottom_of_element = $(obj).offset().top + $(obj).outerHeight();
- var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
- var top_of_screen = $(window).scrollTop();
-
- console.log("screen: " + top_of_screen + " " + bottom_of_screen);
- console.log("elem: " + top_of_element + " " + bottom_of_element);
-
- if (bottom_of_screen > top_of_element && top_of_screen < bottom_of_element) {
- return true;
- }
- return false;
- }
-
- function page_load_home() {
-
- document_load(0);
- }
-
- function document_load(page) {
- if (!page || page == 0) {
- $('#autodoc_home_body').html('');
- page = 0;
- }
-
- var tmpl = $("#autodoc_template_home");
- var row = $(tmpl)
- .find(".autodoc_template_home_row")
- .clone();
-
- $.getJSON(
- conf.openapi +
- "/documents?pageSize=" +
- conf.home.width +
- "&pageIndex=" +
- page,
- null,
- function(data, textStatus, jqXHR) {
- $.each(data, function(id, doc) {
- var col = $(tmpl)
- .find(".autodoc_template_home_col")
- .clone();
- $(col)
- .find(".autodoc_template_home_img")
- .attr(
- "src",
- conf.openapi +
- "/documents/" +
- doc.id +
- "/image?maxWidth=" +
- Math.floor(1000 / conf.home.width)
- );
-
- $(col)
- .find(".autodoc_template_home_owner")
- .html(doc.owner);
-
- $(col)
- .find(".autodoc_template_home_created")
- .html(doc.created);
- $.each(doc.tags, function(id, tag) {
- $(col)
- .find(".autodoc_template_home_tag")
- .after(
- $(col)
- .find(".autodoc_template_home_tag")
- .clone()
- .html(tag)
- );
- });
- $(row).append(col);
- });
- $("#autodoc_home_body").append(row);
- }
- );
- // continue to load until out of browser.
- console.log($('#autodoc_home_body'));
- console.log($('#autodoc_home_body').parent());
-
- console.log($('#autodoc_home_body').find('.autodoc_template_home_col'));
- if (isvisible($.find(".autodoc_template_home_col").last())) {
- document_load(page + 1);
- }
- }
|