| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** Provides client-side behavior for generated docs. */ | |
| 6 #library('client-live-nav'); | |
| 7 | |
| 8 #import('dart:html'); | |
| 9 #import('dart:json'); | |
| 10 #import('../../lib/compiler/implementation/source_file.dart'); | |
| 11 #import('classify.dart'); | |
| 12 #import('markdown.dart', prefix: 'md'); | |
| 13 | |
| 14 #source('dropdown.dart'); | |
| 15 #source('search.dart'); | |
| 16 #source('nav.dart'); | |
| 17 #source('client-shared.dart'); | |
| 18 | |
| 19 main() { | |
| 20 setupLocation(); | |
| 21 | |
| 22 enableCodeBlocks(); | |
| 23 | |
| 24 // Request the navigation data so we can build the HTML for it. | |
| 25 new HttpRequest.get('${prefix}nav.json', (request) { | |
| 26 var json = JSON.parse(request.responseText); | |
| 27 buildNavigation(json); | |
| 28 setupSearch(json); | |
| 29 }); | |
| 30 } | |
| 31 | |
| 32 | |
| 33 /** | |
| 34 * Takes [libraries], a JSON array representing a set of libraries and builds | |
| 35 * the appropriate navigation DOM for it relative to the current library and | |
| 36 * type. | |
| 37 */ | |
| 38 buildNavigation(List libraries) { | |
| 39 final html = new StringBuffer(); | |
| 40 for (Map libraryInfo in libraries) { | |
| 41 String libraryName = libraryInfo[NAME]; | |
| 42 html.add('<h2><div class="icon-library"></div>'); | |
| 43 if (currentLibrary == libraryName && currentType == null) { | |
| 44 html.add('<strong>${md.escapeHtml(libraryName)}</strong>'); | |
| 45 } else { | |
| 46 final url = getLibraryUrl(libraryName); | |
| 47 html.add('<a href="$url">${md.escapeHtml(libraryName)}</a>'); | |
| 48 } | |
| 49 html.add('</h2>'); | |
| 50 | |
| 51 // Only list the types for the current library. | |
| 52 if (currentLibrary == libraryName && libraryInfo.containsKey(TYPES)) { | |
| 53 buildLibraryNavigation(html, libraryInfo); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 // Insert it into the DOM. | |
| 58 final navElement = document.query('.nav'); | |
| 59 navElement.innerHTML = html.toString(); | |
| 60 } | |
| 61 | |
| 62 /** Writes the navigation for the types contained by [library] to [html]. */ | |
| 63 buildLibraryNavigation(StringBuffer html, Map libraryInfo) { | |
| 64 // Show the exception types separately. | |
| 65 final types = []; | |
| 66 final exceptions = []; | |
| 67 | |
| 68 for (Map typeInfo in libraryInfo[TYPES]) { | |
| 69 if (typeInfo[NAME].endsWith('Exception')) { | |
| 70 exceptions.add(typeInfo); | |
| 71 } else { | |
| 72 types.add(typeInfo); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 if (types.length == 0 && exceptions.length == 0) return; | |
| 77 | |
| 78 writeType(String icon, Map typeInfo) { | |
| 79 html.add('<li>'); | |
| 80 if (currentType == typeInfo[NAME]) { | |
| 81 html.add( | |
| 82 '<div class="icon-$icon"></div><strong>${getTypeName(typeInfo)}</stron
g>'); | |
| 83 } else { | |
| 84 html.add( | |
| 85 ''' | |
| 86 <a href="${getTypeUrl(currentLibrary, typeInfo)}"> | |
| 87 <div class="icon-$icon"></div>${getTypeName(typeInfo)} | |
| 88 </a> | |
| 89 '''); | |
| 90 } | |
| 91 html.add('</li>'); | |
| 92 } | |
| 93 | |
| 94 html.add('<ul class="icon">'); | |
| 95 types.forEach((typeInfo) => | |
| 96 writeType(kindToString(typeInfo[KIND]), typeInfo)); | |
| 97 exceptions.forEach((typeInfo) => writeType('exception', typeInfo)); | |
| 98 html.add('</ul>'); | |
| 99 } | |
| OLD | NEW |