Question: toolbar button is appearing, when loading the mail for the first time
I am adding toolbar button to the gmail view, using gmail.js.
var main = function() { gmail = new Gmail(); // add toolbar gmail.tools.add_toolbar_button('', function()) }
calling this main function on page loading,
refresh(main); function refresh(f) { if( (/in/.test(document.readyState)) || (typeof Gmail === undefined) ) { setTimeout('refresh(' + f + ')', 10); } else { f(); } }
As, I am calling this main() on page loading, this toolbar button is appearing right after we are opening gmail ui. but my requirement is to show the toolbar button only when at least 1 mail is selected, like other toolbar buttons. How to catch the event of mail selection, so that I can call the add_toolbar_button() only when at least one mail is selected from visible label
used display:none style class to hide the button for 1 st time load of gmail. now button is visible only if 1 mail is s elected by checkbox. but button remains hidden if user clicks on the mail and open it
but my requirement is to show the toolbar button only when at least 1 mail is selected, like other toolbar buttons
No idea. You will have to roll your own.
gmail.tools.add_toolbar_button() only provides a means to inject a toolbar into the DOM. It does not help persist or manipulate it.
but button remains hidden if user clicks on the mail and open it
This is a known issue with several duplicate bug-reports. Search closed issues for workarounds.
Related to this issue, it looks like gmail on the inbox list is setting the display style to none for the the button if you select and then unselect a thread.
This is the minified code doing that:
if (this.Aa != a) {
this.Aa = a;
this.ha.Gc = a;
b = this.Ea(_.Dm);
for (var c = this.Ea("mam"), d = _.Lt(this.Na(), _.pd, "nu", this.Ea())[0], e = _.Lt(this.Na(), _.pd, _.nha, this.Ea()), f, h = 0; f = e[h]; h++)
d && _.Bt(f, d) ? f.style.display = a ? "" : _.Yk : c && _.Bt(f, c) ? (f = _.Lt(this.Na(), _.Ge, "bjy", this.Ea())[0],
_.Dt(f, _.vja)) : b && _.Bt(f, b) || (f.style.display = a ? _.Yk : "");
this.dispatchEvent(_.fm)
}
So basically even more pitfalls then? 😅
Old issue is old. Closing.