@@ -13,7 +13,8 @@ var ToolbarModel = widgets.DOMWidgetModel.extend({
13
13
_model_module_version : '^' + version ,
14
14
_view_module_version : '^' + version ,
15
15
toolitems : [ ] ,
16
- orientation : 'vertical'
16
+ orientation : 'vertical' ,
17
+ button_style : ''
17
18
} ) ;
18
19
}
19
20
} ) ;
@@ -52,6 +53,8 @@ var ToolbarView = widgets.DOMWidgetView.extend({
52
53
this . toolbar . classList = this . get_container_class ( ) ;
53
54
this . toolbar_container . appendChild ( this . toolbar ) ;
54
55
56
+ this . buttons = [ this . toggle_button ] ;
57
+
55
58
for ( var toolbar_ind in toolbar_items ) {
56
59
var name = toolbar_items [ toolbar_ind ] [ 0 ] ;
57
60
var tooltip = toolbar_items [ toolbar_ind ] [ 1 ] ;
@@ -70,8 +73,12 @@ var ToolbarView = widgets.DOMWidgetView.extend({
70
73
icon . classList = 'center fa fa-' + image ;
71
74
button . appendChild ( icon ) ;
72
75
76
+ this . buttons . push ( button ) ;
77
+
73
78
this . toolbar . appendChild ( button ) ;
74
79
}
80
+
81
+ this . set_buttons_style ( ) ;
75
82
} ,
76
83
77
84
get_container_class : function ( ) {
@@ -84,27 +91,27 @@ var ToolbarView = widgets.DOMWidgetView.extend({
84
91
} ,
85
92
86
93
toolbar_button_onclick : function ( name ) {
87
- var toolbar_widget = this ;
94
+ var that = this ;
88
95
89
96
return function ( event ) {
90
- var button = event . target ;
97
+ var target = event . target ;
91
98
92
99
// Special case for pan and zoom as they are toggle buttons
93
100
if ( name == 'pan' || name == 'zoom' ) {
94
- if ( toolbar_widget . current_action == '' ) {
95
- toolbar_widget . current_action = name ;
96
- button . classList . add ( 'mod-active' ) ;
101
+ if ( that . current_action == '' ) {
102
+ that . current_action = name ;
103
+ target . classList . add ( 'mod-active' ) ;
97
104
}
98
- else if ( toolbar_widget . current_action == name ) {
99
- toolbar_widget . current_action = '' ;
100
- button . classList . remove ( 'mod-active' ) ;
105
+ else if ( that . current_action == name ) {
106
+ that . current_action = '' ;
107
+ target . classList . remove ( 'mod-active' ) ;
101
108
}
102
109
else {
103
- toolbar_widget . current_action = name ;
104
- [ ] . forEach . call ( toolbar_widget . toolbar . children , function ( child ) {
105
- child . classList . remove ( 'mod-active' ) ;
110
+ that . current_action = name ;
111
+ that . buttons . forEach ( function ( button ) {
112
+ button . classList . remove ( 'mod-active' ) ;
106
113
} ) ;
107
- button . classList . add ( 'mod-active' ) ;
114
+ target . classList . add ( 'mod-active' ) ;
108
115
}
109
116
}
110
117
@@ -113,8 +120,31 @@ var ToolbarView = widgets.DOMWidgetView.extend({
113
120
'name' : name
114
121
} ;
115
122
116
- toolbar_widget . send ( message ) ;
123
+ that . send ( message ) ;
124
+ } ;
125
+ } ,
126
+
127
+ set_buttons_style : function ( ) {
128
+ var that = this ;
129
+
130
+ var class_map = {
131
+ primary : [ 'mod-primary' ] ,
132
+ success : [ 'mod-success' ] ,
133
+ info : [ 'mod-info' ] ,
134
+ warning : [ 'mod-warning' ] ,
135
+ danger : [ 'mod-danger' ]
117
136
} ;
137
+
138
+ this . buttons . forEach ( function ( button ) {
139
+ for ( var class_name in class_map ) {
140
+ button . classList . remove ( class_map [ class_name ] ) ;
141
+ }
142
+
143
+ var class_name = that . model . get ( 'button_style' ) ;
144
+ if ( class_name != '' ) {
145
+ button . classList . add ( class_map [ class_name ] ) ;
146
+ }
147
+ } ) ;
118
148
} ,
119
149
120
150
toggle_interaction : function ( ) {
@@ -125,6 +155,7 @@ var ToolbarView = widgets.DOMWidgetView.extend({
125
155
126
156
model_events : function ( ) {
127
157
this . model . on ( 'change:orientation' , this . update_orientation . bind ( this ) ) ;
158
+ this . model . on ( 'change:button_style' , this . set_buttons_style . bind ( this ) ) ;
128
159
} ,
129
160
130
161
update_orientation : function ( ) {
0 commit comments