mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-08-22 22:26:01 +00:00
deploy: efa0a93fb7
This commit is contained in:
parent
aac35dcdc2
commit
64da4d976f
275 changed files with 8121 additions and 6835 deletions
js
56
js/theme.js
56
js/theme.js
|
@ -528,31 +528,55 @@ function initOpenapi( update, attrs ){
|
|||
}
|
||||
|
||||
function initAnchorClipboard(){
|
||||
if( window.relearn.disableAnchorCopy && window.relearn.disableAnchorScrolling ){
|
||||
return;
|
||||
}
|
||||
|
||||
document.querySelectorAll( 'h1~h2,h1~h3,h1~h4,h1~h5,h1~h6').forEach( function( element ){
|
||||
var url = encodeURI( (document.location.origin == "null" ? (document.location.protocol + "//" + document.location.host) : document.location.origin )+ document.location.pathname);
|
||||
var link = url + "#" + element.id;
|
||||
var new_element = document.createElement( 'span' );
|
||||
new_element.classList.add( 'anchor' );
|
||||
new_element.setAttribute( 'title', window.T_Copy_link_to_clipboard );
|
||||
if( !window.relearn.disableAnchorCopy ){
|
||||
new_element.setAttribute( 'title', window.T_Copy_link_to_clipboard );
|
||||
}
|
||||
new_element.setAttribute( 'data-clipboard-text', link );
|
||||
new_element.innerHTML = '<i class="fas fa-link fa-lg"></i>';
|
||||
element.appendChild( new_element );
|
||||
});
|
||||
|
||||
var anchors = document.querySelectorAll( '.anchor' );
|
||||
for( var i = 0; i < anchors.length; i++ ) {
|
||||
anchors[i].addEventListener( 'mouseleave', function( e ){
|
||||
this.removeAttribute( 'aria-label' );
|
||||
this.classList.remove( 'tooltipped', 'tooltipped-se', 'tooltipped-sw' );
|
||||
});
|
||||
}
|
||||
if( !window.relearn.disableAnchorCopy ){
|
||||
for( var i = 0; i < anchors.length; i++ ) {
|
||||
anchors[i].addEventListener( 'mouseleave', function( e ){
|
||||
this.removeAttribute( 'aria-label' );
|
||||
this.classList.remove( 'tooltipped', 'tooltipped-se', 'tooltipped-sw' );
|
||||
});
|
||||
}
|
||||
|
||||
var clip = new ClipboardJS( '.anchor' );
|
||||
clip.on( 'success', function( e ){
|
||||
e.clearSelection();
|
||||
e.trigger.setAttribute( 'aria-label', window.T_Link_copied_to_clipboard );
|
||||
e.trigger.classList.add( 'tooltipped', 'tooltipped-s'+(isRtl?'e':'w') );
|
||||
});
|
||||
var clip = new ClipboardJS( '.anchor' );
|
||||
clip.on( 'success', function( e ){
|
||||
e.clearSelection();
|
||||
e.trigger.setAttribute( 'aria-label', window.T_Link_copied_to_clipboard );
|
||||
e.trigger.classList.add( 'tooltipped', 'tooltipped-s'+(isRtl?'e':'w') );
|
||||
if( !window.relearn.disableAnchorScrolling ){
|
||||
e.trigger.parentElement.scrollIntoView({ behavior: 'smooth' });
|
||||
var state = window.history.state || {};
|
||||
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
||||
history.replaceState( {}, '', e.text );
|
||||
}
|
||||
});
|
||||
}
|
||||
else if ( !window.relearn.disableAnchorScrolling ){
|
||||
for( var i = 0; i < anchors.length; i++ ) {
|
||||
anchors[i].addEventListener( 'click', function( e ){
|
||||
e.target.parentElement.parentElement.scrollIntoView({ behavior: 'smooth' });
|
||||
var state = window.history.state || {};
|
||||
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
||||
history.replaceState( {}, '', e.text );
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initCodeClipboard(){
|
||||
|
@ -1267,7 +1291,7 @@ function scrollToPositions() {
|
|||
var found = elementContains( search, elc );
|
||||
var searchedElem = found.length && found[ 0 ];
|
||||
if( searchedElem ){
|
||||
searchedElem.scrollIntoView( true );
|
||||
searchedElem.scrollIntoView();
|
||||
var scrolledY = window.scrollY;
|
||||
if( scrolledY ){
|
||||
window.scroll( 0, scrolledY - 125 );
|
||||
|
@ -1281,9 +1305,7 @@ function scrollToPositions() {
|
|||
try{
|
||||
var e = document.querySelector( window.location.hash );
|
||||
if( e && e.scrollIntoView ){
|
||||
e.scrollIntoView({
|
||||
block: 'start',
|
||||
});
|
||||
e.scrollIntoView();
|
||||
}
|
||||
} catch( e ){}
|
||||
}, 10 );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue