Commit 00cae17a authored by Mengyun Yang's avatar Mengyun Yang Committed by Yuxin Wu

Refactoring javascript to show class name (#385)

parent 37ecbd4e
...@@ -3,14 +3,22 @@ ...@@ -3,14 +3,22 @@
$(function (){ $(function (){
var createList = function(selected) { var createList = function(selected) {
var obj = {};
var ul = $('<ul>'); var ul = $('<ul>');
selected.each(function(i,e) { selected.each(function(i,e) {
var className = e.getElementsByTagName('a')[0].href;
className = className.substr(className.lastIndexOf('/')+1);
className = className.substr(0,className.lastIndexOf(".html"));
var fullname = e.id; var fullname = e.id;
var n = $(e).children('.descname').clone();
if (fullname.startsWith('tensorpack.')) if (fullname.startsWith('tensorpack.'))
fullname = fullname.substr(11); fullname = fullname.substr(11);
var n = $(e).children('.descname').clone();
n[0].innerText = fullname; n[0].innerText = fullname;
var l = $(e).children('.headerlink'); var l = $(e).children('.headerlink');
...@@ -20,9 +28,19 @@ $(function (){ ...@@ -20,9 +28,19 @@ $(function (){
a.append(n); a.append(n);
var entry = $('<li>').append(a); var entry = $('<li>').append(a);
if(className in obj) {
obj[className] = obj[className].append(entry);
} else {
var ul = $('<ul>');
ul.append(entry); ul.append(entry);
obj[className] = ul;
}
}); });
return ul;
return obj;
} }
...@@ -30,15 +48,20 @@ $(function (){ ...@@ -30,15 +48,20 @@ $(function (){
var customIndex = $('.custom-index'); var customIndex = $('.custom-index');
customIndex.empty(); customIndex.empty();
var selected = $('div.section>dl>dt'); var selected = $('div.section>dl>dt');
if (selected.length === 0) if (selected.length === 0)
return; return;
var l = createList(selected); var obj = createList(selected);
for(var key in obj) {
var c = $('<div style="min-width: 300px;">'); var c = $('<div style="min-width: 300px;">');
var ul = c.clone() var a = $('<h4>');
.append(l); a.html(key);
var u = c.clone().append(a);
var ul = c.clone().append(obj[key]);
customIndex.append(u);
customIndex.append(ul); customIndex.append(ul);
}
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment