From ea70ec45b38ce982fd3ddf38fca5693018766306 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Tue, 5 Mar 2019 13:04:53 -0500 Subject: [PATCH] Update favorite preset button state automatically --- modules/ui/preset_favorite.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/ui/preset_favorite.js b/modules/ui/preset_favorite.js index 00440cefc..2cc7b43b4 100644 --- a/modules/ui/preset_favorite.js +++ b/modules/ui/preset_favorite.js @@ -31,24 +31,24 @@ export function uiPresetFavorite(preset, geom, context, klass) { .merge(_button); _button - .classed('active', function() { - return context.isFavoritePreset(preset, geom); - }) .on('click', function () { d3_event.stopPropagation(); d3_event.preventDefault(); - //update state of favorite icon - d3_select(this) - .classed('active', function() { - return !d3_select(this).classed('active'); - }); - - context.favoritePreset(preset, geom); + context.favoritePreset(preset, geom); + update(); }); + update(); }; + function update() { + _button + .classed('active', context.isFavoritePreset(preset, geom)); + } + + context.on('favoritePreset.button-' + preset.id.replace(/[^a-zA-Z\d:]/g, '-') + '-' + geom, update); + return presetFavorite; }