Skip to content

Commit

Permalink
Add google webfontloader to fix scrollspy position after webfont load…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
rottmann committed Dec 14, 2015
1 parent 20ef1d8 commit 4f0f24e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
27 changes: 14 additions & 13 deletions template/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require.config({
prettify: './vendor/prettify/prettify',
semver: './vendor/semver.min',
utilsSampleRequest: './utils/send_sample_request',
webfontloader: './vendor/webfontloader'
},
shim: {
bootstrap: {
Expand Down Expand Up @@ -44,9 +45,10 @@ require([
'prettify',
'utilsSampleRequest',
'semver',
'webfontloader',
'bootstrap',
'pathToRegexp'
], function($, _, locale, Handlebars, apiProject, apiData, prettyPrint, sampleRequest, semver) {
], function($, _, locale, Handlebars, apiProject, apiData, prettyPrint, sampleRequest, semver, WebFont) {

// load google web fonts
loadGoogleFontCss();
Expand Down Expand Up @@ -433,7 +435,8 @@ require([
}
});

// show / hide groups in content

// show 1st equal or lower Version of each entry
$('article[data-version]').each(function(index) {
var group = $(this).data('group');
$('section#api-' + group).removeClass('hide');
Expand Down Expand Up @@ -657,17 +660,15 @@ require([
* Load google fonts.
*/
function loadGoogleFontCss() {
var host = document.location.hostname.toLowerCase();
var protocol = document.location.protocol.toLowerCase();
var googleCss = '//fonts.googleapis.com/css?family=Source+Code+Pro|Source+Sans+Pro:400,600,700';
if (host == 'localhost' || !host.length || protocol === 'file:')
googleCss = 'http:' + googleCss;

$('<link/>', {
rel: 'stylesheet',
type: 'text/css',
href: googleCss
}).appendTo('head');
WebFont.load({
active: function() {
// Update scrollspy
$(window).scrollspy('refresh')
},
google: {
families: ['Source Code Pro', 'Source Sans Pro:n4,n6,n7']
}
});
}

/**
Expand Down
18 changes: 18 additions & 0 deletions template/vendor/webfontloader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f0f24e

Please sign in to comment.