mirror of https://github.com/istio/istio.io.git
19 lines
3.0 KiB
JavaScript
19 lines
3.0 KiB
JavaScript
|
|
|
|
|
|
"use strict"
|
|
function doSearch(){var url='/v0.6/search.html?q='+document.getElementsByName('q')[0].value;window.location.assign(url)}
|
|
$(function($){$(document).ready(function(){$('.btn-search').on('click',function(e){e.preventDefault();doSearch()});$('[data-toggle="offcanvas"]').on('click',function(){$('.row-offcanvas').toggleClass('active')
|
|
$(this).children('i.fa').toggleClass('fa-chevron-right');$(this).children('i.fa').toggleClass('fa-chevron-left')})
|
|
$(document).on('click','.tree-toggle',function(){$(this).children('i.fa').toggleClass('fa-caret-right');$(this).children('i.fa').toggleClass('fa-caret-down');$(this).parent().children('ul.tree').toggle(200)});$(document).on('mouseenter','pre',function(){$(this).next().toggleClass("copy-show",!0)
|
|
$(this).next().toggleClass("copy-hide",!1)});$(document).on('mouseleave','pre',function(){$(this).next().toggleClass("copy-show",!1)
|
|
$(this).next().toggleClass("copy-hide",!0)});$(document).on('mouseenter','button.copy',function(){$(this).toggleClass("copy-show",!0)
|
|
$(this).toggleClass("copy-hide",!1)});$(document).on('mouseleave','button.copy',function(){$(this).toggleClass("copy-show",!1)
|
|
$(this).toggleClass("copy-hide",!0)})})}(jQuery));function patchDOM(){function attachCopyButtons(){var pre=document.getElementsByTagName('PRE');for(var i=0;i<pre.length;i++){var button=document.createElement("BUTTON");button.title="Copy to clipboard";button.className="copy copy-hide";button.innerText="Copy";pre[i].parentElement.appendChild(button)}
|
|
var copyCode=new Clipboard('button.copy',{target:function(trigger){return trigger.previousElementSibling}});copyCode.on('success',function(event){event.clearSelection();event.trigger.textContent='Done';window.setTimeout(function(){event.trigger.textContent='Copy'},2000)});copyCode.on('error',function(event){event.trigger.textContent='Not supported';window.setTimeout(function(){event.trigger.textContent='Copy'},5000)})}
|
|
function attachLinksToHeaders(){for(var level=1;level<=6;level++){for(var header in document.getElementsByTagName("h"+level)){if(typeof header.id!=="undefined"&&header.id!==""){var i=document.createElement("i");i.className="fa fa-link";var anchor=document.createElement("a");anchor.className="header-link";anchor.href="#"+header.id;anchor.appendChild(i);header.appendChild(anchor)}}}}
|
|
function makeOutsideLinksOpenInTabs(){for(var link in document.getElementsByTagName("a")){if(link.hostname&&link.hostname!=location.hostname){link.setAttribute("target","_blank")}}}
|
|
function loadExternalPreBlocks(){function fetchFile(elem,url){fetch(url).then(response=>response.text()).then(data=>{elem.firstChild.innerText=data})}
|
|
var pre=document.getElementsByTagName('PRE');for(var i=0;i<pre.length;i++){if(pre[i].hasAttribute("data-src")){fetchFile(pre[i],pre[i].getAttribute("data-src"))}}}
|
|
attachCopyButtons();attachLinksToHeaders();makeOutsideLinksOpenInTabs();loadExternalPreBlocks()}
|
|
document.addEventListener("DOMContentLoaded",patchDOM) |