diff options
Diffstat (limited to 'modules/freetype2/docs/reference/javascripts/extra.js')
-rw-r--r-- | modules/freetype2/docs/reference/javascripts/extra.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/modules/freetype2/docs/reference/javascripts/extra.js b/modules/freetype2/docs/reference/javascripts/extra.js new file mode 100644 index 0000000000..00f1670890 --- /dev/null +++ b/modules/freetype2/docs/reference/javascripts/extra.js @@ -0,0 +1,54 @@ +/* +Internal link topbar offest adjust Javascript +Code provided by @makshh on GitHub + +Bug report on material-mkdocs + https://github.com/squidfunk/mkdocs-material/issues/791 +*/ + +// Offset top helper +function offsetY(elem) { + if(!elem) elem = this; + var y = elem.offsetTop; + while (elem = elem.offsetParent) { + y += elem.offsetTop; + } + return y; +} + +// If a link on the same page is clicked, calculate the +// correct offset and scroll to that part of the page. +// +var links = document.getElementsByTagName('a'); +for(var i = 0; i < links.length; i++) { + links[i].onclick = function (event) { + if (this.pathname == window.location.pathname && + this.protocol == window.location.protocol && + this.host == window.location.host) { + event.preventDefault(); + if(this.hash.substr(1)){ + var o = document.getElementById(this.hash.substr(1)); + var sT = offsetY(o) - document.getElementsByClassName('md-header')[0].clientHeight; + window.location.hash = this.hash; + window.scrollTo(0, sT); + } + } + } +} + +// Slugify supplied text +function slugify(text){ + text = text.toLowerCase(); + text = text.replace(" ", "-"); + return text; +} + +// If there is a hash in the url, slugify it +// and replace +if(window.location.hash) { + // Fragment exists + slug = slugify(window.location.hash); + history.replaceState(undefined, undefined, slug) + //window.location.hash = slug; + document.location.replace(window.location.href); +} |