@odilo/core
Version:
Share buttons components for Angular and Ionic.
1,743 lines (1,715 loc) • 58 kB
JavaScript
import { DOCUMENT } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Meta } from '@angular/platform-browser';
import { Platform, PlatformModule } from '@angular/cdk/platform';
import { BehaviorSubject, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { InjectionToken, Inject, Injectable, Optional, NgModule, Directive, Input, Output, HostBinding, HostListener, EventEmitter, ElementRef, Renderer2, ChangeDetectorRef, Pipe, defineInjectable, inject } from '@angular/core';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const SHARE_BUTTONS_CONFIG = new InjectionToken('shareButtonsConfig');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._self = this;
/**
* If share button supports share count
*/
this.supportShareCount = false;
}
/**
* Share button label
* @return {?}
*/
get text() {
return this._props.text;
}
/**
* Share button aria-label attribute
* @return {?}
*/
get ariaLabel() {
return this._props.ariaLabel;
}
/**
* Share button color
* @return {?}
*/
get color() {
return this._props.color;
}
/**
* Share button icon (FontAwesome)
* @return {?}
*/
get icon() {
return this._props.icon;
}
/**
* @return {?}
*/
get desktop() {
return undefined;
}
/**
* @return {?}
*/
get android() {
return this.desktop;
}
/**
* @return {?}
*/
get ios() {
return this.desktop;
}
/**
* @return {?}
*/
get sharerUrl() {
if (this._platform.IOS)
return this.ios;
if (this._platform.ANDROID)
return this.android;
return this.desktop;
}
/**
* Opens share window
* @param {?} metaTags
* @return {?}
*/
click(metaTags) {
return this._open(this._serializeMetaTags(metaTags));
}
/**
* Get share count of a URL
* @param {?} url
* @return {?}
*/
shareCount(url) {
return undefined;
}
/**
* @protected
* @param {?} metaTags
* @return {?}
*/
_serializeMetaTags(metaTags) {
return Object.entries(this._supportedMetaTags)
.map((/**
* @param {?} __0
* @return {?}
*/
([key, value]) => metaTags[key] ? `${value}=${encodeURIComponent(metaTags[key])}` : ''))
.join('&');
}
/**
* @protected
* @param {?} serializedMetaTags
* @return {?}
*/
_open(serializedMetaTags) {
return new Promise((/**
* @param {?} resolve
* @return {?}
*/
(resolve) => {
// Avoid SSR error
if (this.sharerUrl && this._platform.isBrowser) {
/** @type {?} */
const finalUrl = this.sharerUrl + serializedMetaTags;
// Debug mode, log sharer link
this._logger(finalUrl);
/** @type {?} */
const popUp = this._document.defaultView.open(finalUrl, 'newwindow', this._windowSize);
// Resolve when share dialog is closed
if (popUp) {
/** @type {?} */
const pollTimer = this._document.defaultView.setInterval((/**
* @return {?}
*/
() => {
if (popUp.closed) {
this._document.defaultView.clearInterval(pollTimer);
resolve();
}
}), 200);
}
}
else {
console.warn(`${this.text} button is not compatible on this Platform`);
}
}));
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class FacebookButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this.supportShareCount = true;
this._supportedMetaTags = {
url: 'u'
};
}
/**
* @return {?}
*/
get desktop() {
return `https://www.facebook.com/sharer/sharer.php?`;
}
/**
* @param {?} url
* @return {?}
*/
shareCount(url) {
return this._http.get(`https://graph.facebook.com?id=${url}`).pipe(map((/**
* @param {?} res
* @return {?}
*/
(res) => +res.share.share_count)));
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class TwitterButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url',
description: 'text',
tags: 'hashtags',
via: 'via'
};
}
/**
* @return {?}
*/
get desktop() {
return `https://twitter.com/intent/tweet?`;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class LinkedinButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url',
title: 'title',
description: 'summary'
};
}
/**
* @return {?}
*/
get desktop() {
return `http://www.linkedin.com/shareArticle?`;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class GooglePlusButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url'
};
}
/**
* @return {?}
*/
get desktop() {
return `https://plus.google.com/share?`;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class TumblrButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this.supportShareCount = true;
this._supportedMetaTags = {
url: 'canonicalUrl',
description: 'caption',
tags: 'tags'
};
}
/**
* @return {?}
*/
get desktop() {
return `http://tumblr.com/widgets/share/tool?`;
}
/**
* @param {?} url
* @return {?}
*/
shareCount(url) {
return this._http.jsonp(`https://api.tumblr.com/v2/share/stats?url=${url}`, 'callback').pipe(map((/**
* @param {?} res
* @return {?}
*/
(res) => +res.response.note_count)));
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class PinterestButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this.supportShareCount = true;
this._supportedMetaTags = {
url: 'url',
description: 'description',
image: 'media'
};
}
/**
* @return {?}
*/
get desktop() {
return `https://pinterest.com/pin/create/button/?`;
}
/**
* @param {?} metaTags
* @return {?}
*/
click(metaTags) {
// Check if image parameter is defined
if (metaTags.image) {
return this._open(this._serializeMetaTags(metaTags));
}
console.warn('Pinterest button: image parameter is required!');
}
/**
* @param {?} url
* @return {?}
*/
shareCount(url) {
return this._http.get(`https://api.pinterest.com/v1/urls/count.json?url=${url}`, { responseType: 'text' }).pipe(map((/**
* @param {?} text
* @return {?}
*/
(text) => JSON.parse(text.replace(/^receiveCount\((.*)\)/, '$1')))), map((/**
* @param {?} res
* @return {?}
*/
(res) => +res.count)));
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class RedditButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url',
title: 'title'
};
}
/**
* @return {?}
*/
get desktop() {
return `http://www.reddit.com/submit?`;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class VkButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url'
};
}
/**
* @return {?}
*/
get desktop() {
return `http://vk.com/share.php?`;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class TelegramButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url',
description: 'text'
};
}
/**
* @return {?}
*/
get desktop() {
return 'https://t.me/share/url?';
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MessengerButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'link'
};
}
/**
* @return {?}
*/
get android() {
return 'fb-messenger://share/?';
}
/**
* @return {?}
*/
get ios() {
return 'fb-messenger://share/?';
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class WhatsappButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
description: 'text'
};
}
/**
* @return {?}
*/
get desktop() {
return `https://wa.me/?`;
}
/**
* @return {?}
*/
get android() {
return `whatsapp://send?`;
}
/**
* @return {?}
*/
get ios() {
return `https://api.whatsapp.com/send?`;
}
/**
* @param {?} metaTags
* @return {?}
*/
click(metaTags) {
// Add the URL to message body
metaTags.description = metaTags.description ? `${metaTags.description}\r\n${this._url()}` : this._url();
/** @type {?} */
const serializedMetaTags = this._serializeMetaTags(metaTags);
return this._open(serializedMetaTags);
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class XingButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url'
};
}
/**
* @return {?}
*/
get desktop() {
return `https://www.xing.com/app/user?op=share&`;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class SmsButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
description: 'body'
};
}
/**
* @return {?}
*/
get desktop() {
return `sms:?`;
}
/**
* @return {?}
*/
get android() {
return `sms:?`;
}
/**
* @return {?}
*/
get ios() {
return 'sms:&';
}
/**
* @param {?} metaTags
* @return {?}
*/
click(metaTags) {
// Add the URL to message body
metaTags.description = metaTags.description ? `${metaTags.description}\r\n${this._url()}` : this._url();
/** @type {?} */
const serializedMetaTags = this._serializeMetaTags(metaTags);
return this._open(serializedMetaTags);
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class EmailButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
title: 'subject',
description: 'body'
};
}
/**
* @return {?}
*/
get desktop() {
return `mailto:?`;
}
/**
* @param {?} metaTags
* @return {?}
*/
click(metaTags) {
// Add URL to message body
metaTags.description = metaTags.description ? `${metaTags.description}\r\n${this._url()}` : this._url();
/** @type {?} */
const serializedMetaTags = this._serializeMetaTags(metaTags);
return this._open(serializedMetaTags);
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class PrintButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
}
/**
* @return {?}
*/
click() {
return new Promise((/**
* @param {?} resolve
* @return {?}
*/
(resolve) => {
this._document.defaultView.print();
resolve();
}));
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class CopyButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
}
/**
* @return {?}
*/
get text() {
return this._disable ? this._props.extra.successLabel : this._props.text;
}
/**
* @return {?}
*/
get icon() {
return this._disable ? this._props.extra.successIcon : this._props.icon;
}
/**
* @private
* @return {?}
*/
_disableButton() {
// Disable pointer for tiny delay
this._disable = true;
this._disableButtonClick(true);
}
/**
* @private
* @return {?}
*/
_resetButton() {
this._disable = false;
this._disableButtonClick(false);
}
/**
* @return {?}
*/
click() {
return new Promise((/**
* @param {?} resolve
* @return {?}
*/
(resolve) => {
try {
/** @type {?} */
const textArea = (/** @type {?} */ (this._document.createElement('textarea')));
textArea.value = decodeURIComponent(this._url());
this._document.body.appendChild(textArea);
// highlight TextArea to copy the sharing link
if (this._platform.IOS) {
/** @type {?} */
const range = this._document.createRange();
range.selectNodeContents(textArea);
/** @type {?} */
const selection = this._document.defaultView.getSelection();
selection.removeAllRanges();
selection.addRange(range);
textArea.readOnly = true;
textArea.setSelectionRange(0, 999999);
}
else {
textArea.select();
}
this._document.execCommand('copy');
this._document.body.removeChild(textArea);
this._disableButton();
}
catch (e) {
console.warn('Copy link failed!', e.message);
}
finally {
setTimeout((/**
* @return {?}
*/
() => this._resetButton()), 2000);
resolve();
}
}));
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MixButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url'
};
}
/**
* @return {?}
*/
get desktop() {
return `https://mix.com/add?`;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class LineButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url'
};
}
/**
* @return {?}
*/
get desktop() {
return `https://social-plugins.line.me/lineit/share?`;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class QqButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url',
title: 'title',
description: 'desc'
};
}
/**
* @return {?}
*/
get desktop() {
return 'https://connect.qq.com/widget/shareqq/index.html?';
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class WeiboButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'url',
description: 'title'
};
}
/**
* @return {?}
*/
get desktop() {
return 'http://service.weibo.com/share/share.php?';
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class WeChatButton extends ShareButtonBase {
/**
* @param {?} _props
* @param {?} _url
* @param {?} _http
* @param {?} _platform
* @param {?} _document
* @param {?} _windowSize
* @param {?} _disableButtonClick
* @param {?} _logger
*/
constructor(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger) {
super(_props, _url, _http, _platform, _document, _windowSize, _disableButtonClick, _logger);
this._props = _props;
this._url = _url;
this._http = _http;
this._platform = _platform;
this._document = _document;
this._windowSize = _windowSize;
this._disableButtonClick = _disableButtonClick;
this._logger = _logger;
this._supportedMetaTags = {
url: 'data'
};
}
/**
* @return {?}
*/
get desktop() {
return 'https://api.qrserver.com/v1/create-qr-code/?';
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Default share buttons properties
* @type {?}
*/
const SHARE_BUTTONS = {
facebook: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new FacebookButton(a, b, c, d, e, f, g, h)),
text: 'Facebook',
icon: ['fab', 'facebook-f'],
color: '#4267B2',
ariaLabel: 'Share on Facebook'
},
twitter: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new TwitterButton(a, b, c, d, e, f, g, h)),
text: 'Twitter',
icon: ['fab', 'twitter'],
color: '#00acee',
ariaLabel: 'Share on Twitter'
},
linkedin: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new LinkedinButton(a, b, c, d, e, f, g, h)),
text: 'LinkedIn',
icon: ['fab', 'linkedin-in'],
color: '#006fa6',
ariaLabel: 'Share on LinkedIn'
},
google: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new GooglePlusButton(a, b, c, d, e, f, g, h)),
text: 'Google+',
icon: ['fab', 'google-plus-g'],
color: '#DB4437',
ariaLabel: 'Share on Google plus'
},
pinterest: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new PinterestButton(a, b, c, d, e, f, g, h)),
text: 'Pinterest',
icon: ['fab', 'pinterest-p'],
color: '#BD091D',
ariaLabel: 'Share on Pinterest'
},
reddit: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new RedditButton(a, b, c, d, e, f, g, h)),
text: 'Reddit',
icon: ['fab', 'reddit-alien'],
color: '#FF4006',
ariaLabel: 'Share on Reddit'
},
tumblr: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new TumblrButton(a, b, c, d, e, f, g, h)),
text: 'Tumblr',
icon: ['fab', 'tumblr'],
color: '#36465D',
ariaLabel: 'Share on Tumblr'
},
mix: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new MixButton(a, b, c, d, e, f, g, h)),
text: 'Mix',
icon: ['fab', 'mix'],
color: '#ff8226',
ariaLabel: 'Share on Mix'
},
vk: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new VkButton(a, b, c, d, e, f, g, h)),
text: 'VKontakte',
icon: ['fab', 'vk'],
color: '#4C75A3',
ariaLabel: 'Share on VKontakte'
},
telegram: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new TelegramButton(a, b, c, d, e, f, g, h)),
text: 'Telegram',
icon: ['fab', 'telegram-plane'],
color: '#0088cc',
ariaLabel: 'Share on Telegram'
},
messenger: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new MessengerButton(a, b, c, d, e, f, g, h)),
text: 'Messenger',
icon: ['fab', 'facebook-messenger'],
color: '#0080FF',
ariaLabel: 'Share on Messenger'
},
whatsapp: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new WhatsappButton(a, b, c, d, e, f, g, h)),
text: 'WhatsApp',
icon: ['fab', 'whatsapp'],
color: '#25D366',
ariaLabel: 'Share on WhatsApp'
},
xing: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new XingButton(a, b, c, d, e, f, g, h)),
text: 'Xing',
icon: ['fab', 'xing'],
color: '#006567',
ariaLabel: 'Share on Xing'
},
line: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new LineButton(a, b, c, d, e, f, g, h)),
text: 'Line',
icon: ['fab', 'line'],
color: '#00b900',
ariaLabel: 'Share on Line'
},
sms: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new SmsButton(a, b, c, d, e, f, g, h)),
text: 'SMS',
icon: 'comment-alt',
color: '#20c16c',
ariaLabel: 'Share link via SMS'
},
email: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new EmailButton(a, b, c, d, e, f, g, h)),
text: 'Email',
icon: 'envelope',
color: '#FF961C',
ariaLabel: 'Share link via email'
},
print: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new PrintButton(a, b, c, d, e, f, g, h)),
text: 'Print',
icon: 'print',
color: '#765AA2',
ariaLabel: 'Print page'
},
copy: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new CopyButton(a, b, c, d, e, f, g, h)),
text: 'Copy link',
icon: 'link',
color: '#607D8B',
ariaLabel: 'Copy link',
extra: {
successLabel: 'Copied',
successIcon: 'check'
}
},
qq: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new QqButton(a, b, c, d, e, f, g, h)),
text: 'QQ',
icon: ['fab', 'qq'],
color: '#000',
ariaLabel: 'Share on QQ'
},
weibo: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new WeiboButton(a, b, c, d, e, f, g, h)),
text: 'Weibo',
icon: ['fab', 'weibo'],
color: '#000',
ariaLabel: 'Share on Weibo'
},
wechat: {
create: (/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} e
* @param {?} f
* @param {?} g
* @param {?} h
* @return {?}
*/
(a, b, c, d, e, f, g, h) => new WeChatButton(a, b, c, d, e, f, g, h)),
text: 'WeChat',
icon: ['fab', 'weixin'],
color: '#000',
ariaLabel: 'Share on WeChat'
},
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Simple object check.
* @param {?} item
* @return {?}
*/
function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
/**
* Deep merge two objects.
* @param {?} target
* @param {...?} sources
* @return {?}
*/
function mergeDeep(target, ...sources) {
if (!sources.length) {
return target;
}
/** @type {?} */
const source = sources.shift();
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) {
Object.assign(target, { [key]: {} });
}
mergeDeep(target[key], source[key]);
}
else {
Object.assign(target, { [key]: source[key] });
}
}
}
return mergeDeep(target, ...sources);
}
/**
* Returns a readable number from share count
* @param {?} num
* @param {?} digits
* @return {?}
*/
function shareCountFormatter(num, digits) {
/** @type {?} */
const si = [
{ value: 1E9, symbol: 'B' },
{ value: 1E6, symbol: 'M' },
{ value: 1E3, symbol: 'K' }
];
/** @type {?} */
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
for (let i = 0; i < si.length; i++) {
if (num >= si[i].value) {
return (num / si[i].value).toFixed(digits).replace(rx, '$1') + si[i].symbol;
}
}
return num.toFixed(digits).replace(rx, '$1');
}
/**
* Returns a valid URL or falls back to current URL
* @param {?} url
* @param {?} fallbackUrl
* @return {?}
*/
function getValidUrl(url, fallbackUrl) {
if (url) {
/** @type {?} */
const r = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
if (r.test(url))
return url;
console.warn(`[ShareButtons]: Sharing link '${url}' is invalid!`);
}
return fallbackUrl;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class ShareService {
/**
* @param {?} config
*/
constructor(config) {
/**
* Global config that applies on all share buttons in the app
*/
this.config = {
prop: SHARE_BUTTONS,
theme: 'default',
include: [],
exclude: [],
size: 0,
autoSetMeta: true,
windowWidth: 800,
windowHeight: 500,
moreButtonIcon: 'ellipsis-h',
lessButtonIcon: 'minus'
};
/**
* Stream that emits when config changes
*/
this.config$ = new BehaviorSubject(this.config);
if (config) {
this.setConfig(config);
}
}
/**
* Share buttons properties, used to get the text, color and icon of each button.
* @return {?}
*/
get prop() {
return this.config.prop;
}
/**
* @return {?}
*/
get windowSize() {
return `width=${this.config.windowWidth}, height=${this.config.windowHeight}`;
}
/**
* @param {?} config
* @return {?}
*/
setConfig(config) {
this.config = mergeDeep(this.config, config);
this.config$.next(this.config);
}
}
ShareService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
ShareService.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [SHARE_BUTTONS_CONFIG,] }] }
];
/** @nocollapse */ ShareService.ngInjectableDef = defineInjectable({ factory: function ShareService_Factory() { return new ShareService(inject(SHARE_BUTTONS_CONFIG, 8)); }, token: ShareService, providedIn: "root" });
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class ShareDirective {
/**
* @param {?} _meta
* @param {?} _el
* @param {?} _http
* @param {?} _platform
* @param {?} _renderer
* @param {?} _cd
* @param {?} _share
* @param {?} _document
*/
constructor(_meta, _el, _http, _platform, _renderer, _cd, _share, _document) {
this._meta = _meta;
this._el = _el;
this._http = _http;
this._platform = _platform;
this._renderer = _renderer;
this._cd = _cd;
this._share = _share;
this._document = _document;
/**
* Share window closed event subscription
*/
this._shareWindowClosed = Subscription.EMPTY;
/**
* Get share count
*/
this.getCount = false;
/**
* Set meta tags from document head, useful when SEO is supported
*/
this.autoSetMeta = this._share.config.autoSetMeta;
/**
* Sharing link
*/
this.url = this._share.config.url;
/**
* Sets the title parameter
*/
this.title = this._share.config.title;
/**
* Sets the description parameter
*/
this.description = this._share.config.description;
/**
* Sets the image parameter for sharing on Pinterest
*/
this.image = this._share.config.image;
/**
* Sets the tags parameter for sharing on Twitter and Tumblr
*/
this.tags = this._share.config