|
@@ -20,9 +20,16 @@
|
|
*/
|
|
*/
|
|
function ahTocBuildToc() {
|
|
function ahTocBuildToc() {
|
|
|
|
|
|
- var context = $('div.advanced-help-topic');
|
|
|
|
- var elements = $('*', context).filter(function (index) {
|
|
|
|
- return ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7'].indexOf(this.nodeName) != -1;
|
|
|
|
|
|
+ var context, // the context of the help page
|
|
|
|
+ elements, // the list of headings
|
|
|
|
+ element, // one of the headings
|
|
|
|
+ list, // the string form of the toc list
|
|
|
|
+ index, // a running index for missing heading IDs
|
|
|
|
+ id; // the current id when iterating on the headings
|
|
|
|
+
|
|
|
|
+ context = $('div.advanced-help-topic');
|
|
|
|
+ elements = $('*', context).filter(function (index) {
|
|
|
|
+ return ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7'].indexOf(this.nodeName) !== -1;
|
|
});
|
|
});
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -33,11 +40,21 @@ function ahTocBuildToc() {
|
|
}
|
|
}
|
|
|
|
|
|
// Build the headings list
|
|
// Build the headings list
|
|
- var list = "<ul>\n";
|
|
|
|
|
|
+ list = "<ul>\n";
|
|
|
|
+ index = 0;
|
|
|
|
+
|
|
elements.each(function() {
|
|
elements.each(function() {
|
|
- list += '<li class="' + this.nodeName.toLowerCase() + '">'
|
|
|
|
- + $(this).text() + "</li>\n";
|
|
|
|
- })
|
|
|
|
|
|
+ element = $(this);
|
|
|
|
+ id = element.attr('id');
|
|
|
|
+ if (id === '') {
|
|
|
|
+ index += 1; // Avoid JSline warning on ++ use
|
|
|
|
+ id = 'toc' + index;
|
|
|
|
+ element.attr('id', id);
|
|
|
|
+ }
|
|
|
|
+ // @TODO use some form of l() instead of string concatenation
|
|
|
|
+ list += '<li class="' + this.nodeName.toLowerCase() + '">' +
|
|
|
|
+ '<a href="#' + id + '">' + element.text() + "</a></li>\n";
|
|
|
|
+ });
|
|
list += "</ul>\n";
|
|
list += "</ul>\n";
|
|
|
|
|
|
// Avoid creating multiple TOCs if this function is called several times
|
|
// Avoid creating multiple TOCs if this function is called several times
|