Skip to content

Commit 8dc4c1a

Browse files
committed
Pan/Zoom toggle buttons
1 parent 35fb999 commit 8dc4c1a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

js/src/toolbar_widget.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ var ToolbarView = widgets.DOMWidgetView.extend({
3131
create_toolbar: function() {
3232
var toolbar_items = this.model.get('toolitems');
3333

34+
this.current_action = '';
35+
3436
this.toolbar_container = document.createElement('div');
3537
this.toolbar_container.classList = this.get_container_class();
3638
this.toggle_button = document.createElement('button');
@@ -85,12 +87,35 @@ var ToolbarView = widgets.DOMWidgetView.extend({
8587
toolbar_button_onclick: function(name) {
8688
var figure_id = this.model.get('figure_id');
8789
var toolbar_widget = this;
88-
return function() {
90+
91+
return function(event) {
92+
var button = event.target;
93+
94+
// Special case for pan and zoom as they are toggle buttons
95+
if (name == 'pan' || name == 'zoom') {
96+
if (toolbar_widget.current_action == '') {
97+
toolbar_widget.current_action = name;
98+
button.classList.add('mod-active');
99+
}
100+
else if (toolbar_widget.current_action == name) {
101+
toolbar_widget.current_action = '';
102+
button.classList.remove('mod-active');
103+
}
104+
else {
105+
toolbar_widget.current_action = name;
106+
[].forEach.call(toolbar_widget.toolbar.children, function(child) {
107+
child.classList.remove('mod-active');
108+
});
109+
button.classList.add('mod-active');
110+
}
111+
}
112+
89113
var message = {
90114
'type': 'toolbar_button',
91115
'figure_id': figure_id,
92116
'name': name
93117
};
118+
94119
toolbar_widget.send(JSON.stringify(message));
95120
};
96121
},

0 commit comments

Comments
 (0)