Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions utils/docs/template/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,20 @@ function updateItemName( item ) {

function addParamAttributes( params ) {

return params.filter( ( { name } ) => name && ! name.includes( '.' ) ).map( updateItemName );
return params.filter( ( { name } ) => name && ! name.includes( '.' ) ).map( param => {

let itemName = updateItemName( param );

if ( param.type && param.type.names && param.type.names.length ) {

const escapedTypes = param.type.names.map( name => htmlsafe( name ) );
itemName += ' : <span class="param-type">' + escapedTypes.join( ' | ' ) + '</span>';

}

return itemName;

} );

}

Expand Down Expand Up @@ -182,41 +195,16 @@ function addSignatureParams( f ) {

const params = f.params ? addParamAttributes( f.params ) : [];

f.signature = util.format( '%s(%s)', ( f.signature || '' ), params.join( ', ' ) );
f.signature = util.format( '%s( %s )', ( f.signature || '' ), params.join( ', ' ) );

}

function addSignatureReturns( f ) {

const attribs = [];
let attribsString = '';
let returnTypes = [];
let returnTypesString = '';
const source = f.yields || f.returns;

// jam all the return-type attributes into an array. this could create odd results (for example,
// if there are both nullable and non-nullable return types), but let's assume that most people
// who use multiple @return tags aren't using Closure Compiler type annotations, and vice-versa.
if ( source ) {

source.forEach( item => {

helper.getAttribs( item ).forEach( attrib => {

if ( ! attribs.includes( attrib ) ) {

attribs.push( attrib );

}

} );

} );

attribsString = buildAttribsString( attribs );

}

if ( source ) {

returnTypes = addNonParamAttributes( source );
Expand All @@ -225,7 +213,7 @@ function addSignatureReturns( f ) {

if ( returnTypes.length ) {

returnTypesString = util.format( ' &rarr; %s{%s}', attribsString, returnTypes.join( '|' ) );
returnTypesString = util.format( ' : %s', returnTypes.join( ' | ' ) );

}

Expand All @@ -237,13 +225,13 @@ function addSignatureTypes( f ) {

const types = f.type ? buildItemTypeStrings( f ) : [];

f.signature = `${f.signature || ''}<span class="type-signature">${types.length ? ` :${types.join( '|' )}` : ''}</span>`;
f.signature = `${f.signature || ''}<span class="type-signature">${types.length ? ` : ${types.join( ' | ' )}` : ''}</span>`;

}

function addAttribs( f ) {

const attribs = helper.getAttribs( f );
const attribs = helper.getAttribs( f ).filter( attrib => attrib !== 'static' );
const attribsString = buildAttribsString( attribs );

f.attribs = util.format( '<span class="type-signature">%s</span>', attribsString );
Expand Down Expand Up @@ -287,7 +275,8 @@ function generate( title, docs, filename, resolveLinks ) {
const docData = {
env: env,
title: title,
docs: docs
docs: docs,
augments: docs && docs[0] ? docs[0].augments : null
};

const outpath = path.join( outdir, filename );
Expand Down
50 changes: 39 additions & 11 deletions utils/docs/template/static/scripts/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,42 @@

( function loadNavigation() {

const navContainer = document.querySelector( '#content nav' );
const content = document.getElementById( 'content' );
const navContainer = content.querySelector( 'nav' );

if ( navContainer ) {
fetch( 'nav.html' )
.then( response => response.text() )
.then( html => {

fetch( 'nav.html' )
.then( response => response.text() )
.then( html => {
navContainer.innerHTML = html;

navContainer.innerHTML = html;
const savedScrollTop = sessionStorage.getItem( 'navScrollTop' );

} )
.catch( err => console.error( 'Failed to load navigation:', err ) );
if ( savedScrollTop !== null ) {

}
content.scrollTop = parseInt( savedScrollTop, 10 );

}

// Save scroll position when clicking nav links
navContainer.addEventListener( 'click', function ( event ) {

const link = event.target.closest( 'a' );

if ( link ) {

sessionStorage.setItem( 'navScrollTop', content.scrollTop );

}

} );

updateNavigation();

sessionStorage.removeItem( 'navScrollTop' );

} )
.catch( err => console.error( 'Failed to load navigation:', err ) );

} )();

Expand Down Expand Up @@ -163,7 +185,6 @@ clearSearchButton.onclick = function () {

//

window.addEventListener( 'DOMContentLoaded', updateNavigation );
window.addEventListener( 'hashchange', updateNavigation );

function updateNavigation() {
Expand Down Expand Up @@ -194,7 +215,14 @@ function updateNavigation() {

if ( aElement !== null ) {

aElement.scrollIntoView( { block: 'center' } );
const savedScrollTop = sessionStorage.getItem( 'navScrollTop' );

if ( savedScrollTop === null ) {

aElement.scrollIntoView( { block: 'center' } );

}

aElement.classList.add( 'selected' );

}
Expand Down
Loading