@@ -81,6 +81,10 @@ function trackDisableShareButton(solutionId, button) {
8181function updateNotificationsBadge ( ) {
8282 const dropdown = document . getElementById ( 'navbarNavDropdown' ) ;
8383 const container = document . getElementById ( 'notifications-list' ) ;
84+ if ( dropdown === null || container === null ) {
85+ return ;
86+ }
87+
8488 const unread = container . querySelectorAll ( '.dropdown-item[data-read="false"]' ) ;
8589 const counter = dropdown . querySelector ( '#notification-count' ) ;
8690 const bgColor = ( unread . length > 0 ) ? badColor : naturalColor ;
@@ -95,6 +99,10 @@ function sendReadAllNotificationsRequest() {
9599}
96100
97101function trackReadAllNotificationsButton ( button ) {
102+ if ( button === null ) {
103+ return ;
104+ }
105+
98106 button . addEventListener ( 'click' , ( ) => {
99107 sendReadAllNotificationsRequest ( ) ;
100108 const notifications = document . querySelectorAll ( '.dropdown-item[data-read="false"]' ) ;
@@ -105,20 +113,9 @@ function trackReadAllNotificationsButton(button) {
105113 } ) ;
106114}
107115
108- function getPostUploadMessage ( ) {
109- const myDropzone = Dropzone . forElement ( '#demo-upload' ) ;
110- const feedbacks = document . getElementById ( 'upload-feedbacks' ) ;
111- const matchesSpan = document . getElementById ( 'upload-matches' ) ;
112- const missesSpan = document . getElementById ( 'upload-misses' ) ;
113- myDropzone . on ( 'success' , function ( ) {
114- const uploadStatus = Array . from ( arguments ) . slice ( 1 ) [ 0 ] ;
115- postUploadMessageUpdate ( feedbacks , uploadStatus , matchesSpan , missesSpan ) ;
116- } ) ;
117- }
118-
119116function postUploadMessageUpdate ( feedbacks , uploadStatus , matchesSpan , missesSpan ) {
120- const matches = uploadStatus [ ' exercise_matches' ] ;
121- const misses = uploadStatus [ ' exercise_misses' ] ;
117+ const matches = uploadStatus . exercise_matches ;
118+ const misses = uploadStatus . exercise_misses ;
122119 if ( ! feedbacks . classList . contains ( 'feedback-hidden' ) ) {
123120 feedbacks . classList . add ( 'feedback-hidden' ) ;
124121 }
@@ -131,19 +128,32 @@ function postUploadMessageUpdate(feedbacks, uploadStatus, matchesSpan, missesSpa
131128 missesSpan . classList . remove ( 'feedback-hidden' ) ;
132129 }
133130 feedbacks . classList . add ( 'feedback-transition' ) ;
134- feedbacks . clientWidth ; // Forces layout to ensure the transition
131+ feedbacks . clientWidth ; // Forces layout to ensure the transition
135132 feedbacks . classList . remove ( 'feedback-hidden' ) ;
136- feedbacks . addEventListener ( 'transitionend' , function ( ) {
133+ feedbacks . addEventListener ( 'transitionend' , ( ) => {
137134 feedbacks . classList . remove ( 'feedback-transition' ) ;
138135 } ) ;
139136}
140137
138+ function getPostUploadMessage ( ) {
139+ const myDropzone = Dropzone . forElement ( '#demo-upload' ) ;
140+ const feedbacks = document . getElementById ( 'upload-feedbacks' ) ;
141+ const matchesSpan = document . getElementById ( 'upload-matches' ) ;
142+ const missesSpan = document . getElementById ( 'upload-misses' ) ;
143+ myDropzone . on ( 'success' , ( ...args ) => {
144+ const uploadStatus = Array . from ( args ) . slice ( 1 ) [ 0 ] ;
145+ if ( uploadStatus !== null ) {
146+ postUploadMessageUpdate ( feedbacks , uploadStatus , matchesSpan , missesSpan ) ;
147+ }
148+ } ) ;
149+ }
150+
141151window . escapeUnicode = escapeUnicode ;
142152
143153window . addEventListener ( 'load' , ( ) => {
144154 updateNotificationsBadge ( ) ;
145155 trackReadAllNotificationsButton ( document . getElementById ( 'read-notifications' ) ) ;
146- const codeElement = document . getElementById ( 'code-view' )
156+ const codeElement = document . getElementById ( 'code-view' ) ;
147157 if ( codeElement !== null ) {
148158 const codeElementData = codeElement . dataset ;
149159 const solutionId = codeElementData . id ;
0 commit comments