Skip to content

Commit

Permalink
Reorganize the code for setting the mode class on the container
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed May 29, 2020
1 parent 7877e8a commit 620d79b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
10 changes: 10 additions & 0 deletions modules/ui/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ export function uiInit(context) {
context.map().toggleHighlightEdited();
});

context
.on('enter.editor', function(entered) {
container
.classed('mode-' + entered.id, true);
})
.on('exit.editor', function(exited) {
container
.classed('mode-' + exited.id, false);
});

context.enter(modeBrowse(context));

if (!_initCounter++) {
Expand Down
18 changes: 2 additions & 16 deletions modules/ui/tools/modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,6 @@ export function uiToolOldDrawModes(context) {
.attr('class', 'joined')
.style('display', 'flex');

context
.on('enter.editor', function(entered) {
selection.selectAll('button.add-button')
.classed('active', function(mode) { return entered.button === mode.button; });
context.container()
.classed('mode-' + entered.id, true);
});

context
.on('exit.editor', function(exited) {
context.container()
.classed('mode-' + exited.id, false);
});


var debouncedUpdate = _debounce(update, 500, { leading: true, trailing: true });

context.map()
Expand Down Expand Up @@ -152,7 +137,8 @@ export function uiToolOldDrawModes(context) {
// update
buttons = buttons
.merge(buttonsEnter)
.classed('disabled', function(d) { return !enabled(d); });
.classed('disabled', function(d) { return !enabled(d); })
.classed('active', function(d) { return context.mode() && context.mode().button === d.button; });
}
};

Expand Down
17 changes: 2 additions & 15 deletions modules/ui/tools/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@ export function uiToolNotes(context) {

tool.render = function(selection) {

context
.on('enter.editor.notes', function(entered) {
selection.selectAll('button.add-button')
.classed('active', function(mode) { return entered.button === mode.button; });
context.container()
.classed('mode-' + entered.id, true);
});

context
.on('exit.editor.notes', function(exited) {
context.container()
.classed('mode-' + exited.id, false);
});


var debouncedUpdate = _debounce(update, 500, { leading: true, trailing: true });

Expand Down Expand Up @@ -123,7 +109,8 @@ export function uiToolNotes(context) {
// update
buttons = buttons
.merge(buttonsEnter)
.classed('disabled', function(d) { return !enabled(d); });
.classed('disabled', function(d) { return !enabled(d); })
.classed('active', function(d) { return context.mode() && context.mode().button === d.button; });
}
};

Expand Down

0 comments on commit 620d79b

Please sign in to comment.