UNPKG

ng-social-media-share

Version:

A reusable Angular component for social media share buttons.

138 lines (137 loc) 7.92 kB
"use strict"; var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); var _, done = false; for (var i = decorators.length - 1; i >= 0; i--) { var context = {}; for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; for (var p in contextIn.access) context.access[p] = contextIn.access[p]; context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); if (kind === "accessor") { if (result === void 0) continue; if (result === null || typeof result !== "object") throw new TypeError("Object expected"); if (_ = accept(result.get)) descriptor.get = _; if (_ = accept(result.set)) descriptor.set = _; if (_ = accept(result.init)) initializers.unshift(_); } else if (_ = accept(result)) { if (kind === "field") initializers.unshift(_); else descriptor[key] = _; } } if (target) Object.defineProperty(target, contextIn.name, descriptor); done = true; }; var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { var useValue = arguments.length > 2; for (var i = 0; i < initializers.length; i++) { value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); } return useValue ? value : void 0; }; var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) { if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SocialMediaShareComponent = void 0; const core_1 = require("@angular/core"); let SocialMediaShareComponent = (() => { let _classDecorators = [(0, core_1.Component)({ selector: 'social-media-share', template: ` <div class="social-media-share"> <a *ngFor="let platform of socialMediaList" [href]="getShareLink(platform)" target="_blank"> <img [src]="getIconUrl(platform)" [alt]="platform"> </a> </div> `, styles: [` .social-media-share { display: flex; } .social-media-share img { margin-right: 10px; width: 30px; height: auto; } `] })]; let _classDescriptor; let _classExtraInitializers = []; let _classThis; let _instanceExtraInitializers = []; let _url_decorators; let _url_initializers = []; let _width_decorators; let _width_initializers = []; let _platforms_decorators; let _platforms_initializers = []; var SocialMediaShareComponent = _classThis = class { constructor() { this.url = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _url_initializers, void 0)); this.width = __runInitializers(this, _width_initializers, 30); this.platforms = __runInitializers(this, _platforms_initializers, []); this.socialMediaList = [ 'facebook', 'twitter', 'linkedin', 'instagram', 'pinterest', 'whatsapp', 'reddit', 'tumblr', 'telegram', 'snapchat', 'youtube', 'email', 'medium' ]; } getIconUrl(platform) { return `https://cdn.jsdelivr.net/npm/simple-icons@5.15.2/icons/${platform}.svg`; } getShareLink(platform) { switch (platform) { case 'facebook': return `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(this.url)}`; case 'twitter': return `https://twitter.com/intent/tweet?url=${encodeURIComponent(this.url)}`; case 'linkedin': return `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(this.url)}`; case 'instagram': return `https://www.instagram.com/share?url=${encodeURIComponent(this.url)}`; case 'pinterest': return `https://pinterest.com/pin/create/button/?url=${encodeURIComponent(this.url)}`; case 'whatsapp': return `https://api.whatsapp.com/send?text=${encodeURIComponent(this.url)}`; case 'reddit': return `https://reddit.com/submit?url=${encodeURIComponent(this.url)}`; case 'tumblr': return `https://www.tumblr.com/share/link?url=${encodeURIComponent(this.url)}`; case 'telegram': return `https://telegram.me/share/url?url=${encodeURIComponent(this.url)}`; case 'snapchat': return `https://www.snapchat.com/add/${encodeURIComponent(this.url)}`; case 'youtube': return `https://www.youtube.com/watch?v=${encodeURIComponent(this.url)}`; case 'email': return `mailto:?body=${encodeURIComponent(this.url)}`; case 'medium': return `https://medium.com/p/${encodeURIComponent(this.url)}`; default: return ''; } } }; __setFunctionName(_classThis, "SocialMediaShareComponent"); (() => { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; _url_decorators = [(0, core_1.Input)()]; _width_decorators = [(0, core_1.Input)()]; _platforms_decorators = [(0, core_1.Input)()]; __esDecorate(null, null, _url_decorators, { kind: "field", name: "url", static: false, private: false, access: { has: obj => "url" in obj, get: obj => obj.url, set: (obj, value) => { obj.url = value; } }, metadata: _metadata }, _url_initializers, _instanceExtraInitializers); __esDecorate(null, null, _width_decorators, { kind: "field", name: "width", static: false, private: false, access: { has: obj => "width" in obj, get: obj => obj.width, set: (obj, value) => { obj.width = value; } }, metadata: _metadata }, _width_initializers, _instanceExtraInitializers); __esDecorate(null, null, _platforms_decorators, { kind: "field", name: "platforms", static: false, private: false, access: { has: obj => "platforms" in obj, get: obj => obj.platforms, set: (obj, value) => { obj.platforms = value; } }, metadata: _metadata }, _platforms_initializers, _instanceExtraInitializers); __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); SocialMediaShareComponent = _classThis = _classDescriptor.value; if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); __runInitializers(_classThis, _classExtraInitializers); })(); return SocialMediaShareComponent = _classThis; })(); exports.SocialMediaShareComponent = SocialMediaShareComponent;