From 7ba2f60ce3d609bc5cb5213e6852cbaf609b5909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Fri, 13 Dec 2024 00:55:45 +0000 Subject: [PATCH] what if the editor didn't crash? --- src/c3nav/editor/static/editor/js/editor.js | 33 +++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/c3nav/editor/static/editor/js/editor.js b/src/c3nav/editor/static/editor/js/editor.js index 47b3a312..94732b72 100644 --- a/src/c3nav/editor/static/editor/js/editor.js +++ b/src/c3nav/editor/static/editor/js/editor.js @@ -1072,13 +1072,21 @@ editor = { list_elem = $('#sidebar').find('[data-list] tr[data-pk=' + String(highlight_id) + ']'); } if (list_elem.length === 0) return; - var option = editor.accessRestrictionSelect.find('[value='+String(feature.properties.access_restriction)+']'); + var hasOption, optionSelected; + if (editor.accessRestrictionSelect) { + var option = editor.accessRestrictionSelect.find('[value=' + String(feature.properties.access_restriction) + ']'); + hasOption = !!option.length; + optionSelected = option.is(':selected'); + } else { + hasOption = false; + optionSelected = false; + } var highlight_layer = L.geoJSON(layer.feature, { style: function () { return { - color: option.length ? '#FF0000' : '#FFFFDD', - weight: (option.length && !option.is(':selected')) ? 1 : 3, - opacity: option.length ? (option.is(':selected') ? 1 : 0.3) : 0, + color: hasOption ? '#FF0000' : '#FFFFDD', + weight: (hasOption && !optionSelected) ? 1 : 3, + opacity: hasOption ? (optionSelected ? 1 : 0.3) : 0, fillOpacity: 0, className: 'c3nav-highlight' }; @@ -1232,7 +1240,6 @@ editor = { if (!geometries) return; var option; for (geometry of geometries) { - option = editor.accessRestrictionSelect.find('[value='+String(geometry.highlightID)+']') geometry.setStyle({ color: '#FFFFDD', weight: 3, @@ -1248,11 +1255,19 @@ editor = { if (!geometries) return; var option; for (geometry of geometries) { - option = editor.accessRestrictionSelect.find('[value='+String(geometry.highlightID)+']') + var hasOption, optionSelected; + if (editor.accessRestrictionSelect) { + var option = editor.accessRestrictionSelect.find('[value=' + String(feature.properties.access_restriction) + ']'); + hasOption = !!option.length; + optionSelected = option.is(':selected'); + } else { + hasOption = false; + optionSelected = false; + } geometry.setStyle({ - color: option.length ? '#FF0000' : '#FFFFDD', - weight: (option.length && !option.is(':selected')) ? 1 : 3, - opacity: option.length ? (option.is(':selected') ? 1 : 0.3) : 0, + color: hasOption ? '#FF0000' : '#FFFFDD', + weight: (hasOption && !optionSelected) ? 1 : 3, + opacity: hasOption ? (optionSelected ? 1 : 0.3) : 0, fillOpacity: 0, }); geometry.list_elem.removeClass('highlight');