@@ -81,6 +81,10 @@ function trackDisableShareButton(solutionId, button) {
81
81
function updateNotificationsBadge ( ) {
82
82
const dropdown = document . getElementById ( 'navbarNavDropdown' ) ;
83
83
const container = document . getElementById ( 'notifications-list' ) ;
84
+ if ( dropdown === null || container === null ) {
85
+ return ;
86
+ }
87
+
84
88
const unread = container . querySelectorAll ( '.dropdown-item[data-read="false"]' ) ;
85
89
const counter = dropdown . querySelector ( '#notification-count' ) ;
86
90
const bgColor = ( unread . length > 0 ) ? badColor : naturalColor ;
@@ -95,6 +99,10 @@ function sendReadAllNotificationsRequest() {
95
99
}
96
100
97
101
function trackReadAllNotificationsButton ( button ) {
102
+ if ( button === null ) {
103
+ return ;
104
+ }
105
+
98
106
button . addEventListener ( 'click' , ( ) => {
99
107
sendReadAllNotificationsRequest ( ) ;
100
108
const notifications = document . querySelectorAll ( '.dropdown-item[data-read="false"]' ) ;
@@ -105,20 +113,9 @@ function trackReadAllNotificationsButton(button) {
105
113
} ) ;
106
114
}
107
115
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
-
119
116
function 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 ;
122
119
if ( ! feedbacks . classList . contains ( 'feedback-hidden' ) ) {
123
120
feedbacks . classList . add ( 'feedback-hidden' ) ;
124
121
}
@@ -131,19 +128,32 @@ function postUploadMessageUpdate(feedbacks, uploadStatus, matchesSpan, missesSpa
131
128
missesSpan . classList . remove ( 'feedback-hidden' ) ;
132
129
}
133
130
feedbacks . classList . add ( 'feedback-transition' ) ;
134
- feedbacks . clientWidth ; // Forces layout to ensure the transition
131
+ feedbacks . clientWidth ; // Forces layout to ensure the transition
135
132
feedbacks . classList . remove ( 'feedback-hidden' ) ;
136
- feedbacks . addEventListener ( 'transitionend' , function ( ) {
133
+ feedbacks . addEventListener ( 'transitionend' , ( ) => {
137
134
feedbacks . classList . remove ( 'feedback-transition' ) ;
138
135
} ) ;
139
136
}
140
137
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
+
141
151
window . escapeUnicode = escapeUnicode ;
142
152
143
153
window . addEventListener ( 'load' , ( ) => {
144
154
updateNotificationsBadge ( ) ;
145
155
trackReadAllNotificationsButton ( document . getElementById ( 'read-notifications' ) ) ;
146
- const codeElement = document . getElementById ( 'code-view' )
156
+ const codeElement = document . getElementById ( 'code-view' ) ;
147
157
if ( codeElement !== null ) {
148
158
const codeElementData = codeElement . dataset ;
149
159
const solutionId = codeElementData . id ;
0 commit comments