2013-07-31 23:08:46 -06:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
/* A little code to ease navigation of these documents.
|
|
|
|
*
|
|
|
|
* On window load we:
|
|
|
|
* + Generate a table of contents (generateTOC)
|
|
|
|
* + Bind foldable sections (bindToggles)
|
|
|
|
* + Bind links to foldable sections (bindToggleLinks)
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2015-04-17 17:09:18 -06:00
|
|
|
// Mobile-friendly topbar menu
|
|
|
|
$(function() {
|
|
|
|
var menu = $('#menu');
|
|
|
|
var menuButton = $('#menu-button');
|
|
|
|
var menuButtonArrow = $('#menu-button-arrow');
|
|
|
|
menuButton.click(function(event) {
|
|
|
|
menu.toggleClass('menu-visible');
|
|
|
|
menuButtonArrow.toggleClass('vertical-flip');
|
|
|
|
event.preventDefault();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-31 23:08:46 -06:00
|
|
|
/* Generates a table of contents: looks for h2 and h3 elements and generates
|
|
|
|
* links. "Decorates" the element with id=="nav" with this table of contents.
|
|
|
|
*/
|
|
|
|
function generateTOC() {
|
|
|
|
if ($('#manual-nav').length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-11 02:03:17 -06:00
|
|
|
// For search, we send the toc precomputed from server-side.
|
|
|
|
// TODO: Ideally, this should always be precomputed for all pages, but then
|
|
|
|
// we need to do HTML parsing on the server-side.
|
|
|
|
if (location.pathname === '/search') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-31 23:08:46 -06:00
|
|
|
var nav = $('#nav');
|
|
|
|
if (nav.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var toc_items = [];
|
|
|
|
$(nav).nextAll('h2, h3').each(function() {
|
|
|
|
var node = this;
|
|
|
|
if (node.id == '')
|
|
|
|
node.id = 'tmp_' + toc_items.length;
|
|
|
|
var link = $('<a/>').attr('href', '#' + node.id).text($(node).text());
|
|
|
|
var item;
|
|
|
|
if ($(node).is('h2')) {
|
|
|
|
item = $('<dt/>');
|
|
|
|
} else { // h3
|
2015-04-17 17:09:18 -06:00
|
|
|
item = $('<dd class="indent"/>');
|
2013-07-31 23:08:46 -06:00
|
|
|
}
|
|
|
|
item.append(link);
|
|
|
|
toc_items.push(item);
|
|
|
|
});
|
|
|
|
if (toc_items.length <= 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var dl1 = $('<dl/>');
|
|
|
|
var dl2 = $('<dl/>');
|
|
|
|
|
|
|
|
var split_index = (toc_items.length / 2) + 1;
|
|
|
|
if (split_index < 8) {
|
|
|
|
split_index = toc_items.length;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < split_index; i++) {
|
|
|
|
dl1.append(toc_items[i]);
|
|
|
|
}
|
|
|
|
for (/* keep using i */; i < toc_items.length; i++) {
|
|
|
|
dl2.append(toc_items[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var tocTable = $('<table class="unruled"/>').appendTo(nav);
|
|
|
|
var tocBody = $('<tbody/>').appendTo(tocTable);
|
|
|
|
var tocRow = $('<tr/>').appendTo(tocBody);
|
|
|
|
|
|
|
|
// 1st column
|
|
|
|
$('<td class="first"/>').appendTo(tocRow).append(dl1);
|
|
|
|
// 2nd column
|
|
|
|
$('<td/>').appendTo(tocRow).append(dl2);
|
|
|
|
}
|
|
|
|
|
|
|
|
function bindToggle(el) {
|
|
|
|
$('.toggleButton', el).click(function() {
|
2017-01-05 18:20:21 -07:00
|
|
|
if ($(this).closest(".toggle, .toggleVisible")[0] != el) {
|
|
|
|
// Only trigger the closest toggle header.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-31 23:08:46 -06:00
|
|
|
if ($(el).is('.toggle')) {
|
|
|
|
$(el).addClass('toggleVisible').removeClass('toggle');
|
|
|
|
} else {
|
|
|
|
$(el).addClass('toggle').removeClass('toggleVisible');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-01-05 18:20:21 -07:00
|
|
|
|
2013-07-31 23:08:46 -06:00
|
|
|
function bindToggles(selector) {
|
|
|
|
$(selector).each(function(i, el) {
|
|
|
|
bindToggle(el);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function bindToggleLink(el, prefix) {
|
|
|
|
$(el).click(function() {
|
|
|
|
var href = $(el).attr('href');
|
|
|
|
var i = href.indexOf('#'+prefix);
|
|
|
|
if (i < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var id = '#' + prefix + href.slice(i+1+prefix.length);
|
|
|
|
if ($(id).is('.toggle')) {
|
|
|
|
$(id).find('.toggleButton').first().click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function bindToggleLinks(selector, prefix) {
|
|
|
|
$(selector).each(function(i, el) {
|
|
|
|
bindToggleLink(el, prefix);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupDropdownPlayground() {
|
|
|
|
if (!$('#page').is('.wide')) {
|
|
|
|
return; // don't show on front page
|
|
|
|
}
|
|
|
|
var button = $('#playgroundButton');
|
|
|
|
var div = $('#playground');
|
|
|
|
var setup = false;
|
|
|
|
button.toggle(function() {
|
|
|
|
button.addClass('active');
|
|
|
|
div.show();
|
|
|
|
if (setup) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setup = true;
|
|
|
|
playground({
|
|
|
|
'codeEl': $('.code', div),
|
|
|
|
'outputEl': $('.output', div),
|
|
|
|
'runEl': $('.run', div),
|
|
|
|
'fmtEl': $('.fmt', div),
|
|
|
|
'shareEl': $('.share', div),
|
2014-07-24 18:27:31 -06:00
|
|
|
'shareRedirect': '//play.golang.org/p/'
|
2013-07-31 23:08:46 -06:00
|
|
|
});
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
button.removeClass('active');
|
|
|
|
div.hide();
|
|
|
|
});
|
|
|
|
$('#menu').css('min-width', '+=60');
|
2018-08-15 06:38:08 -06:00
|
|
|
|
|
|
|
// Hide inline playground if we click somewhere on the page.
|
|
|
|
// This is needed in mobile devices, where the "Play" button
|
|
|
|
// is not clickable once the playground opens up.
|
|
|
|
$("#page").click(function() {
|
|
|
|
if (button.hasClass('active')) {
|
|
|
|
button.click();
|
|
|
|
}
|
|
|
|
});
|
2013-07-31 23:08:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function setupInlinePlayground() {
|
|
|
|
'use strict';
|
|
|
|
// Set up playground when each element is toggled.
|
|
|
|
$('div.play').each(function (i, el) {
|
|
|
|
// Set up playground for this example.
|
|
|
|
var setup = function() {
|
|
|
|
var code = $('.code', el);
|
|
|
|
playground({
|
|
|
|
'codeEl': code,
|
|
|
|
'outputEl': $('.output', el),
|
|
|
|
'runEl': $('.run', el),
|
|
|
|
'fmtEl': $('.fmt', el),
|
|
|
|
'shareEl': $('.share', el),
|
2014-07-24 18:27:31 -06:00
|
|
|
'shareRedirect': '//play.golang.org/p/'
|
2013-07-31 23:08:46 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
// Make the code textarea resize to fit content.
|
|
|
|
var resize = function() {
|
|
|
|
code.height(0);
|
|
|
|
var h = code[0].scrollHeight;
|
|
|
|
code.height(h+20); // minimize bouncing.
|
|
|
|
code.closest('.input').height(h);
|
|
|
|
};
|
|
|
|
code.on('keydown', resize);
|
|
|
|
code.on('keyup', resize);
|
|
|
|
code.keyup(); // resize now.
|
|
|
|
};
|
2018-01-24 19:48:19 -07:00
|
|
|
|
2013-07-31 23:08:46 -06:00
|
|
|
// If example already visible, set up playground now.
|
|
|
|
if ($(el).is(':visible')) {
|
|
|
|
setup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, set up playground when example is expanded.
|
|
|
|
var built = false;
|
|
|
|
$(el).closest('.toggle').click(function() {
|
|
|
|
// Only set up once.
|
|
|
|
if (!built) {
|
|
|
|
setup();
|
|
|
|
built = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// fixFocus tries to put focus to div#page so that keyboard navigation works.
|
|
|
|
function fixFocus() {
|
|
|
|
var page = $('div#page');
|
|
|
|
var topbar = $('div#topbar');
|
|
|
|
page.css('outline', 0); // disable outline when focused
|
|
|
|
page.attr('tabindex', -1); // and set tabindex so that it is focusable
|
|
|
|
$(window).resize(function (evt) {
|
|
|
|
// only focus page when the topbar is at fixed position (that is, it's in
|
|
|
|
// front of page, and keyboard event will go to the former by default.)
|
|
|
|
// by focusing page, keyboard event will go to page so that up/down arrow,
|
|
|
|
// space, etc. will work as expected.
|
|
|
|
if (topbar.css('position') == "fixed")
|
|
|
|
page.focus();
|
|
|
|
}).resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleHash() {
|
2017-02-03 20:16:49 -07:00
|
|
|
var id = window.location.hash.substring(1);
|
2017-01-05 18:20:21 -07:00
|
|
|
// Open all of the toggles for a particular hash.
|
2017-02-03 20:16:49 -07:00
|
|
|
var els = $(
|
|
|
|
document.getElementById(id),
|
|
|
|
$('a[name]').filter(function() {
|
|
|
|
return $(this).attr('name') == id;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2017-01-05 18:20:21 -07:00
|
|
|
while (els.length) {
|
|
|
|
for (var i = 0; i < els.length; i++) {
|
|
|
|
var el = $(els[i]);
|
|
|
|
if (el.is('.toggle')) {
|
|
|
|
el.find('.toggleButton').first().click();
|
|
|
|
}
|
2013-07-31 23:08:46 -06:00
|
|
|
}
|
2017-01-05 18:20:21 -07:00
|
|
|
els = el.parent();
|
|
|
|
}
|
2013-07-31 23:08:46 -06:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:36:28 -06:00
|
|
|
function personalizeInstallInstructions() {
|
|
|
|
var prefix = '?download=';
|
|
|
|
var s = window.location.search;
|
2015-08-23 13:25:07 -06:00
|
|
|
if (s.indexOf(prefix) != 0) {
|
2017-01-10 15:20:17 -07:00
|
|
|
// No 'download' query string; detect "test" instructions from User Agent.
|
|
|
|
if (navigator.platform.indexOf('Win') != -1) {
|
|
|
|
$('.testUnix').hide();
|
|
|
|
$('.testWindows').show();
|
|
|
|
} else {
|
|
|
|
$('.testUnix').show();
|
|
|
|
$('.testWindows').hide();
|
|
|
|
}
|
2015-08-04 21:36:28 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var filename = s.substr(prefix.length);
|
2015-08-05 00:22:07 -06:00
|
|
|
var filenameRE = /^go1\.\d+(\.\d+)?([a-z0-9]+)?\.([a-z0-9]+)(-[a-z0-9]+)?(-osx10\.[68])?\.([a-z.]+)$/;
|
2015-08-04 21:36:28 -06:00
|
|
|
var m = filenameRE.exec(filename);
|
|
|
|
if (!m) {
|
|
|
|
// Can't interpret file name; bail.
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 12:02:51 -06:00
|
|
|
$('.downloadFilename').text(filename);
|
|
|
|
$('.hideFromDownload').hide();
|
2015-08-04 21:36:28 -06:00
|
|
|
|
|
|
|
var os = m[3];
|
2015-08-05 00:22:07 -06:00
|
|
|
var ext = m[6];
|
2015-08-04 21:36:28 -06:00
|
|
|
if (ext != 'tar.gz') {
|
|
|
|
$('#tarballInstructions').hide();
|
|
|
|
}
|
|
|
|
if (os != 'darwin' || ext != 'pkg') {
|
|
|
|
$('#darwinPackageInstructions').hide();
|
|
|
|
}
|
|
|
|
if (os != 'windows') {
|
|
|
|
$('#windowsInstructions').hide();
|
2016-01-06 16:52:28 -07:00
|
|
|
$('.testUnix').show();
|
|
|
|
$('.testWindows').hide();
|
2015-08-04 21:36:28 -06:00
|
|
|
} else {
|
|
|
|
if (ext != 'msi') {
|
|
|
|
$('#windowsInstallerInstructions').hide();
|
|
|
|
}
|
|
|
|
if (ext != 'zip') {
|
|
|
|
$('#windowsZipInstructions').hide();
|
|
|
|
}
|
2016-01-06 16:52:28 -07:00
|
|
|
$('.testUnix').hide();
|
|
|
|
$('.testWindows').show();
|
2015-08-04 21:36:28 -06:00
|
|
|
}
|
2015-08-04 23:31:48 -06:00
|
|
|
|
2018-01-24 19:48:19 -07:00
|
|
|
var download = "https://dl.google.com/go/" + filename;
|
2015-08-04 23:31:48 -06:00
|
|
|
|
|
|
|
var message = $('<p class="downloading">'+
|
|
|
|
'Your download should begin shortly. '+
|
|
|
|
'If it does not, click <a>this link</a>.</p>');
|
|
|
|
message.find('a').attr('href', download);
|
|
|
|
message.insertAfter('#nav');
|
|
|
|
|
|
|
|
window.location = download;
|
2015-08-04 21:36:28 -06:00
|
|
|
}
|
|
|
|
|
2016-04-13 20:13:35 -06:00
|
|
|
function updateVersionTags() {
|
|
|
|
var v = window.goVersion;
|
|
|
|
if (/^go[0-9.]+$/.test(v)) {
|
|
|
|
$(".versionTag").empty().text(v);
|
|
|
|
$(".whereTag").hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 16:24:11 -07:00
|
|
|
function addPermalinks() {
|
|
|
|
function addPermalink(source, parent) {
|
|
|
|
var id = source.attr("id");
|
|
|
|
if (id == "" || id.indexOf("tmp_") === 0) {
|
|
|
|
// Auto-generated permalink.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parent.find("> .permalink").length) {
|
|
|
|
// Already attached.
|
|
|
|
return;
|
|
|
|
}
|
2017-10-24 14:45:43 -06:00
|
|
|
parent.append(" ").append($("<a class='permalink'>¶</a>").attr("href", "#" + id));
|
2016-11-28 16:24:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#page .container").find("h2[id], h3[id]").each(function() {
|
|
|
|
var el = $(this);
|
|
|
|
addPermalink(el, el);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#page .container").find("dl[id]").each(function() {
|
|
|
|
var el = $(this);
|
|
|
|
// Add the anchor to the "dt" element.
|
|
|
|
addPermalink(el, el.find("> dt").first());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-13 03:29:40 -06:00
|
|
|
$(".js-expandAll").click(function() {
|
|
|
|
if ($(this).hasClass("collapsed")) {
|
|
|
|
toggleExamples('toggle');
|
|
|
|
$(this).text("(Collapse All)");
|
|
|
|
} else {
|
|
|
|
toggleExamples('toggleVisible');
|
|
|
|
$(this).text("(Expand All)");
|
|
|
|
}
|
|
|
|
$(this).toggleClass("collapsed")
|
|
|
|
});
|
|
|
|
|
|
|
|
function toggleExamples(className) {
|
|
|
|
// We need to explicitly iterate through divs starting with "example_"
|
|
|
|
// to avoid toggling Overview and Index collapsibles.
|
|
|
|
$("[id^='example_']").each(function() {
|
|
|
|
// Check for state and click it only if required.
|
|
|
|
if ($(this).hasClass(className)) {
|
|
|
|
$(this).find('.toggleButton').first().click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-07-31 23:08:46 -06:00
|
|
|
$(document).ready(function() {
|
|
|
|
generateTOC();
|
2016-11-28 16:24:11 -07:00
|
|
|
addPermalinks();
|
2013-07-31 23:08:46 -06:00
|
|
|
bindToggles(".toggle");
|
|
|
|
bindToggles(".toggleVisible");
|
|
|
|
bindToggleLinks(".exampleLink", "example_");
|
|
|
|
bindToggleLinks(".overviewLink", "");
|
|
|
|
bindToggleLinks(".examplesLink", "");
|
|
|
|
bindToggleLinks(".indexLink", "");
|
|
|
|
setupDropdownPlayground();
|
|
|
|
setupInlinePlayground();
|
|
|
|
fixFocus();
|
2014-03-14 16:58:22 -06:00
|
|
|
setupTypeInfo();
|
|
|
|
setupCallgraphs();
|
2013-07-31 23:08:46 -06:00
|
|
|
toggleHash();
|
2015-08-04 21:36:28 -06:00
|
|
|
personalizeInstallInstructions();
|
2016-04-13 20:13:35 -06:00
|
|
|
updateVersionTags();
|
2013-07-31 23:08:46 -06:00
|
|
|
|
|
|
|
// godoc.html defines window.initFuncs in the <head> tag, and root.html and
|
|
|
|
// codewalk.js push their on-page-ready functions to the list.
|
|
|
|
// We execute those functions here, to avoid loading jQuery until the page
|
|
|
|
// content is loaded.
|
|
|
|
for (var i = 0; i < window.initFuncs.length; i++) window.initFuncs[i]();
|
|
|
|
});
|
|
|
|
|
2014-03-14 16:58:22 -06:00
|
|
|
// -- analysis ---------------------------------------------------------
|
|
|
|
|
|
|
|
// escapeHTML returns HTML for s, with metacharacters quoted.
|
|
|
|
// It is safe for use in both elements and attributes
|
|
|
|
// (unlike the "set innerText, read innerHTML" trick).
|
|
|
|
function escapeHTML(s) {
|
|
|
|
return s.replace(/&/g, '&').
|
|
|
|
replace(/\"/g, '"').
|
|
|
|
replace(/\'/g, ''').
|
|
|
|
replace(/</g, '<').
|
|
|
|
replace(/>/g, '>');
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeAnchor returns HTML for an <a> element, given an anchorJSON object.
|
|
|
|
function makeAnchor(json) {
|
|
|
|
var html = escapeHTML(json.Text);
|
|
|
|
if (json.Href != "") {
|
|
|
|
html = "<a href='" + escapeHTML(json.Href) + "'>" + html + "</a>";
|
|
|
|
}
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function showLowFrame(html) {
|
|
|
|
var lowframe = document.getElementById('lowframe');
|
|
|
|
lowframe.style.height = "200px";
|
|
|
|
lowframe.innerHTML = "<p style='text-align: left;'>" + html + "</p>\n" +
|
|
|
|
"<div onclick='hideLowFrame()' style='position: absolute; top: 0; right: 0; cursor: pointer;'>✘</div>"
|
|
|
|
};
|
|
|
|
|
|
|
|
document.hideLowFrame = function() {
|
|
|
|
var lowframe = document.getElementById('lowframe');
|
|
|
|
lowframe.style.height = "0px";
|
|
|
|
}
|
|
|
|
|
|
|
|
// onClickCallers is the onclick action for the 'func' tokens of a
|
|
|
|
// function declaration.
|
|
|
|
document.onClickCallers = function(index) {
|
|
|
|
var data = document.ANALYSIS_DATA[index]
|
|
|
|
if (data.Callers.length == 1 && data.Callers[0].Sites.length == 1) {
|
|
|
|
document.location = data.Callers[0].Sites[0].Href; // jump to sole caller
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var html = "Callers of <code>" + escapeHTML(data.Callee) + "</code>:<br/>\n";
|
|
|
|
for (var i = 0; i < data.Callers.length; i++) {
|
|
|
|
var caller = data.Callers[i];
|
|
|
|
html += "<code>" + escapeHTML(caller.Func) + "</code>";
|
|
|
|
var sites = caller.Sites;
|
|
|
|
if (sites != null && sites.length > 0) {
|
|
|
|
html += " at line ";
|
|
|
|
for (var j = 0; j < sites.length; j++) {
|
|
|
|
if (j > 0) {
|
|
|
|
html += ", ";
|
|
|
|
}
|
|
|
|
html += "<code>" + makeAnchor(sites[j]) + "</code>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
html += "<br/>\n";
|
|
|
|
}
|
|
|
|
showLowFrame(html);
|
|
|
|
};
|
|
|
|
|
|
|
|
// onClickCallees is the onclick action for the '(' token of a function call.
|
|
|
|
document.onClickCallees = function(index) {
|
|
|
|
var data = document.ANALYSIS_DATA[index]
|
|
|
|
if (data.Callees.length == 1) {
|
|
|
|
document.location = data.Callees[0].Href; // jump to sole callee
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var html = "Callees of this " + escapeHTML(data.Descr) + ":<br/>\n";
|
|
|
|
for (var i = 0; i < data.Callees.length; i++) {
|
|
|
|
html += "<code>" + makeAnchor(data.Callees[i]) + "</code><br/>\n";
|
|
|
|
}
|
|
|
|
showLowFrame(html);
|
|
|
|
};
|
|
|
|
|
|
|
|
// onClickTypeInfo is the onclick action for identifiers declaring a named type.
|
|
|
|
document.onClickTypeInfo = function(index) {
|
|
|
|
var data = document.ANALYSIS_DATA[index];
|
|
|
|
var html = "Type <code>" + data.Name + "</code>: " +
|
|
|
|
" <small>(size=" + data.Size + ", align=" + data.Align + ")</small><br/>\n";
|
|
|
|
html += implementsHTML(data);
|
|
|
|
html += methodsetHTML(data);
|
|
|
|
showLowFrame(html);
|
|
|
|
};
|
|
|
|
|
|
|
|
// implementsHTML returns HTML for the implements relation of the
|
|
|
|
// specified TypeInfoJSON value.
|
|
|
|
function implementsHTML(info) {
|
|
|
|
var html = "";
|
|
|
|
if (info.ImplGroups != null) {
|
|
|
|
for (var i = 0; i < info.ImplGroups.length; i++) {
|
|
|
|
var group = info.ImplGroups[i];
|
|
|
|
var x = "<code>" + escapeHTML(group.Descr) + "</code> ";
|
|
|
|
for (var j = 0; j < group.Facts.length; j++) {
|
|
|
|
var fact = group.Facts[j];
|
|
|
|
var y = "<code>" + makeAnchor(fact.Other) + "</code>";
|
|
|
|
if (fact.ByKind != null) {
|
|
|
|
html += escapeHTML(fact.ByKind) + " type " + y + " implements " + x;
|
|
|
|
} else {
|
|
|
|
html += x + " implements " + y;
|
|
|
|
}
|
|
|
|
html += "<br/>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// methodsetHTML returns HTML for the methodset of the specified
|
|
|
|
// TypeInfoJSON value.
|
|
|
|
function methodsetHTML(info) {
|
|
|
|
var html = "";
|
|
|
|
if (info.Methods != null) {
|
|
|
|
for (var i = 0; i < info.Methods.length; i++) {
|
|
|
|
html += "<code>" + makeAnchor(info.Methods[i]) + "</code><br/>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
// onClickComm is the onclick action for channel "make" and "<-"
|
|
|
|
// send/receive tokens.
|
|
|
|
document.onClickComm = function(index) {
|
|
|
|
var ops = document.ANALYSIS_DATA[index].Ops
|
|
|
|
if (ops.length == 1) {
|
|
|
|
document.location = ops[0].Op.Href; // jump to sole element
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var html = "Operations on this channel:<br/>\n";
|
|
|
|
for (var i = 0; i < ops.length; i++) {
|
|
|
|
html += makeAnchor(ops[i].Op) + " by <code>" + escapeHTML(ops[i].Fn) + "</code><br/>\n";
|
|
|
|
}
|
|
|
|
if (ops.length == 0) {
|
|
|
|
html += "(none)<br/>\n";
|
|
|
|
}
|
|
|
|
showLowFrame(html);
|
|
|
|
};
|
|
|
|
|
|
|
|
$(window).load(function() {
|
|
|
|
// Scroll window so that first selection is visible.
|
|
|
|
// (This means we don't need to emit id='L%d' spans for each line.)
|
|
|
|
// TODO(adonovan): ideally, scroll it so that it's under the pointer,
|
|
|
|
// but I don't know how to get the pointer y coordinate.
|
|
|
|
var elts = document.getElementsByClassName("selection");
|
|
|
|
if (elts.length > 0) {
|
|
|
|
elts[0].scrollIntoView()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// setupTypeInfo populates the "Implements" and "Method set" toggle for
|
|
|
|
// each type in the package doc.
|
|
|
|
function setupTypeInfo() {
|
|
|
|
for (var i in document.ANALYSIS_DATA) {
|
|
|
|
var data = document.ANALYSIS_DATA[i];
|
|
|
|
|
|
|
|
var el = document.getElementById("implements-" + i);
|
|
|
|
if (el != null) {
|
|
|
|
// el != null => data is TypeInfoJSON.
|
|
|
|
if (data.ImplGroups != null) {
|
|
|
|
el.innerHTML = implementsHTML(data);
|
|
|
|
el.parentNode.parentNode.style.display = "block";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var el = document.getElementById("methodset-" + i);
|
|
|
|
if (el != null) {
|
|
|
|
// el != null => data is TypeInfoJSON.
|
|
|
|
if (data.Methods != null) {
|
|
|
|
el.innerHTML = methodsetHTML(data);
|
|
|
|
el.parentNode.parentNode.style.display = "block";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupCallgraphs() {
|
|
|
|
if (document.CALLGRAPH == null) {
|
|
|
|
return
|
|
|
|
}
|
2014-03-27 13:30:14 -06:00
|
|
|
document.getElementById("pkg-callgraph").style.display = "block";
|
|
|
|
|
2014-03-14 16:58:22 -06:00
|
|
|
var treeviews = document.getElementsByClassName("treeview");
|
2014-09-15 11:00:40 -06:00
|
|
|
for (var i = 0; i < treeviews.length; i++) {
|
2014-03-14 16:58:22 -06:00
|
|
|
var tree = treeviews[i];
|
|
|
|
if (tree.id == null || tree.id.indexOf("callgraph-") != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var id = tree.id.substring("callgraph-".length);
|
|
|
|
$(tree).treeview({collapsed: true, animated: "fast"});
|
|
|
|
document.cgAddChildren(tree, tree, [id]);
|
|
|
|
tree.parentNode.parentNode.style.display = "block";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.cgAddChildren = function(tree, ul, indices) {
|
|
|
|
if (indices != null) {
|
|
|
|
for (var i = 0; i < indices.length; i++) {
|
|
|
|
var li = cgAddChild(tree, ul, document.CALLGRAPH[indices[i]]);
|
|
|
|
if (i == indices.length - 1) {
|
|
|
|
$(li).addClass("last");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(tree).treeview({animated: "fast", add: ul});
|
|
|
|
}
|
|
|
|
|
|
|
|
// cgAddChild adds an <li> element for document.CALLGRAPH node cgn to
|
|
|
|
// the parent <ul> element ul. tree is the tree's root <ul> element.
|
|
|
|
function cgAddChild(tree, ul, cgn) {
|
|
|
|
var li = document.createElement("li");
|
|
|
|
ul.appendChild(li);
|
|
|
|
li.className = "closed";
|
|
|
|
|
|
|
|
var code = document.createElement("code");
|
|
|
|
|
|
|
|
if (cgn.Callees != null) {
|
|
|
|
$(li).addClass("expandable");
|
|
|
|
|
|
|
|
// Event handlers and innerHTML updates don't play nicely together,
|
|
|
|
// hence all this explicit DOM manipulation.
|
|
|
|
var hitarea = document.createElement("div");
|
|
|
|
hitarea.className = "hitarea expandable-hitarea";
|
|
|
|
li.appendChild(hitarea);
|
|
|
|
|
|
|
|
li.appendChild(code);
|
|
|
|
|
|
|
|
var childUL = document.createElement("ul");
|
|
|
|
li.appendChild(childUL);
|
|
|
|
childUL.setAttribute('style', "display: none;");
|
|
|
|
|
|
|
|
var onClick = function() {
|
|
|
|
document.cgAddChildren(tree, childUL, cgn.Callees);
|
|
|
|
hitarea.removeEventListener('click', onClick)
|
|
|
|
};
|
|
|
|
hitarea.addEventListener('click', onClick);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
li.appendChild(code);
|
|
|
|
}
|
|
|
|
code.innerHTML += " " + makeAnchor(cgn.Func);
|
|
|
|
return li
|
|
|
|
}
|
|
|
|
|
2013-07-31 23:08:46 -06:00
|
|
|
})();
|