Bez popisu

webhtml.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. // Copyright 2017 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package driver
  15. import "html/template"
  16. // addTemplates adds a set of template definitions to templates.
  17. func addTemplates(templates *template.Template) {
  18. template.Must(templates.Parse(`
  19. {{define "css"}}
  20. <style type="text/css">
  21. html {
  22. height: 100%;
  23. min-height: 100%;
  24. margin: 0px;
  25. }
  26. body {
  27. margin: 0px;
  28. width: 100%;
  29. height: 100%;
  30. min-height: 100%;
  31. overflow: hidden;
  32. }
  33. #graphcontainer {
  34. display: flex;
  35. flex-direction: column;
  36. height: 100%;
  37. min-height: 100%;
  38. width: 100%;
  39. min-width: 100%;
  40. margin: 0px;
  41. }
  42. #graph {
  43. flex: 1 1 auto;
  44. overflow: hidden;
  45. }
  46. svg {
  47. width: 100%;
  48. height: auto;
  49. }
  50. button {
  51. margin-top: 5px;
  52. margin-bottom: 5px;
  53. }
  54. #detailtext {
  55. display: none;
  56. position: fixed;
  57. top: 20px;
  58. right: 10px;
  59. background-color: #ffffff;
  60. min-width: 160px;
  61. border: 1px solid #888;
  62. box-shadow: 4px 4px 4px 0px rgba(0,0,0,0.2);
  63. z-index: 1;
  64. }
  65. #closedetails {
  66. float: right;
  67. margin: 2px;
  68. }
  69. #home {
  70. font-size: 14pt;
  71. padding-left: 0.5em;
  72. padding-right: 0.5em;
  73. float: right;
  74. }
  75. .menubar {
  76. display: inline-block;
  77. background-color: #f8f8f8;
  78. border: 1px solid #ccc;
  79. width: 100%;
  80. }
  81. .menu-header {
  82. position: relative;
  83. display: inline-block;
  84. padding: 2px 2px;
  85. cursor: default;
  86. font-size: 14pt;
  87. }
  88. .menu {
  89. display: none;
  90. position: absolute;
  91. background-color: #f8f8f8;
  92. border: 1px solid #888;
  93. box-shadow: 4px 4px 4px 0px rgba(0,0,0,0.2);
  94. z-index: 1;
  95. margin-top: 2px;
  96. left: 0px;
  97. min-width: 5em;
  98. }
  99. .menu hr {
  100. background-color: #fff;
  101. margin-top: 0px;
  102. margin-bottom: 0px;
  103. }
  104. .menu a, .menu button {
  105. display: block;
  106. width: 100%;
  107. margin: 0px;
  108. padding: 2px 0px 2px 0px;
  109. text-align: left;
  110. text-decoration: none;
  111. color: #000;
  112. background-color: #f8f8f8;
  113. font-size: 12pt;
  114. border: none;
  115. }
  116. .menu-header:hover {
  117. background-color: #ccc;
  118. }
  119. .menu-header:hover .menu {
  120. display: block;
  121. }
  122. .menu a:hover, .menu button:hover {
  123. background-color: #ccc;
  124. }
  125. .menu a.disabled {
  126. color: gray;
  127. pointer-events: none;
  128. }
  129. #searchbox {
  130. margin-left: 10pt;
  131. }
  132. #bodycontainer {
  133. width: 100%;
  134. height: 100%;
  135. max-height: 100%;
  136. overflow: scroll;
  137. padding-top: 5px;
  138. }
  139. #toptable {
  140. border-spacing: 0px;
  141. width: 100%;
  142. }
  143. #toptable tr th {
  144. border-bottom: 1px solid black;
  145. text-align: right;
  146. padding-left: 1em;
  147. }
  148. #toptable tr th:nth-child(6) { text-align: left; }
  149. #toptable tr th:nth-child(7) { text-align: left; }
  150. #toptable tr td {
  151. padding-left: 1em;
  152. font: monospace;
  153. text-align: right;
  154. white-space: nowrap;
  155. cursor: default;
  156. }
  157. #toptable tr td:nth-child(6) {
  158. text-align: left;
  159. max-width: 30em; // Truncate very long names
  160. overflow: hidden;
  161. }
  162. #toptable tr td:nth-child(7) { text-align: left; }
  163. .hilite {
  164. background-color: #ccf;
  165. }
  166. </style>
  167. {{end}}
  168. {{define "header"}}
  169. <div id="detailtext">
  170. <button id="closedetails">Close</button>
  171. {{range .Legend}}<div>{{.}}</div>{{end}}
  172. </div>
  173. <div class="menubar">
  174. <div class="menu-header">
  175. View
  176. <div class="menu">
  177. <a title="{{.Help.top}}" href="/top" id="topbtn">Top</a>
  178. <a title="{{.Help.graph}}" href="/" id="graphbtn">Graph</a>
  179. <a title="{{.Help.peek}}" href="/peek" id="peek">Peek</a>
  180. <a title="{{.Help.list}}" href="/source" id="list">Source</a>
  181. <a title="{{.Help.disasm}}" href="/disasm" id="disasm">Disassemble</a>
  182. <hr>
  183. <button title="{{.Help.details}}" id="details">Details</button>
  184. </div>
  185. </div>
  186. <div class="menu-header">
  187. Refine
  188. <div class="menu">
  189. <a title="{{.Help.focus}}" href="{{.BaseURL}}" id="focus">Focus</a>
  190. <a title="{{.Help.ignore}}" href="{{.BaseURL}}" id="ignore">Ignore</a>
  191. <a title="{{.Help.hide}}" href="{{.BaseURL}}" id="hide">Hide</a>
  192. <a title="{{.Help.show}}" href="{{.BaseURL}}" id="show">Show</a>
  193. <hr>
  194. <a title="{{.Help.reset}}" href="{{.BaseURL}}">Reset</a>
  195. </div>
  196. </div>
  197. <input id="searchbox" type="text" placeholder="Search regexp" autocomplete="off" autocapitalize="none" size=40>
  198. <span id="home">{{.Title}}</span>
  199. </div> <!-- menubar -->
  200. <div id="errors">{{range .Errors}}<div>{{.}}</div>{{end}}</div>
  201. {{end}}
  202. {{define "graph" -}}
  203. <!DOCTYPE html>
  204. <html>
  205. <head>
  206. <meta charset="utf-8">
  207. <title>{{.Title}}</title>
  208. {{template "css" .}}
  209. </head>
  210. <body>
  211. {{template "header" .}}
  212. <div id="graphcontainer">
  213. <div id="graph">
  214. {{.HTMLBody}}
  215. </div>
  216. </div>
  217. {{template "script" .}}
  218. <script>viewer({{.BaseURL}}, {{.Nodes}})</script>
  219. </body>
  220. </html>
  221. {{end}}
  222. {{define "script"}}
  223. <script>
  224. // Make svg pannable and zoomable.
  225. // Call clickHandler(t) if a click event is caught by the pan event handlers.
  226. function initPanAndZoom(svg, clickHandler) {
  227. 'use strict';
  228. // Current mouse/touch handling mode
  229. const IDLE = 0
  230. const MOUSEPAN = 1
  231. const TOUCHPAN = 2
  232. const TOUCHZOOM = 3
  233. let mode = IDLE
  234. // State needed to implement zooming.
  235. let currentScale = 1.0
  236. const initWidth = svg.viewBox.baseVal.width
  237. const initHeight = svg.viewBox.baseVal.height
  238. // State needed to implement panning.
  239. let panLastX = 0 // Last event X coordinate
  240. let panLastY = 0 // Last event Y coordinate
  241. let moved = false // Have we seen significant movement
  242. let touchid = null // Current touch identifier
  243. // State needed for pinch zooming
  244. let touchid2 = null // Second id for pinch zooming
  245. let initGap = 1.0 // Starting gap between two touches
  246. let initScale = 1.0 // currentScale when pinch zoom started
  247. let centerPoint = null // Center point for scaling
  248. // Convert event coordinates to svg coordinates.
  249. function toSvg(x, y) {
  250. const p = svg.createSVGPoint()
  251. p.x = x
  252. p.y = y
  253. let m = svg.getCTM()
  254. if (m == null) m = svg.getScreenCTM() // Firefox workaround.
  255. return p.matrixTransform(m.inverse())
  256. }
  257. // Change the scaling for the svg to s, keeping the point denoted
  258. // by u (in svg coordinates]) fixed at the same screen location.
  259. function rescale(s, u) {
  260. // Limit to a good range.
  261. if (s < 0.2) s = 0.2
  262. if (s > 10.0) s = 10.0
  263. currentScale = s
  264. // svg.viewBox defines the visible portion of the user coordinate
  265. // system. So to magnify by s, divide the visible portion by s,
  266. // which will then be stretched to fit the viewport.
  267. const vb = svg.viewBox
  268. const w1 = vb.baseVal.width
  269. const w2 = initWidth / s
  270. const h1 = vb.baseVal.height
  271. const h2 = initHeight / s
  272. vb.baseVal.width = w2
  273. vb.baseVal.height = h2
  274. // We also want to adjust vb.baseVal.x so that u.x remains at same
  275. // screen X coordinate. In other words, want to change it from x1 to x2
  276. // so that:
  277. // (u.x - x1) / w1 = (u.x - x2) / w2
  278. // Simplifying that, we get
  279. // (u.x - x1) * (w2 / w1) = u.x - x2
  280. // x2 = u.x - (u.x - x1) * (w2 / w1)
  281. vb.baseVal.x = u.x - (u.x - vb.baseVal.x) * (w2 / w1)
  282. vb.baseVal.y = u.y - (u.y - vb.baseVal.y) * (h2 / h1)
  283. }
  284. function handleWheel(e) {
  285. if (e.deltaY == 0) return
  286. // Change scale factor by 1.1 or 1/1.1
  287. rescale(currentScale * (e.deltaY < 0 ? 1.1 : (1/1.1)),
  288. toSvg(e.offsetX, e.offsetY))
  289. }
  290. function setMode(m) {
  291. mode = m
  292. touchid = null
  293. touchid2 = null
  294. }
  295. function panStart(x, y) {
  296. moved = false
  297. panLastX = x
  298. panLastY = y
  299. }
  300. function panMove(x, y) {
  301. let dx = x - panLastX
  302. let dy = y - panLastY
  303. if (Math.abs(dx) <= 2 && Math.abs(dy) <= 2) return // Ignore tiny moves
  304. moved = true
  305. panLastX = x
  306. panLastY = y
  307. // Firefox workaround: get dimensions from parentNode.
  308. const swidth = svg.clientWidth || svg.parentNode.clientWidth
  309. const sheight = svg.clientHeight || svg.parentNode.clientHeight
  310. // Convert deltas from screen space to svg space.
  311. dx *= (svg.viewBox.baseVal.width / swidth)
  312. dy *= (svg.viewBox.baseVal.height / sheight)
  313. svg.viewBox.baseVal.x -= dx
  314. svg.viewBox.baseVal.y -= dy
  315. }
  316. function handleScanStart(e) {
  317. if (e.button != 0) return // Do not catch right-clicks etc.
  318. setMode(MOUSEPAN)
  319. panStart(e.clientX, e.clientY)
  320. e.preventDefault()
  321. svg.addEventListener("mousemove", handleScanMove)
  322. }
  323. function handleScanMove(e) {
  324. if (e.buttons == 0) {
  325. // Missed an end event, perhaps because mouse moved outside window.
  326. setMode(IDLE)
  327. svg.removeEventListener("mousemove", handleScanMove)
  328. return
  329. }
  330. if (mode == MOUSEPAN) panMove(e.clientX, e.clientY)
  331. }
  332. function handleScanEnd(e) {
  333. if (mode == MOUSEPAN) panMove(e.clientX, e.clientY)
  334. setMode(IDLE)
  335. svg.removeEventListener("mousemove", handleScanMove)
  336. if (!moved) clickHandler(e.target)
  337. }
  338. // Find touch object with specified identifier.
  339. function findTouch(tlist, id) {
  340. for (const t of tlist) {
  341. if (t.identifier == id) return t
  342. }
  343. return null
  344. }
  345. // Return distance between two touch points
  346. function touchGap(t1, t2) {
  347. const dx = t1.clientX - t2.clientX
  348. const dy = t1.clientY - t2.clientY
  349. return Math.hypot(dx, dy)
  350. }
  351. function handleTouchStart(e) {
  352. if (mode == IDLE && e.changedTouches.length == 1) {
  353. // Start touch based panning
  354. const t = e.changedTouches[0]
  355. setMode(TOUCHPAN)
  356. touchid = t.identifier
  357. panStart(t.clientX, t.clientY)
  358. e.preventDefault()
  359. } else if (mode == TOUCHPAN && e.touches.length == 2) {
  360. // Start pinch zooming
  361. setMode(TOUCHZOOM)
  362. const t1 = e.touches[0]
  363. const t2 = e.touches[1]
  364. touchid = t1.identifier
  365. touchid2 = t2.identifier
  366. initScale = currentScale
  367. initGap = touchGap(t1, t2)
  368. centerPoint = toSvg((t1.clientX + t2.clientX) / 2,
  369. (t1.clientY + t2.clientY) / 2)
  370. e.preventDefault()
  371. }
  372. }
  373. function handleTouchMove(e) {
  374. if (mode == TOUCHPAN) {
  375. const t = findTouch(e.changedTouches, touchid)
  376. if (t == null) return
  377. if (e.touches.length != 1) {
  378. setMode(IDLE)
  379. return
  380. }
  381. panMove(t.clientX, t.clientY)
  382. e.preventDefault()
  383. } else if (mode == TOUCHZOOM) {
  384. // Get two touches; new gap; rescale to ratio.
  385. const t1 = findTouch(e.touches, touchid)
  386. const t2 = findTouch(e.touches, touchid2)
  387. if (t1 == null || t2 == null) return
  388. const gap = touchGap(t1, t2)
  389. rescale(initScale * gap / initGap, centerPoint)
  390. e.preventDefault()
  391. }
  392. }
  393. function handleTouchEnd(e) {
  394. if (mode == TOUCHPAN) {
  395. const t = findTouch(e.changedTouches, touchid)
  396. if (t == null) return
  397. panMove(t.clientX, t.clientY)
  398. setMode(IDLE)
  399. e.preventDefault()
  400. if (!moved) clickHandler(t.target)
  401. } else if (mode == TOUCHZOOM) {
  402. setMode(IDLE)
  403. e.preventDefault()
  404. }
  405. }
  406. svg.addEventListener("mousedown", handleScanStart)
  407. svg.addEventListener("mouseup", handleScanEnd)
  408. svg.addEventListener("touchstart", handleTouchStart)
  409. svg.addEventListener("touchmove", handleTouchMove)
  410. svg.addEventListener("touchend", handleTouchEnd)
  411. svg.addEventListener("wheel", handleWheel, true)
  412. }
  413. function viewer(baseUrl, nodes) {
  414. 'use strict';
  415. // Elements
  416. const search = document.getElementById("searchbox")
  417. const graph0 = document.getElementById("graph0")
  418. const svg = (graph0 == null ? null : graph0.parentElement)
  419. const toptable = document.getElementById("toptable")
  420. let regexpActive = false
  421. let selected = new Map()
  422. let origFill = new Map()
  423. let searchAlarm = null
  424. let buttonsEnabled = true
  425. function handleDetails() {
  426. const detailsText = document.getElementById("detailtext")
  427. if (detailsText != null) detailsText.style.display = "block"
  428. }
  429. function handleCloseDetails() {
  430. const detailsText = document.getElementById("detailtext")
  431. if (detailsText != null) detailsText.style.display = "none"
  432. }
  433. function handleKey(e) {
  434. if (e.keyCode != 13) return
  435. window.location.href =
  436. updateUrl(new URL({{.BaseURL}}, window.location.href), "f")
  437. e.preventDefault()
  438. }
  439. function handleSearch() {
  440. // Delay expensive processing so a flurry of key strokes is handled once.
  441. if (searchAlarm != null) {
  442. clearTimeout(searchAlarm)
  443. }
  444. searchAlarm = setTimeout(selectMatching, 300)
  445. regexpActive = true
  446. updateButtons()
  447. }
  448. function selectMatching() {
  449. searchAlarm = null
  450. let re = null
  451. if (search.value != "") {
  452. try {
  453. re = new RegExp(search.value)
  454. } catch (e) {
  455. // TODO: Display error state in search box
  456. return
  457. }
  458. }
  459. function match(text) {
  460. return re != null && re.test(text)
  461. }
  462. // drop currently selected items that do not match re.
  463. selected.forEach(function(v, n) {
  464. if (!match(nodes[n])) {
  465. unselect(n, document.getElementById("node" + n))
  466. }
  467. })
  468. // add matching items that are not currently selected.
  469. for (let n = 0; n < nodes.length; n++) {
  470. if (!selected.has(n) && match(nodes[n])) {
  471. select(n, document.getElementById("node" + n))
  472. }
  473. }
  474. updateButtons()
  475. }
  476. function toggleSvgSelect(elem) {
  477. // Walk up to immediate child of graph0
  478. while (elem != null && elem.parentElement != graph0) {
  479. elem = elem.parentElement
  480. }
  481. if (!elem) return
  482. // Disable regexp mode.
  483. regexpActive = false
  484. const n = nodeId(elem)
  485. if (n < 0) return
  486. if (selected.has(n)) {
  487. unselect(n, elem)
  488. } else {
  489. select(n, elem)
  490. }
  491. updateButtons()
  492. }
  493. function unselect(n, elem) {
  494. if (elem == null) return
  495. selected.delete(n)
  496. setBackground(elem, false)
  497. }
  498. function select(n, elem) {
  499. if (elem == null) return
  500. selected.set(n, true)
  501. setBackground(elem, true)
  502. }
  503. function nodeId(elem) {
  504. const id = elem.id
  505. if (!id) return -1
  506. if (!id.startsWith("node")) return -1
  507. const n = parseInt(id.slice(4), 10)
  508. if (isNaN(n)) return -1
  509. if (n < 0 || n >= nodes.length) return -1
  510. return n
  511. }
  512. function setBackground(elem, set) {
  513. // Handle table row highlighting.
  514. if (elem.nodeName == "TR") {
  515. elem.classList.toggle("hilite", set)
  516. return
  517. }
  518. // Handle svg element highlighting.
  519. const p = findPolygon(elem)
  520. if (p != null) {
  521. if (set) {
  522. origFill.set(p, p.style.fill)
  523. p.style.fill = "#ccccff"
  524. } else if (origFill.has(p)) {
  525. p.style.fill = origFill.get(p)
  526. }
  527. }
  528. }
  529. function findPolygon(elem) {
  530. if (elem.localName == "polygon") return elem
  531. for (const c of elem.children) {
  532. const p = findPolygon(c)
  533. if (p != null) return p
  534. }
  535. return null
  536. }
  537. // convert a string to a regexp that matches that string.
  538. function quotemeta(str) {
  539. return str.replace(/([\\\.?+*\[\](){}|^$])/g, '\\$1')
  540. }
  541. // Update id's href to reflect current selection whenever it is
  542. // liable to be followed.
  543. function makeLinkDynamic(id) {
  544. const elem = document.getElementById(id)
  545. if (elem == null) return
  546. // Most links copy current selection into the "f" parameter,
  547. // but Refine menu links are different.
  548. let param = "f"
  549. if (id == "ignore") param = "i"
  550. if (id == "hide") param = "h"
  551. if (id == "show") param = "s"
  552. // We update on mouseenter so middle-click/right-click work properly.
  553. elem.addEventListener("mouseenter", updater)
  554. elem.addEventListener("touchstart", updater)
  555. function updater() {
  556. elem.href = updateUrl(new URL(elem.href), param)
  557. }
  558. }
  559. // Update URL to reflect current selection.
  560. function updateUrl(url, param) {
  561. url.hash = ""
  562. // The selection can be in one of two modes: regexp-based or
  563. // list-based. Construct regular expression depending on mode.
  564. let re = regexpActive
  565. ? search.value
  566. : Array.from(selected.keys()).map(key => quotemeta(nodes[key])).join("|")
  567. // Copy params from this page's URL.
  568. const params = url.searchParams
  569. for (const p of new URLSearchParams(window.location.search)) {
  570. params.set(p[0], p[1])
  571. }
  572. if (re != "") {
  573. // For focus/show, forget old parameter. For others, add to re.
  574. if (param != "f" && param != "s" && params.has(param)) {
  575. const old = params.get(param)
  576. if (old != "") {
  577. re += "|" + old
  578. }
  579. }
  580. params.set(param, re)
  581. }
  582. return url.toString()
  583. }
  584. function handleTopClick(e) {
  585. // Walk back until we find TR and then get the Name column (index 5)
  586. let elem = e.target
  587. while (elem != null && elem.nodeName != "TR") {
  588. elem = elem.parentElement
  589. }
  590. if (elem == null || elem.children.length < 6) return
  591. e.preventDefault()
  592. const tr = elem
  593. const td = elem.children[5]
  594. if (td.nodeName != "TD") return
  595. const name = td.innerText
  596. const index = nodes.indexOf(name)
  597. if (index < 0) return
  598. // Disable regexp mode.
  599. regexpActive = false
  600. if (selected.has(index)) {
  601. unselect(index, elem)
  602. } else {
  603. select(index, elem)
  604. }
  605. updateButtons()
  606. }
  607. function updateButtons() {
  608. const enable = (search.value != "" || selected.size != 0)
  609. if (buttonsEnabled == enable) return
  610. buttonsEnabled = enable
  611. for (const id of ["focus", "ignore", "hide", "show"]) {
  612. const link = document.getElementById(id)
  613. if (link != null) {
  614. link.classList.toggle("disabled", !enable)
  615. }
  616. }
  617. }
  618. // Initialize button states
  619. updateButtons()
  620. // Setup event handlers
  621. if (svg != null) {
  622. initPanAndZoom(svg, toggleSvgSelect)
  623. }
  624. if (toptable != null) {
  625. toptable.addEventListener("mousedown", handleTopClick)
  626. toptable.addEventListener("touchstart", handleTopClick)
  627. }
  628. const ids = ["topbtn", "graphbtn", "peek", "list", "disasm",
  629. "focus", "ignore", "hide", "show"]
  630. ids.forEach(makeLinkDynamic)
  631. // Bind action to button with specified id.
  632. function addAction(id, action) {
  633. const btn = document.getElementById(id)
  634. if (btn != null) {
  635. btn.addEventListener("click", action)
  636. btn.addEventListener("touchstart", action)
  637. }
  638. }
  639. addAction("details", handleDetails)
  640. addAction("closedetails", handleCloseDetails)
  641. search.addEventListener("input", handleSearch)
  642. search.addEventListener("keydown", handleKey)
  643. // Give initial focus to main container so it can be scrolled using keys.
  644. const main = document.getElementById("bodycontainer")
  645. if (main) {
  646. main.focus()
  647. }
  648. }
  649. </script>
  650. {{end}}
  651. {{define "top" -}}
  652. <!DOCTYPE html>
  653. <html>
  654. <head>
  655. <meta charset="utf-8">
  656. <title>{{.Title}}</title>
  657. {{template "css" .}}
  658. </head>
  659. <body>
  660. {{template "header" .}}
  661. <div id="bodycontainer">
  662. <table id="toptable">
  663. <tr><th>Flat<th>Flat%<th>Sum%<th>Cum<th>Cum%<th>Name<th>Inlined?</tr>
  664. {{range $i,$e := .Top}}
  665. <tr id="node{{$i}}"><td>{{$e.Flat}}<td>{{$e.FlatPercent}}<td>{{$e.SumPercent}}<td>{{$e.Cum}}<td>{{$e.CumPercent}}<td>{{$e.Name}}<td>{{$e.InlineLabel}}</tr>
  666. {{end}}
  667. </table>
  668. </div>
  669. {{template "script" .}}
  670. <script>viewer({{.BaseURL}}, {{.Nodes}})</script>
  671. </body>
  672. </html>
  673. {{end}}
  674. {{define "sourcelisting" -}}
  675. <!DOCTYPE html>
  676. <html>
  677. <head>
  678. <meta charset="utf-8">
  679. <title>{{.Title}}</title>
  680. {{template "css" .}}
  681. {{template "weblistcss" .}}
  682. {{template "weblistjs" .}}
  683. </head>
  684. <body>
  685. {{template "header" .}}
  686. <div id="bodycontainer">
  687. {{.HTMLBody}}
  688. </div>
  689. {{template "script" .}}
  690. <script>viewer({{.BaseURL}}, null)</script>
  691. </body>
  692. </html>
  693. {{end}}
  694. {{define "plaintext" -}}
  695. <!DOCTYPE html>
  696. <html>
  697. <head>
  698. <meta charset="utf-8">
  699. <title>{{.Title}}</title>
  700. {{template "css" .}}
  701. </head>
  702. <body>
  703. {{template "header" .}}
  704. <div id="bodycontainer">
  705. <pre>
  706. {{.TextBody}}
  707. </pre>
  708. </div>
  709. {{template "script" .}}
  710. <script>viewer({{.BaseURL}}, null)</script>
  711. </body>
  712. </html>
  713. {{end}}
  714. `))
  715. }