@@ -4,6 +4,7 @@ window.HELP_IMPROVE_VIDEOJS = false;
44function toggleMoreWorks ( ) {
55 const dropdown = document . getElementById ( 'moreWorksDropdown' ) ;
66 const button = document . querySelector ( '.more-works-btn' ) ;
7+ if ( ! dropdown || ! button ) return ;
78
89 if ( dropdown . classList . contains ( 'show' ) ) {
910 dropdown . classList . remove ( 'show' ) ;
@@ -19,7 +20,8 @@ document.addEventListener('click', function(event) {
1920 const container = document . querySelector ( '.more-works-container' ) ;
2021 const dropdown = document . getElementById ( 'moreWorksDropdown' ) ;
2122 const button = document . querySelector ( '.more-works-btn' ) ;
22-
23+ if ( ! container || ! dropdown || ! button ) return ;
24+
2325 if ( container && ! container . contains ( event . target ) ) {
2426 dropdown . classList . remove ( 'show' ) ;
2527 button . classList . remove ( 'active' ) ;
@@ -31,6 +33,7 @@ document.addEventListener('keydown', function(event) {
3133 if ( event . key === 'Escape' ) {
3234 const dropdown = document . getElementById ( 'moreWorksDropdown' ) ;
3335 const button = document . querySelector ( '.more-works-btn' ) ;
36+ if ( ! dropdown || ! button ) return ;
3437 dropdown . classList . remove ( 'show' ) ;
3538 button . classList . remove ( 'active' ) ;
3639 }
@@ -40,36 +43,31 @@ document.addEventListener('keydown', function(event) {
4043function copyBibTeX ( ) {
4144 const bibtexElement = document . getElementById ( 'bibtex-code' ) ;
4245 const button = document . querySelector ( '.copy-bibtex-btn' ) ;
46+ if ( ! bibtexElement || ! button ) return ;
4347 const copyText = button . querySelector ( '.copy-text' ) ;
44-
45- if ( bibtexElement ) {
46- navigator . clipboard . writeText ( bibtexElement . textContent ) . then ( function ( ) {
47- // Success feedback
48- button . classList . add ( 'copied' ) ;
49- copyText . textContent = 'Cop' ;
50-
51- setTimeout ( function ( ) {
52- button . classList . remove ( 'copied' ) ;
53- copyText . textContent = 'Copy' ;
54- } , 2000 ) ;
55- } ) . catch ( function ( err ) {
56- console . error ( 'Failed to copy: ' , err ) ;
57- // Fallback for older browsers
58- const textArea = document . createElement ( 'textarea' ) ;
59- textArea . value = bibtexElement . textContent ;
60- document . body . appendChild ( textArea ) ;
61- textArea . select ( ) ;
62- document . execCommand ( 'copy' ) ;
63- document . body . removeChild ( textArea ) ;
64-
65- button . classList . add ( 'copied' ) ;
66- copyText . textContent = 'Cop' ;
67- setTimeout ( function ( ) {
68- button . classList . remove ( 'copied' ) ;
69- copyText . textContent = 'Copy' ;
70- } , 2000 ) ;
71- } ) ;
48+
49+ function showCopiedState ( ) {
50+ button . classList . add ( 'copied' ) ;
51+ copyText . textContent = 'Copied' ;
52+
53+ setTimeout ( function ( ) {
54+ button . classList . remove ( 'copied' ) ;
55+ copyText . textContent = 'Copy' ;
56+ } , 1800 ) ;
7257 }
58+
59+ navigator . clipboard . writeText ( bibtexElement . textContent ) . then ( function ( ) {
60+ showCopiedState ( ) ;
61+ } ) . catch ( function ( err ) {
62+ console . error ( 'Failed to copy: ' , err ) ;
63+ const textArea = document . createElement ( 'textarea' ) ;
64+ textArea . value = bibtexElement . textContent ;
65+ document . body . appendChild ( textArea ) ;
66+ textArea . select ( ) ;
67+ document . execCommand ( 'copy' ) ;
68+ document . body . removeChild ( textArea ) ;
69+ showCopiedState ( ) ;
70+ } ) ;
7371}
7472
7573// Scroll to top functionality
@@ -83,6 +81,7 @@ function scrollToTop() {
8381// Show/hide scroll to top button
8482window . addEventListener ( 'scroll' , function ( ) {
8583 const scrollButton = document . querySelector ( '.scroll-to-top' ) ;
84+ if ( ! scrollButton ) return ;
8685 if ( window . pageYOffset > 300 ) {
8786 scrollButton . classList . add ( 'visible' ) ;
8887 } else {
0 commit comments