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 // Code shared between the different client-side libraries. | 5 // Code shared between the different client-side libraries. |
6 | 6 |
| 7 // The names of the library and type that this page documents. |
| 8 String currentLibrary = null; |
| 9 String currentType = null; |
| 10 |
| 11 // What we need to prefix relative URLs with to get them to work. |
| 12 String prefix = ''; |
| 13 |
| 14 void setupLocation() { |
| 15 // Figure out where we are. |
| 16 final body = document.query('body'); |
| 17 currentLibrary = body.dataAttributes['library']; |
| 18 currentType = body.dataAttributes['type']; |
| 19 prefix = (currentType != null) ? '../' : ''; |
| 20 } |
| 21 |
7 /** | 22 /** |
8 * Finds all code blocks and makes them toggleable. Syntax highlights each | 23 * Finds all code blocks and makes them toggleable. Syntax highlights each |
9 * code block the first time it's shown. | 24 * code block the first time it's shown. |
10 */ | 25 */ |
11 enableCodeBlocks() { | 26 enableCodeBlocks() { |
12 for (var elem in document.queryAll('.method, .field')) { | 27 for (var elem in document.queryAll('.method, .field')) { |
13 var showCode = elem.query('.show-code'); | 28 var showCode = elem.query('.show-code'); |
14 | 29 |
15 // Skip it if we don't have a code link. Will happen if source code is | 30 // Skip it if we don't have a code link. Will happen if source code is |
16 // disabled. | 31 // disabled. |
17 if (showCode == null) continue; | 32 if (showCode == null) continue; |
18 | 33 |
19 var pre = elem.query('pre.source'); | 34 var pre = elem.query('pre.source'); |
20 | 35 |
21 showCode.on.click.add((e) { | 36 showCode.on.click.add((e) { |
22 if (pre.classes.contains('expanded')) { | 37 if (pre.classes.contains('expanded')) { |
23 pre.classes.remove('expanded'); | 38 pre.classes.remove('expanded'); |
24 } else { | 39 } else { |
25 // Syntax highlight. | 40 // Syntax highlight. |
26 if (!pre.classes.contains('formatted')) { | 41 if (!pre.classes.contains('formatted')) { |
27 pre.innerHTML = classifySource(pre.text); | 42 pre.innerHTML = classifySource(pre.text); |
28 pre.classes.add('formatted'); | 43 pre.classes.add('formatted'); |
29 }; | 44 }; |
30 pre.classes.add('expanded'); | 45 pre.classes.add('expanded'); |
31 } | 46 } |
32 }); | 47 }); |
33 | |
34 } | 48 } |
35 } | 49 } |
| 50 |
| 51 |
| 52 /** Turns [name] into something that's safe to use as a file name. */ |
| 53 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_'); |
| 54 |
| 55 String getTypeName(Map typeInfo) => |
| 56 typeInfo.containsKey('args') |
| 57 ? '${typeInfo[NAME]}<${typeInfo[NAME]}>' |
| 58 : typeInfo[NAME]; |
| 59 |
| 60 String getLibraryUrl(String libraryName) => |
| 61 '$prefix${sanitize(libraryName)}.html'; |
| 62 |
| 63 String getTypeUrl(String libraryName, Map typeInfo) => |
| 64 '$prefix${sanitize(libraryName)}/${sanitize(typeInfo[NAME])}.html'; |
| 65 |
| 66 String getLibraryMemberUrl(String libraryName, Map memberInfo) => |
| 67 '$prefix${sanitize(libraryName)}.html#${getMemberAnchor(memberInfo)}'; |
| 68 |
| 69 String getTypeMemberUrl(String libraryName, String typeName, Map memberInfo) => |
| 70 '$prefix${sanitize(libraryName)}/${sanitize(typeName)}.html#' |
| 71 '${getMemberAnchor(memberInfo)}'; |
| 72 |
| 73 String getMemberAnchor(Map memberInfo) => memberInfo.containsKey(LINK_NAME) |
| 74 ? memberInfo[LINK_NAME] : memberInfo[NAME]; |
OLD | NEW |