| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** Provides client-side behavior for generated docs. */ | 5 /** Provides client-side behavior for generated docs. */ |
| 6 #library('client-live-nav'); | 6 #library('client-live-nav'); |
| 7 | 7 |
| 8 #import('dart:html'); | 8 #import('dart:html'); |
| 9 #import('dart:json'); | 9 #import('dart:json'); |
| 10 #import('../../frog/lang.dart', prefix: 'frog'); | 10 #import('../../frog/lang.dart', prefix: 'frog'); |
| 11 #import('classify.dart'); | 11 #import('classify.dart'); |
| 12 #import('markdown.dart', prefix: 'md'); | 12 #import('markdown.dart', prefix: 'md'); |
| 13 | 13 |
| 14 #source('client-shared.dart'); | 14 #source('client-shared.dart'); |
| 15 | 15 |
| 16 // The names of the library and type that this page documents. | 16 // The names of the library and type that this page documents. |
| 17 String currentLibrary = null; | 17 String currentLibrary = null; |
| 18 String currentType = null; | 18 String currentType = null; |
| 19 | 19 |
| 20 // What we need to prefix relative URLs with to get them to work. | 20 // What we need to prefix relative URLs with to get them to work. |
| 21 String prefix = ''; | 21 String prefix = ''; |
| 22 | 22 |
| 23 main() { | 23 main() { |
| 24 // Figure out where we are. | 24 window.on.contentLoaded.add((e) { |
| 25 final body = document.query('body'); | 25 // Figure out where we are. |
| 26 currentLibrary = body.dataAttributes['library']; | 26 final body = document.query('body'); |
| 27 currentType = body.dataAttributes['type']; | 27 currentLibrary = body.dataAttributes['library']; |
| 28 prefix = (currentType != null) ? '../' : ''; | 28 currentType = body.dataAttributes['type']; |
| 29 prefix = (currentType != null) ? '../' : ''; |
| 29 | 30 |
| 30 enableCodeBlocks(); | 31 enableCodeBlocks(); |
| 31 | 32 |
| 32 // Request the navigation data so we can build the HTML for it. | 33 // Request the navigation data so we can build the HTML for it. |
| 33 new XMLHttpRequest.getTEMPNAME('${prefix}nav.json', (request) { | 34 new XMLHttpRequest.getTEMPNAME('${prefix}nav.json', (request) { |
| 34 buildNavigation(JSON.parse(request.responseText)); | 35 buildNavigation(JSON.parse(request.responseText)); |
| 36 }); |
| 35 }); | 37 }); |
| 36 } | 38 } |
| 37 | 39 |
| 38 /** Turns [name] into something that's safe to use as a file name. */ | 40 /** Turns [name] into something that's safe to use as a file name. */ |
| 39 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_'); | 41 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_'); |
| 40 | 42 |
| 41 /** | 43 /** |
| 42 * Takes [libraries], a JSON object representing a set of libraries and builds | 44 * Takes [libraries], a JSON object representing a set of libraries and builds |
| 43 * the appropriate navigation DOM for it relative to the current library and | 45 * the appropriate navigation DOM for it relative to the current library and |
| 44 * type. | 46 * type. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 '''); | 101 '''); |
| 100 } | 102 } |
| 101 html.add('</li>'); | 103 html.add('</li>'); |
| 102 } | 104 } |
| 103 | 105 |
| 104 html.add('<ul class="icon">'); | 106 html.add('<ul class="icon">'); |
| 105 types.forEach((type) => writeType(type['kind'], type)); | 107 types.forEach((type) => writeType(type['kind'], type)); |
| 106 exceptions.forEach((type) => writeType('exception', type)); | 108 exceptions.forEach((type) => writeType('exception', type)); |
| 107 html.add('</ul>'); | 109 html.add('</ul>'); |
| 108 } | 110 } |
| OLD | NEW |