// TODO: sanitize all HTML renderings, especially markdown: https://github.com/cure53/DOMPurify var pageData = {}, pageDocs = {}; var $renderbox, $hovercard; const nonStandardFlag = 'Non-standard'; $(function() { $renderbox = $('#renderbox'); $hovercard = $('#hovercard'); var hoverTimeout; $hovercard.hover(function() { clearTimeout(hoverTimeout); }, function() { clearTimeout(hoverTimeout); $hovercard.removeClass('popup'); }); // toggle an object as expanded or collapsed $('#renderbox').on('click', '.toggle-obj', function() { if ($(this).hasClass('expanded')) { // collapse $(this).html('▸'); } else { // expand $(this).html('▾'); } $(this).nextUntil('.end-obj').toggleClass('collapsed'); $(this).toggleClass('expanded'); }); $('body').on({ mouseenter: function() { // don't allow hoverbox to close anymore, we're re-opening it clearTimeout(hoverTimeout); var pos = $(this).offset(); // there is a gap between the hoverbox and the link that originated it; // there may be a different link in this gap; if the hover box is visible, // then we should ignore the hover on this link to allow cursor to visit // the hoverbox if that is where it is going; this makes it possible to // visit the hoverbox while it is over a list of links that are tightly // stacked vertically; if user wants to visit hoverbox for link in this // gap, they can just move the cursor slow enough to fire the timeout if ($hovercard.is(':visible') && $hovercard.offset().top - 10 < pos.top) { return; } // fill out hovercard var elemPath = $(this).data('path'); var modNamespace = $(this).data('namespace'); $('.hovercard-elem').hide(); if ($(this).hasClass('module')) { // module var $list =$('
'); if (pageData.namespaces && pageData.namespaces[modNamespace]) { for (var i = 0; i < pageData.namespaces[modNamespace].length; i++) { var modInfo = pageData.namespaces[modNamespace][i]; var href = canTraverse() ? '.'+elemPath+'/'+modInfo.name+'/' : './'+modNamespace+'.'+modInfo.name; var content = ' '+modInfo.name; if (!isStandard(modInfo.package)) { content += nonStandardFlag; } content += ''+truncate(modInfo.docs, 115)+''; $list.append(content); } } $('#hovercard-module-list').html($list); $('#hovercard-namespace').text(modNamespace) $('#hovercard-module').show(); } else if ($(this).hasClass('module-inline-key')) { // inline key $('#hovercard-inline-key').show(); } else if ($(this).hasClass('breadcrumb')) { // breadcrumb siblings var siblingPath = $(this).data('sibling-path'); var bcVal = pageData.breadcrumb[siblingPath]; var bcSiblings = []; // drill down to the true underlying type while (bcVal.elems) { bcVal = bcVal.elems; } switch (bcVal.type) { case "struct": for (var j = 0; j < bcVal.struct_fields.length; j++) { var sf = bcVal.struct_fields[j]; bcSiblings.push({name: sf.key, path: siblingPath, isStandard: isStandard(bcVal.type_name)}) } break; case "module": case "module_map": for (var j = 0; j < pageData.namespaces[bcVal.module_namespace].length; j++) { var mod = pageData.namespaces[bcVal.module_namespace][j]; bcSiblings.push({name: mod.name, path: siblingPath, isStandard: isStandard(mod.package)}) } } var $siblings = $('