@@ -42,35 +42,34 @@ document.addEventListener('DOMContentLoaded', function() {
4242 function hideModal ( ) {
4343 modal . style . display = 'none' ;
4444 // Remove any event listeners added during display
45- const oldModal = document . getElementById ( 'bibtex-modal' ) ;
46- if ( oldModal ) {
47- const newModal = oldModal . cloneNode ( true ) ;
48- oldModal . parentNode . replaceChild ( newModal , oldModal ) ;
49- // Re-add close functionality
50- const newCloseBtn = newModal . querySelector ( '.bibtex-close' ) ;
51- if ( newCloseBtn ) {
52- newCloseBtn . addEventListener ( 'click' , hideModal ) ;
53- }
54- // Re-add copy functionality
55- const newCopyBtn = document . getElementById ( 'bibtex-copy' ) ;
56- if ( newCopyBtn ) {
57- newCopyBtn . addEventListener ( 'click' , function ( ) {
58- const content = document . getElementById ( 'bibtex-content' ) . textContent ;
59- navigator . clipboard . writeText ( content )
60- . then ( ( ) => {
61- const originalText = newCopyBtn . textContent ;
62- newCopyBtn . textContent = 'Copied!' ;
63- newCopyBtn . classList . add ( 'copied' ) ;
64- setTimeout ( ( ) => {
65- newCopyBtn . textContent = originalText ;
66- newCopyBtn . classList . remove ( 'copied' ) ;
67- } , 2000 ) ;
68- } )
69- . catch ( err => {
70- console . error ( 'Could not copy text: ' , err ) ;
71- } ) ;
45+ // Remove event listeners for close button
46+ const closeBtn = modal . querySelector ( '.bibtex-close' ) ;
47+ if ( closeBtn ) {
48+ closeBtn . removeEventListener ( 'click' , hideModal ) ;
49+ }
50+
51+ // Remove event listeners for copy button
52+ const copyBtn = document . getElementById ( 'bibtex-copy' ) ;
53+ if ( copyBtn ) {
54+ copyBtn . removeEventListener ( 'click' , handleCopy ) ;
55+ }
56+
57+ // Helper function to handle copy functionality
58+ function handleCopy ( ) {
59+ const content = document . getElementById ( 'bibtex- content' ) . textContent ;
60+ navigator . clipboard . writeText ( content )
61+ . then ( ( ) => {
62+ const originalText = copyBtn . textContent ;
63+ copyBtn . textContent = 'Copied!' ;
64+ copyBtn . classList . add ( 'copied' ) ;
65+ setTimeout ( ( ) => {
66+ copyBtn . textContent = originalText ;
67+ copyBtn . classList . remove ( 'copied' ) ;
68+ } , 2000 ) ;
69+ } )
70+ . catch ( err => {
71+ console . error ( 'Could not copy text: ' , err ) ;
7272 } ) ;
73- }
7473 }
7574 }
7675
0 commit comments