Index: pkg/dartdoc/client-live-nav.dart |
diff --git a/pkg/dartdoc/client-live-nav.dart b/pkg/dartdoc/client-live-nav.dart |
index 822088e6525268f083c258cbd8659197424b13bc..d66da8b761c8a2930801e5880974a6d03ac4ba59 100644 |
--- a/pkg/dartdoc/client-live-nav.dart |
+++ b/pkg/dartdoc/client-live-nav.dart |
@@ -11,56 +11,46 @@ |
#import('classify.dart'); |
#import('markdown.dart', prefix: 'md'); |
+#source('dropdown.dart'); |
+#source('search.dart'); |
+#source('nav.dart'); |
#source('client-shared.dart'); |
-// The names of the library and type that this page documents. |
-String currentLibrary = null; |
-String currentType = null; |
- |
-// What we need to prefix relative URLs with to get them to work. |
-String prefix = ''; |
- |
main() { |
- // Figure out where we are. |
- final body = document.query('body'); |
- currentLibrary = body.dataAttributes['library']; |
- currentType = body.dataAttributes['type']; |
- prefix = (currentType != null) ? '../' : ''; |
+ setupLocation(); |
enableCodeBlocks(); |
// Request the navigation data so we can build the HTML for it. |
new HttpRequest.get('${prefix}nav.json', (request) { |
- buildNavigation(JSON.parse(request.responseText)); |
+ var json = JSON.parse(request.responseText); |
+ buildNavigation(json); |
+ setupSearch(json); |
}); |
} |
-/** Turns [name] into something that's safe to use as a file name. */ |
-String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_'); |
/** |
- * Takes [libraries], a JSON object representing a set of libraries and builds |
+ * Takes [libraries], a JSON array representing a set of libraries and builds |
* the appropriate navigation DOM for it relative to the current library and |
* type. |
*/ |
-buildNavigation(libraries) { |
- final libraryNames = libraries.getKeys(); |
- libraryNames.sort((a, b) => a.compareTo(b)); |
- |
+buildNavigation(List libraries) { |
final html = new StringBuffer(); |
- for (final libraryName in libraryNames) { |
+ for (Map libraryInfo in libraries) { |
+ String libraryName = libraryInfo[NAME]; |
html.add('<h2><div class="icon-library"></div>'); |
if (currentLibrary == libraryName && currentType == null) { |
html.add('<strong>${md.escapeHtml(libraryName)}</strong>'); |
} else { |
- final url = '$prefix${sanitize(libraryName)}.html'; |
+ final url = getLibraryUrl(libraryName); |
html.add('<a href="$url">${md.escapeHtml(libraryName)}</a>'); |
} |
html.add('</h2>'); |
// Only list the types for the current library. |
- if (currentLibrary == libraryName) { |
- buildLibraryNavigation(html, libraries[libraryName]); |
+ if (currentLibrary == libraryName && libraryInfo.containsKey(TYPES)) { |
+ buildLibraryNavigation(html, libraryInfo); |
} |
} |
@@ -70,31 +60,31 @@ buildNavigation(libraries) { |
} |
/** Writes the navigation for the types contained by [library] to [html]. */ |
-buildLibraryNavigation(StringBuffer html, library) { |
+buildLibraryNavigation(StringBuffer html, Map libraryInfo) { |
// Show the exception types separately. |
final types = []; |
final exceptions = []; |
- for (final type in library) { |
- if (type['name'].endsWith('Exception')) { |
- exceptions.add(type); |
+ for (Map typeInfo in libraryInfo[TYPES]) { |
+ if (typeInfo[NAME].endsWith('Exception')) { |
+ exceptions.add(typeInfo); |
} else { |
- types.add(type); |
+ types.add(typeInfo); |
} |
} |
if (types.length == 0 && exceptions.length == 0) return; |
- writeType(String icon, type) { |
+ writeType(String icon, Map typeInfo) { |
html.add('<li>'); |
- if (currentType == type['name']) { |
+ if (currentType == typeInfo[NAME]) { |
html.add( |
- '<div class="icon-$icon"></div><strong>${type["name"]}</strong>'); |
+ '<div class="icon-$icon"></div><strong>${getTypeName(typeInfo)}</strong>'); |
} else { |
html.add( |
''' |
- <a href="$prefix${type["url"]}"> |
- <div class="icon-$icon"></div>${type["name"]} |
+ <a href="${getTypeUrl(currentLibrary, typeInfo)}"> |
+ <div class="icon-$icon"></div>${getTypeName(typeInfo)} |
</a> |
'''); |
} |
@@ -102,7 +92,8 @@ buildLibraryNavigation(StringBuffer html, library) { |
} |
html.add('<ul class="icon">'); |
- types.forEach((type) => writeType(type['kind'], type)); |
- exceptions.forEach((type) => writeType('exception', type)); |
+ types.forEach((typeInfo) => |
+ writeType(kindToString(typeInfo[KIND]), typeInfo)); |
+ exceptions.forEach((typeInfo) => writeType('exception', typeInfo)); |
html.add('</ul>'); |
} |