UNPKG

@textback/notification-widget

Version:

TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.

59 lines (53 loc) 2.87 kB
import Button from './index.js'; import icon from '../../icons/icon_whatsapp.svg'; import iconNew from '../../icons/icon_whatsapp_new.svg'; import iconCircle from '../../icons/icon_whatsapp_circle.svg'; import constants from '../../../sdk/utils/constants.js'; const prefixText = encodeURIComponent('Отправьте не изменяя это сообщение '); class WhatsappButton extends Button { render() { super.render(); const link = this.element.querySelector('a'); link.addEventListener('click', (event) => { event.preventDefault(); this.channelAPI.subscribe(); }); } get template() { if (this.config.type === constants.WIDGET_TYPE_API_CALL) { return ` <a target="_blank" href="https://api.whatsapp.com/send/?phone=+${this.config.id}&text=${prefixText + this.deepLink}"> <tb-notification-button__icon>${icon}</tb-notification-button__icon> <tb-notification-button__text>${this.text('whatsapp')}</tb-notification-button__text> </a> <p class="tb-notification-button__tip"> ${this.text('whatsappTip')} </p> `; } else if(this.config.markUp.style === 'gradient' || this.config.markUp.style === 'icons') { return ` <a target="_blank" href="https://api.whatsapp.com/send/?phone=+${this.config.id}&text=${prefixText + this.deepLink}"> <tb-notification-button__icon>${iconCircle}</tb-notification-button__icon> <tb-notification-button__text>${this.text('whatsapp')}</tb-notification-button__text> </a> `; } else if (this.config.markUp.style !== 'square') { return ` <a target="_blank" href="https://api.whatsapp.com/send/?phone=+${this.config.id}&text=${prefixText + this.deepLink}"> <tb-notification-button__icon>${( this.config.markUp.style === 'rounded' ? iconCircle : icon )}</tb-notification-button__icon> <tb-notification-button__text>${this.text('whatsapp')}</tb-notification-button__text> </a> `; } else { return ` <div class="tb-notification-button__inner"> <tb-notification-button__icon>${iconNew}</tb-notification-button__icon> <a target="_blank" href="https://api.whatsapp.com/send/?phone=+${this.config.id}&text=${prefixText + this.deepLink}"> <tb-notification-button__text>${this.text('whatsappExtended')}</tb-notification-button__text> </a> </div> `; } } }; module.exports = WhatsappButton;