| 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 // Code shared between the different client-side libraries. | |
| 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 | |
| 22 /** | |
| 23 * Finds all code blocks and makes them toggleable. Syntax highlights each | |
| 24 * code block the first time it's shown. | |
| 25 */ | |
| 26 enableCodeBlocks() { | |
| 27 for (var elem in document.queryAll('.method, .field')) { | |
| 28 var showCode = elem.query('.show-code'); | |
| 29 | |
| 30 // Skip it if we don't have a code link. Will happen if source code is | |
| 31 // disabled. | |
| 32 if (showCode == null) continue; | |
| 33 | |
| 34 var pre = elem.query('pre.source'); | |
| 35 | |
| 36 showCode.on.click.add((e) { | |
| 37 if (pre.classes.contains('expanded')) { | |
| 38 pre.classes.remove('expanded'); | |
| 39 } else { | |
| 40 // Syntax highlight. | |
| 41 if (!pre.classes.contains('formatted')) { | |
| 42 pre.innerHTML = classifySource(pre.text); | |
| 43 pre.classes.add('formatted'); | |
| 44 }; | |
| 45 pre.classes.add('expanded'); | |
| 46 } | |
| 47 }); | |
| 48 } | |
| 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 |