Skip to content

Commit ff36bad

Browse files
committed
Adds a feature to create a button on the right hand side of the toolbar at the end, right after the settings button.
On the other hand, the old add_toolbar_button function adds a button on the left half of the toolbar.
1 parent 886f3e7 commit ff36bad

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ These methods return the DOM data itself
218218
- gmail.dom**.get_left_sidebar_links()**
219219
- gmail.dom**.search_bar()**
220220
- gmail.dom**.toolbar()**
221+
- gmail.dom**.right_toolbar()**
221222
- gmail.dom**.compose()** - compose dom object - receives the DOM element for the compose window and provides methods to interact
222223
- gmail.dom**.composes()** - retrives an array of `gmail.dom.compose` objects representing any open compose windows
223224
- [gmail.dom**.email()**](#gmaildomemailemail_el-or-email_id) - email dom object - receives an email DOM element or email id for an email currently being viewed. Abstracts interaction with that email.
@@ -246,6 +247,7 @@ These are some helper functions that the rest of the methods use. See source for
246247
- gmail.tools**.i18n(label)**
247248
- gmail.tools**.toggle_minimize()**
248249
- [gmail.tools**.add_toolbar_button(content_html, onclick_action, custom_style_class)**](#gmailtoolsadd_toolbar_buttoncontent_html-onclick_action-custom_style_class)
250+
- [gmail.tools**.add_right_toolbar_button(content_html, onclick_action, custom_style_class)**](#gmailtoolsadd_right_toolbar_buttoncontent_html-onclick_action-custom_style_class)
249251
- [gmail.tools**.add_compose_button(compose_ref, content_html, onclick_action, custom_style_class)**](#gmailtoolsadd_toolbar_buttoncompose_ref-content_html-onclick_action-custom_style_class)
250252
- [gmail.tools**.add_modal_window(title, content_html, onClickOk, onClickCancel, onClickClose)**](#gmailtoolsadd_modal_windowtitle-content_html-onClickOk-onClickCancel-onClickClose)
251253
- [gmail.tools**.remove_modal_window()**](#gmailtoolsremove_modal_window)
@@ -1265,6 +1267,16 @@ gmail.tools.add_toolbar_button('content_html', function() {
12651267
}, 'Custom Style Classes');
12661268
```
12671269

1270+
#### gmail.tools.add_right_toolbar_button(content_html, onclick_action, custom_style_class)
1271+
1272+
Add a new button to Gmail Toolbar on the right hand side
1273+
1274+
```js
1275+
gmail.tools.add_right_toolbar_button('content_html', function() {
1276+
// Code here
1277+
}, 'Custom Style Classes');
1278+
```
1279+
12681280
#### gmail.tools.add_compose_button(compose_ref, content_html, onclick_action, custom_style_class)
12691281

12701282
Add button to compose window.

src/gmail.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ var Gmail_ = function(localJQuery) {
292292
return tb;
293293
};
294294

295+
api.dom.right_toolbar = function() {
296+
var rtb = $(".Cr.aqJ");
297+
298+
while($(rtb).children().length === 1){
299+
rtb = $(rtb).children().first();
300+
}
301+
302+
return rtb;
303+
};
295304

296305
api.check.is_inside_email = function() {
297306
if(api.get.current_page() !== "email" && !api.check.is_preview_pane()) {
@@ -2293,6 +2302,34 @@ var Gmail_ = function(localJQuery) {
22932302
return container;
22942303
};
22952304

2305+
api.tools.add_right_toolbar_button = function(content_html, onClickFunction, styleClass) {
2306+
var container = $(document.createElement("div"));
2307+
container.attr("class","G-Ni J-J5-Ji");
2308+
2309+
var button = $(document.createElement("div"));
2310+
var buttonClasses = "T-I J-J5-Ji ash ";
2311+
if(styleClass !== undefined &&
2312+
styleClass !== null &&
2313+
styleClass !== ""){
2314+
buttonClasses += styleClass;
2315+
}else{
2316+
buttonClasses += "T-I-ax7 L3";
2317+
}
2318+
button.attr("class", buttonClasses);
2319+
2320+
button.html(content_html);
2321+
button.click(onClickFunction);
2322+
2323+
var content = $(document.createElement("div"));
2324+
content.attr("class","asa");
2325+
2326+
container.html(button);
2327+
2328+
api.dom.right_toolbar().append(container);
2329+
2330+
return container;
2331+
};
2332+
22962333
api.tools.add_compose_button = function(composeWindow, content_html, onClickFunction, styleClass) {
22972334
var button = $(document.createElement("div"));
22982335
var buttonClasses = "T-I J-J5-Ji aoO L3 ";

0 commit comments

Comments
 (0)