提交 fc072878 编写于 作者: L Librahang

Fix the issue "Not precise location in the docs".

上级 c86d9392
......@@ -5,40 +5,31 @@
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.4/jstree.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Counter-Up/1.0/jquery.counterup.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-parallax/1.1.3/jquery-parallax.js"></script>
<script src="{{ .Site.BaseURL }}js/front.js"></script>
<!-- owl carousel -->
<script src="{{ .Site.BaseURL }}js/owl.carousel.min.js"></script>
<!-- used to for mobile -->
<script src="{{ .Site.BaseURL }}js/flexible.js"></script>
<script src="{{ .Site.BaseURL }}js/common.js"></script>
<script src="{{ .Site.BaseURL }}js/dist/jso.js"></script>
<script src="{{ .Site.BaseURL }}js/cla.js?t=20191230"></script>
<div id="mask" onclick="hideNav()"></div>
<script type="text/javascript">
$(document).ready(function () {
function getRelativePath() {
var url = location.href;
var arrURL = url.split("//");
return arrURL[1].substring(arrURL[1].indexOf("/"));
var arrURL = url.split('//');
return arrURL[1].substring(arrURL[1].indexOf('/'));
}
function getCurrentID(wholeData, relativeURL) {
for (var j in wholeData) {
var href = wholeData[j].a_attr.href;
var text = wholeData[j].text;
//debugger;
if ((href == relativeURL) || (text.indexOf(relativeURL) >= 0)) {
//console.log(wholeData[j].id);
if ((href === relativeURL) || (text.indexOf(relativeURL) >= 0)) {
return wholeData[j].id;
} else {
if (wholeData[j].children.length > 0) {
......@@ -49,9 +40,8 @@
}
}
}
return "";
return '';
}
if ($('#docstreeview').length) {
$('#docstreeview').jstree();
$('#docstreeview').jstree().hide_dots();
......@@ -74,41 +64,94 @@
}
}
});
/* select the node by the relative url
var currentAElement = $('#docstreeview').find("a[href='" + getRelativePath() + "']");
if (currentAElement.length) {
console.log("click");
currentAElement.trigger("click");
}*/
$("#docstreeview").on("ready.jstree", function (e, data) {
$("#docstreeview").fadeIn("slow")
$('#docstreeview').on('ready.jstree', function (e, data) {
$('#docstreeview').fadeIn('slow');
var relativeURL = getRelativePath();
var wholeData = $("#docstreeview").jstree().get_json();
var wholeData = $('#docstreeview').jstree().get_json();
var currentID = getCurrentID(wholeData, relativeURL);
console.log(currentID);
$("#docstreeview").jstree()._open_to(currentID);
$('#docstreeview').jstree()._open_to(currentID);
$('#docstreeview').jstree().select_node(currentID);
$('#docstreeview').jstree().open_node(currentID);
var data = $('#docstreeview').jstree().get_json();
var nodeList = [];
/*把树状平铺,用于查看是否有上一页下一页*/
var getAllData = function (Arr) {
for (var i = 0; i < Arr.length; i++) {
var tempNode = {};
tempNode.id = Arr[i].id;
var href = Arr[i].a_attr.href;
if (href === '#') {
/*转为jq对象特殊处理*/
var jqNode = $(Arr[i].text);
tempNode.href = jqNode.find('a').attr('href');
} else {
tempNode.href = href;
}
nodeList.push(tempNode);
if (Arr[i].children !== []) {
getAllData(Arr[i].children);
}
}
};
/*获取上一页、下一页*/
var nextAndPevious = function (arr, id) {
var result = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i].id === id) {
if (i === 0) {
result.push(null);
} else {
result.push(arr[i - 1].href);
}
if (i === arr.length - 1) {
result.push(null);
} else {
result.push(arr[i + 1].href);
}
}
}
return result;
};
getAllData(wholeData);
var nextAndPeviousArr = nextAndPevious(nodeList, currentID);
if (nextAndPeviousArr[0] == null) {
$('#docPreviousPage').attr('disabled', 'disabled');
} else {
$('#docPreviousPage').attr('href', nextAndPeviousArr[0]);
}
if (nextAndPeviousArr[1] == null) {
$('#docNextPage').attr('disabled', 'disabled');
} else {
$('#docNextPage').attr('href', nextAndPeviousArr[1]);
}
});
}
function showNav() {
$('#menu').css({
"transform": "translateX(0)"
}).attr("onoff", "on");
'transform': 'translateX(0)'
}).attr('onoff', 'on');
}
function hideNav() {
$('#menu').css({
"transform": "translateX(-100%)"
}).attr("onoff", "off");
'transform': 'translateX(-100%)'
}).attr('onoff', 'off');
}
$("#slideNav").bind('click', function () {
if ($('#menu').attr("onoff") == "on") {
$('#slideNav').bind('click', function () {
if ($('#menu').attr('onoff') === 'on') {
hideNav();
} else {
showNav();
}
})
});
$(' a[href^="#"][href!="#"]').click(function () {
var target = document.getElementById(decodeURI(this.hash).split('#')[1]);
if (!target) return;
var targetOffset = $(target).offset().top - 140 +"px";
$('html,body').animate({
scrollTop: targetOffset
},
300);
return false;
});
});
</script>
</script>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册