mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
godoc: inject treeview content only when needed
- This shaves off 12.8KB (unzipped) / 3.8KB (zipped) downloadable data and around 6ms of javascript parse time when the files are not injected. - Also, conditionally rendering the callgraph html only when callgraph is actually present. - Removed the "text/javascript" attribute as it is the default value now. Change-Id: I70c030bdda2a054c181b2b3a693842bafed88d1a Reviewed-on: https://go-review.googlesource.com/c/115875 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
48cd23a0c8
commit
c75e7e6983
@ -23,6 +23,7 @@ type Page struct {
|
||||
Query string
|
||||
Body []byte
|
||||
GoogleCN bool // page is being served from golang.google.cn
|
||||
TreeView bool // page needs to contain treeview related js and css
|
||||
|
||||
// filled in by ServePage
|
||||
SearchBox bool
|
||||
|
@ -315,6 +315,7 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Emit JSON array for type information.
|
||||
pi := h.c.Analysis.PackageInfo(relpath)
|
||||
hasTreeView := len(pi.CallGraph) != 0
|
||||
info.CallGraphIndex = pi.CallGraphIndex
|
||||
info.CallGraph = htmltemplate.JS(marshalJSON(pi.CallGraph))
|
||||
info.AnalysisData = htmltemplate.JS(marshalJSON(pi.Types))
|
||||
@ -336,6 +337,7 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
Subtitle: subtitle,
|
||||
Body: body,
|
||||
GoogleCN: info.GoogleCN,
|
||||
TreeView: hasTreeView,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,9 @@
|
||||
{{if .SearchBox}}
|
||||
<link rel="search" type="application/opensearchdescription+xml" title="godoc" href="/opensearch.xml" />
|
||||
{{end}}
|
||||
{{if .TreeView}}
|
||||
<link rel="stylesheet" href="/lib/godoc/jquery.treeview.css">
|
||||
{{end}}
|
||||
<script>window.initFuncs = [];</script>
|
||||
{{with .GoogleAnalytics}}
|
||||
<script type="text/javascript">
|
||||
@ -29,8 +31,10 @@ window.trackEvent = function(category, action, opt_label, opt_value, opt_noninte
|
||||
</script>
|
||||
{{end}}
|
||||
<script src="/lib/godoc/jquery.js" defer></script>
|
||||
{{if .TreeView}}
|
||||
<script src="/lib/godoc/jquery.treeview.js" defer></script>
|
||||
<script src="/lib/godoc/jquery.treeview.edit.js" defer></script>
|
||||
{{end}}
|
||||
|
||||
{{if .Playground}}
|
||||
<script src="/lib/godoc/playground.js" defer></script>
|
||||
|
@ -10,7 +10,7 @@
|
||||
correspond to Go identifiers).
|
||||
-->
|
||||
{{with .PDoc}}
|
||||
<script type='text/javascript'>
|
||||
<script>
|
||||
document.ANALYSIS_DATA = {{$.AnalysisData}};
|
||||
document.CALLGRAPH = {{$.CallGraph}};
|
||||
</script>
|
||||
@ -112,6 +112,7 @@
|
||||
</div><!-- .expanded -->
|
||||
</div><!-- #pkg-index -->
|
||||
|
||||
{{if ne $.CallGraph "null"}}
|
||||
<div id="pkg-callgraph" class="toggle" style="display: none">
|
||||
<div class="collapsed">
|
||||
<h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
|
||||
@ -148,6 +149,7 @@
|
||||
<ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
|
||||
</div>
|
||||
</div> <!-- #pkg-callgraph -->
|
||||
{{end}}
|
||||
|
||||
{{with .Consts}}
|
||||
<h2 id="pkg-constants">Constants</h2>
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user