File tree Expand file tree Collapse file tree
themes/math-gallery-theme/assets Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -707,6 +707,42 @@ li code {
707707 color : var (--accent );
708708}
709709
710+ /* "Copied!" tooltip shown after clicking an anchor link */
711+ .anchor-copied-tip {
712+ position : absolute;
713+ bottom : calc (100% + 0.3rem );
714+ right : 0 ;
715+ background : var (--accent );
716+ color : # fff ;
717+ font-size : 0.7rem ;
718+ font-weight : 600 ;
719+ padding : 0.15em 0.45em ;
720+ border-radius : 4px ;
721+ white-space : nowrap;
722+ pointer-events : none;
723+ opacity : 1 ;
724+ animation : anchor-tip-fade 1.5s ease forwards;
725+ }
726+
727+ .heading-anchor .anchor-copied-tip {
728+ bottom : calc (100% + 0.3rem );
729+ right : auto;
730+ left : 50% ;
731+ transform : translateX (-50% );
732+ }
733+
734+ @keyframes anchor-tip-fade {
735+ 0% {
736+ opacity : 1 ;
737+ }
738+ 60% {
739+ opacity : 1 ;
740+ }
741+ 100% {
742+ opacity : 0 ;
743+ }
744+ }
745+
710746/* ============================================================
711747 Media figures (img / video shortcodes)
712748 ============================================================ */
Original file line number Diff line number Diff line change 6666 const LINK_ICON =
6767 '<svg xmlns="http://www.w3.org/2000/svg" width="0.75em" height="0.75em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>' ;
6868
69+ function addCopyAnchor ( anchorEl ) {
70+ anchorEl . addEventListener ( "click" , function ( e ) {
71+ e . preventDefault ( ) ;
72+ var url =
73+ window . location . origin +
74+ window . location . pathname +
75+ anchorEl . getAttribute ( "href" ) ;
76+ navigator . clipboard . writeText ( url ) . then ( function ( ) {
77+ // Navigate after copying
78+ window . location . hash = anchorEl . getAttribute ( "href" ) ;
79+ // Show tooltip feedback
80+ var tip = document . createElement ( "span" ) ;
81+ tip . className = "anchor-copied-tip" ;
82+ tip . textContent = "Copied!" ;
83+ anchorEl . appendChild ( tip ) ;
84+ setTimeout ( function ( ) {
85+ tip . remove ( ) ;
86+ } , 1500 ) ;
87+ } ) ;
88+ } ) ;
89+ }
90+
6991 var postContent = document . querySelector ( ".post-content" ) ;
7092 if ( postContent ) {
7193 // Headings
7799 a . href = "#" + h . id ;
78100 a . setAttribute ( "aria-label" , "Link to this section" ) ;
79101 a . innerHTML = LINK_ICON ;
102+ addCopyAnchor ( a ) ;
80103 h . appendChild ( a ) ;
81104 } ) ;
82105
95118 a . href = "#" + fig . id ;
96119 a . setAttribute ( "aria-label" , "Link to this figure" ) ;
97120 a . innerHTML = LINK_ICON ;
121+ addCopyAnchor ( a ) ;
98122 fig . appendChild ( a ) ;
99123 } ) ;
100124
110134 a . href = "#" + tbl . id ;
111135 a . setAttribute ( "aria-label" , "Link to this table" ) ;
112136 a . innerHTML = LINK_ICON ;
137+ addCopyAnchor ( a ) ;
113138 tbl . appendChild ( a ) ;
114139 } ) ;
115140 }
You can’t perform that action at this time.
0 commit comments