| 344 | } |
| 345 | |
| 346 | addMenuBtn(name, container, beforeElem, clickHandler) { |
| 347 | let menuItemShadowRootElem = container.querySelector(`[data-mv-menu-item="${name}"]`); |
| 348 | let secureMenuItemShadow; |
| 349 | if (!menuItemShadowRootElem) { |
| 350 | menuItemShadowRootElem = document.createElement('div'); |
| 351 | menuItemShadowRootElem.dataset.mvMenuItem = name; |
| 352 | menuItemShadowRootElem.setAttribute('role', 'menuitem'); |
| 353 | container.insertBefore(menuItemShadowRootElem, beforeElem || container.firstChild); |
| 354 | const secureMenuItem = document.createElement('div'); |
| 355 | secureMenuItem.classList.add('mv-menu-item', `mv-menu-item-${name}`); |
| 356 | secureMenuItem.textContent = l10n.map[`provider_gmail_secure_${name}_btn`]; |
| 357 | secureMenuItemShadow = menuItemShadowRootElem.attachShadow({mode: 'open'}); |
| 358 | const secureMenuItemStyle = document.createElement('style'); |
| 359 | secureMenuItemStyle.textContent = gmailIntegrationCsss; |
| 360 | secureMenuItemShadow.append(secureMenuItemStyle); |
| 361 | secureMenuItemShadow.append(secureMenuItem); |
| 362 | } else { |
| 363 | secureMenuItemShadow = menuItemShadowRootElem.shadowRoot; |
| 364 | const cloned = secureMenuItemShadow.lastChild.cloneNode(true); |
| 365 | secureMenuItemShadow.replaceChild(cloned, secureMenuItemShadow.lastChild); |
| 366 | } |
| 367 | secureMenuItemShadow.lastChild.addEventListener('click', clickHandler, {once: true}); |
| 368 | } |
| 369 | |
| 370 | cleanupMenuBtns() { |
| 371 | if (this.menuPopover) { |