// 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: * + Bind search box hint placeholder show/hide events (bindSearchEvents) * + Generate a table of contents (generateTOC) * + Bind foldable sections (bindToggles) * + Bind links to foldable sections (bindToggleLinks) */ (function() { 'use strict'; function bindSearchEvents() { var search = $('#search'); if (search.length === 0) { return; // no search box } function clearInactive() { if (search.is('.inactive')) { search.val(''); search.removeClass('inactive'); } } function restoreInactive() { if (search.val() !== '') { return; } search.val(search.attr('placeholder')); search.addClass('inactive'); } search.on('focus', clearInactive); search.on('blur', restoreInactive); restoreInactive(); } /* 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; } var nav = $('#nav'); if (nav.length === 0) { return; } var toc_items = []; $(nav).nextAll('h2, h3').each(function() { var node = this; var link = $('').attr('href', '#' + node.id).text($(node).text()); var item; if ($(node).is('h2')) { item = $('
'); } else { // h3 item = $(''); } item.append(link); toc_items.push(item); }); if (toc_items.length <= 1) { return; } var dl1 = $('