提交 f9fa6f93 编写于 作者: Z zz85

[docs] Refactor navigation handling a litte.

Wanted to use push & popState, but current hashchange should work fine for now.
上级 231a36ac
......@@ -105,6 +105,7 @@
var html = '<h1><a href="http://threejs.org">three.js</a><span style="font-size: 50%; vertical-align: super;"> r' + REVISION + '</span></h1>';
var DELIMITER = '/';
var nameCategoryMap = {};
for ( var section in list ) {
......@@ -124,6 +125,12 @@
html += '<li><a href="javascript:goTo(\'' + section + '\', \'' + category + '\', \'' + page[ 0 ] + '\')">' + page[ 0 ] + '</a></li>';
nameCategoryMap[page[0]] = {
section: section,
category: category,
name: page[0]
};
}
html += '</ul>';
......@@ -153,16 +160,18 @@
function goTo( section, category, name ) {
// Fully resolve links that only provide a name
if(!category && !name) {
var location = getPageFromList(section);
if(arguments.length == 1) {
var location = nameCategoryMap[section];
section = location.section;
category = location.category;
name = location.name;
}
window.document.title = 'three.js - documentation - ' + section + ' - ' + name;
var title = 'three.js - documentation - ' + section + ' - ' + name;
var url = encodeUrl(section) + DELIMITER + encodeUrl( category ) + DELIMITER + encodeUrl(name);
window.location.hash = encodeUrl(section) + DELIMITER + encodeUrl( category ) + DELIMITER + encodeUrl(name);
window.location.hash = url;
window.document.title = title;
viewer.src = pages[ section ][ category ][ name ] + '.html';
......@@ -176,22 +185,6 @@
}
function getPageFromList( name ) {
for ( var section in pages ) {
for ( var category in pages[section] ) {
for ( var pageName in pages[section][category] ) {
if(pageName === name) {
return {
section: section,
category: category,
name: pageName
};
}
}
}
}
}
window.addEventListener( 'hashchange', goToHash, false );
if ( window.location.hash.length > 0 ) goToHash();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册