|
|
@@ -1,102 +1,134 @@ |
|
|
|
/* AutoDoc Javascript */ |
|
|
|
|
|
|
|
var conf = { |
|
|
|
default_hash: "home", |
|
|
|
openapi: "/v1", |
|
|
|
pageinit: { |
|
|
|
home: "page_load_home()" |
|
|
|
}, |
|
|
|
home: { |
|
|
|
width: 4 |
|
|
|
} |
|
|
|
default_hash: "home", |
|
|
|
openapi: "/v1", |
|
|
|
pageinit: { |
|
|
|
home: "page_load_home()" |
|
|
|
}, |
|
|
|
home: { |
|
|
|
width: 4 |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
$(document).ready(function () { |
|
|
|
change_page(); |
|
|
|
$(document).ready(function() { |
|
|
|
change_page(); |
|
|
|
}); |
|
|
|
|
|
|
|
$(window).bind("hashchange", function () { |
|
|
|
change_page(); |
|
|
|
$(window).bind("hashchange", function() { |
|
|
|
change_page(); |
|
|
|
}); |
|
|
|
|
|
|
|
function change_page() { |
|
|
|
var hash = document.location.hash.substr(1) || conf.default_hash; |
|
|
|
var hash = document.location.hash.substr(1) || conf.default_hash; |
|
|
|
|
|
|
|
if (!$("#autodoc_tab_" + hash).length) { |
|
|
|
hash = 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) { |
|
|
|
console.log("add " + curhash); |
|
|
|
$(obj) |
|
|
|
.parent() |
|
|
|
.addClass("active"); |
|
|
|
$("#autodoc_tab_" + curhash).removeClass("d-none"); |
|
|
|
} else { |
|
|
|
console.log("remove " + curhash); |
|
|
|
$(obj) |
|
|
|
.parent() |
|
|
|
.removeClass("active"); |
|
|
|
$("#autodoc_tab_" + curhash).addClass("d-none"); |
|
|
|
} |
|
|
|
}); |
|
|
|
/* change menu highlights and content visibility */ |
|
|
|
$("#autodoc_navbar") |
|
|
|
.find("a") |
|
|
|
.each(function(id, obj) { |
|
|
|
var curhash = $(obj) |
|
|
|
.attr("href") |
|
|
|
.substr(1); |
|
|
|
if (curhash == hash) { |
|
|
|
console.log("add " + curhash); |
|
|
|
$(obj) |
|
|
|
.parent() |
|
|
|
.addClass("active"); |
|
|
|
$("#autodoc_tab_" + curhash).removeClass("d-none"); |
|
|
|
} else { |
|
|
|
console.log("remove " + curhash); |
|
|
|
$(obj) |
|
|
|
.parent() |
|
|
|
.removeClass("active"); |
|
|
|
$("#autodoc_tab_" + curhash).addClass("d-none"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
if (conf.pageinit[hash]) { |
|
|
|
eval(conf.pageinit[hash]); |
|
|
|
} |
|
|
|
if (conf.pageinit[hash]) { |
|
|
|
eval(conf.pageinit[hash]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function isvisible(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(); |
|
|
|
|
|
|
|
if (bottom_of_screen > top_of_element && top_of_screen < bottom_of_element) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
function page_load_home() { |
|
|
|
document_load(0); |
|
|
|
document_load(0); |
|
|
|
} |
|
|
|
|
|
|
|
function document_load(page) { |
|
|
|
if (!page) { |
|
|
|
page = 0; |
|
|
|
} |
|
|
|
if (!page) { |
|
|
|
page = 0; |
|
|
|
} |
|
|
|
|
|
|
|
var tmpl = $("#autodoc_template_home"); |
|
|
|
var row = $(tmpl) |
|
|
|
.find(".autodoc_template_home_row") |
|
|
|
.clone(); |
|
|
|
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)); |
|
|
|
$.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_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); |
|
|
|
} |
|
|
|
); |
|
|
|
$(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. |
|
|
|
var obj = $("#autodoc_home_body") |
|
|
|
.children() |
|
|
|
.last(); |
|
|
|
if (is_visible(obj)) { |
|
|
|
document_load(page + 1); |
|
|
|
} |
|
|
|
} |