-
Notifications
You must be signed in to change notification settings - Fork 1
/
client-shared.dart
33 lines (29 loc) · 1.07 KB
/
client-shared.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Code shared between the different client-side libraries.
/**
* Finds all code blocks and makes them toggleable. Syntax highlights each
* code block the first time it's shown.
*/
enableCodeBlocks() {
for (var elem in document.queryAll('.method, .field')) {
var showCode = elem.query('.show-code');
// Skip it if we don't have a code link. Will happen if source code is
// disabled.
if (showCode == null) continue;
var pre = elem.query('pre.source');
showCode.on.click.add((e) {
if (pre.classes.contains('expanded')) {
pre.classes.remove('expanded');
} else {
// Syntax highlight.
if (!pre.classes.contains('formatted')) {
pre.innerHTML = classifySource(new frog.SourceFile('', pre.text));
pre.classes.add('formatted');
};
pre.classes.add('expanded');
}
});
}
}