Skip to content

Commit b581afb

Browse files
ddunc23ddunc23
authored andcommitted
updated popup so it no longer looks broken with no image
1 parent e9c3fc6 commit b581afb

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

project_static/js/interactionHandler.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,33 @@ MmtMap.clickInteractions = {
207207

208208
popupHtmlTemplate: '<div class="popup_header"><img src="<%= image %>" alt="Image of <%= name %>" /><p class="text-center feature_title"><%= name %></p><br /></div>',
209209

210+
noThumbPopupHtmlTemplate: '<div class="popup_header" style="margin-top: 10px;"><p class="text-center feature_title"><%= name %></p><br /></div>',
211+
210212
popupAudioFileHtmlTemplate: '<div class="player popup_player <%= playerId %>" id="<%= playerId %>"><div id="play_button_container"><a href="#" class="play" data-audio="<%= url %>"><img src="/static/img/play.svg" alt="play" class="play_button" /></a></div><div class="player_display"><span class="player_timer">--:--</span><div class="progress_bar_container"><div class="progress_bar_fill"></div></div></div></div><p class="text-center player_title"><strong>Listen: </strong><%= playerTitle %></p><hr />',
211213

212214

213215
clickFeature: function(source, sourceLayer, feature, id, coords) {
214216
// Loads the feature from the server and adds a large click popup with an audio player (if there is an audio file related to it)
215217

218+
219+
216220
$.get('api/1.0/features/' + sourceLayer + '/' + id, function(data) {
217221
// Construct the HTML for the popup and add it to the map
218-
219222
let popupPlayerId = undefined;
220-
let popupHtml = _.template(MmtMap.clickInteractions.popupHtmlTemplate);
221-
222-
popupHtml = popupHtml({
223-
image: data.properties.popup_image,
224-
name: data.properties.name
225-
});
226-
223+
let popupHtml = undefined;
224+
225+
if (data.properties.popup_image.length > 0) {
226+
popupHtml = _.template(MmtMap.clickInteractions.popupHtmlTemplate);
227+
popupHtml = popupHtml({
228+
image: data.properties.popup_image,
229+
name: data.properties.name
230+
});
231+
} else {
232+
popupHtml = _.template(MmtMap.clickInteractions.noThumbPopupHtmlTemplate);
233+
popupHtml = popupHtml({
234+
name: data.properties.name
235+
});
236+
}
227237

228238
// If there is an audio file attached to the feature, add a player
229239
if (data.properties.popup_audio_file != null) {
@@ -235,12 +245,10 @@ MmtMap.clickInteractions = {
235245
playerId: popupPlayerId,
236246
url: data.properties.popup_audio_file.url,
237247
playerTitle: data.properties.popup_audio_title
238-
});
239-
popupHtml = popupHtml + popupAudioFileHtml;
248+
});
240249
}
241250

242251

243-
244252
let buttonHtml = '<div class="text-center"><br /><button type="button" class="btn btn-sm btn-light read_more" href="#">Read More</button> <button type="button" class="btn btn-sm btn-light close_popup">Close</button></div>';
245253

246254
popupHtml = popupHtml + buttonHtml;

0 commit comments

Comments
 (0)