UNPKG

@pactsafe/pactsafe-angular-sdk

Version:

Angular SDK for easy Clickwrap/Browsewrap implementation leveraging PactSafe's JavaScript Library

320 lines (313 loc) 15 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) : typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common'], factory) : (global = global || self, factory(global['pactsafe-angular-sdk'] = {}, global.i0, global.common)); }(this, function (exports, i0, common) { 'use strict'; var PSClickWrapComponent = /** @class */ (function () { function PSClickWrapComponent() { // ABSOLUTELY REQUIRED this.accessId = null; // OVERWRITE INPUTS/CAN BE PULLED FROM PS this.clickWrapStyle = 'full'; this.containerName = 'ps-clickwrap'; this.displayImmediately = true; this.displayAll = true; this.forceScroll = false; this.confirmationEmail = false; this.disableSending = false; this.testMode = false; // CONDITIONAL INPUTS this.groupKey = null; this.filter = null; this.dynamic = false; this.renderData = null; this.signerIdSelector = null; this.signerId = null; this.createOptions = {}; this.loadOptions = {}; // Invoke snippet, if it's not already created if (window['_ps'] == null || window['_ps'] == undefined) { (function (w, d, s, c, n, a, b) { w['PactSafeObject'] = n; w[n] = w[n] || function () { (w[n].q = w[n].q || []).push(arguments); }, w[n].on = function () { (w[n].e = w[n].e || []).push(arguments); }, w[n].once = function () { (w[n].eo = w[n].eo || []).push(arguments); }, w[n].off = function () { (w[n].o = w[n].o || []).push(arguments); }, w[n].t = (new Date()).getDate(); a = d.createElement(s); b = d.getElementsByTagName(s)[0]; a.async = 1; a.src = c; b.parentNode.insertBefore(a, b); })(window, document, 'script', '//vault.pactsafe.io/ps.min.js', '_ps'); } } PSClickWrapComponent.prototype.ngOnInit = function () { // Make sure required input has been provided if (this.accessId == null) { throw new Error('Attribute "accessId" is required'); } // Validation and assignment for conditional input // IF GROUPKEY -> NO FILTER : IF FILTER -> NO GROUPKEY if ((this.groupKey == null && this.filter == null) || (this.groupKey != null && this.filter != null)) { throw new Error('Either "groupKey" or "filter" is required in clickwrap attributes'); } else { if (this.groupKey == null) { this.loadOptions['filter'] = this.filter; } else { this.loadOptions['groupKey'] = this.groupKey; this.loadOptions['event_callback'] = function (err, group) { try { group.render(true); } catch (e) { throw new Error('Unable to re-render clickwrap'); } }; } } // IF DYNAMIC -> RENDER DATA != NULL if (this.dynamic && this.renderData == null) { throw new Error('If "dynamic" attribute is set, then "renderData" is required'); } // IF SIGNERIDSELECTOR -> NO SIGNERID : IF SIGNER ID -> NO SIGNERIDSELECTOR if ((this.signerIdSelector == null && this.signerId == null) || (this.signerIdSelector != null && this.signerId != null)) { throw new Error('Either "signerIdSelector" or "signerId" is required in clickwrap attributes'); } else { if (this.signerIdSelector == null) { this.createOptions['signer_id'] = this.signerId; } else { this.loadOptions['signer_id_selector'] = this.signerIdSelector; } } // Set up the ClickWrap options based on input Object.assign(this.createOptions, { testMode: this.testMode, disable_sending: this.disableSending, dynamic: this.dynamic }); Object.assign(this.loadOptions, { container_selector: this.containerName, style: this.clickWrapStyle, display_all: this.displayAll, render_data: this.renderData, auto_run: this.displayImmediately, force_scroll: this.forceScroll, confirmation_email: this.confirmationEmail }); }; PSClickWrapComponent.prototype.ngAfterViewInit = function () { // With everything initialized, create and load in the clickwrap _ps('create', this.accessId, this.createOptions); if (this.groupKey) { _ps('load', this.groupKey, this.loadOptions); } else { _ps('load', this.loadOptions); } }; PSClickWrapComponent.prototype.ngOnDestroy = function () { // Let _ps know that the group is not showing _ps.getByKey(this.groupKey).rendered = false; }; PSClickWrapComponent.ɵfac = function PSClickWrapComponent_Factory(t) { return new (t || PSClickWrapComponent)(); }; PSClickWrapComponent.ɵcmp = i0.ɵɵdefineComponent({ type: PSClickWrapComponent, selectors: [["ps-click-wrap"]], inputs: { accessId: "accessId", clickWrapStyle: "clickWrapStyle", containerName: "containerName", displayImmediately: "displayImmediately", displayAll: "displayAll", forceScroll: "forceScroll", confirmationEmail: "confirmationEmail", disableSending: "disableSending", testMode: "testMode", groupKey: "groupKey", filter: "filter", dynamic: "dynamic", renderData: "renderData", signerIdSelector: "signerIdSelector", signerId: "signerId" }, decls: 1, vars: 1, consts: [[3, "id"]], template: function PSClickWrapComponent_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelement(0, "div", 0); } if (rf & 2) { i0.ɵɵproperty("id", ctx.containerName); } }, encapsulation: 2 }); return PSClickWrapComponent; }()); /*@__PURE__*/ (function () { i0.ɵsetClassMetadata(PSClickWrapComponent, [{ type: i0.Component, args: [{ selector: 'ps-click-wrap', template: "<div [id]=\"containerName\"></div>", styles: [ /* Add your own styles here */] }] }], function () { return []; }, { accessId: [{ type: i0.Input }], clickWrapStyle: [{ type: i0.Input }], containerName: [{ type: i0.Input }], displayImmediately: [{ type: i0.Input }], displayAll: [{ type: i0.Input }], forceScroll: [{ type: i0.Input }], confirmationEmail: [{ type: i0.Input }], disableSending: [{ type: i0.Input }], testMode: [{ type: i0.Input }], groupKey: [{ type: i0.Input }], filter: [{ type: i0.Input }], dynamic: [{ type: i0.Input }], renderData: [{ type: i0.Input }], signerIdSelector: [{ type: i0.Input }], signerId: [{ type: i0.Input }] }); })(); var PSBrowseWrapComponent = /** @class */ (function () { function PSBrowseWrapComponent() { // ABSOLUTELY REQUIRED this.accessId = null; this.groupKey = null; this.linkText = null; // OVERWRITE INPUTS/CAN BE PULLED FROM PS this.alwaysVisible = false; this.badgeText = this.linkText; this.position = 'auto'; // CONDITIONAL INPUTS this.openLegalCenter = true; this.link = null; this.targetSelector = 'psbw-'; this.createOptions = {}; this.loadOptions = {}; // Invoke snippet, if it's not already created if (window['_ps'] == null || window['_ps'] == undefined) { (function (w, d, s, c, n, a, b) { w['PactSafeObject'] = n; w[n] = w[n] || function () { (w[n].q = w[n].q || []).push(arguments); }, w[n].on = function () { (w[n].e = w[n].e || []).push(arguments); }, w[n].once = function () { (w[n].eo = w[n].eo || []).push(arguments); }, w[n].off = function () { (w[n].o = w[n].o || []).push(arguments); }, w[n].t = (new Date()).getDate(); a = d.createElement(s); b = d.getElementsByTagName(s)[0]; a.async = 1; a.src = c; b.parentNode.insertBefore(a, b); })(window, document, 'script', '//vault.pactsafe.io/ps.min.js', '_ps'); } } PSBrowseWrapComponent.prototype.ngOnInit = function () { // Make sure required input has been provided if (this.accessId == null) { throw new Error('Attribute "accessId" is required'); } else if (this.groupKey == null) { throw new Error('Attribute "groupKey" is required'); } else if (this.linkText == null) { throw new Error('Attribute "linkText" is required'); } this.targetSelector = 'psbw-' + this.groupKey; // Validation and assignment for conditional input // IF OPENLEGALCENTER == FALSE -> LINK if (!this.openLegalCenter && this.link == null) { throw new Error('If "openLegalCenter" is false, then "link" is required'); } // Set up the BrowseWrap options based on input Object.assign(this.loadOptions, { target_selector: this.targetSelector, position: this.position, badge_text: this.badgeText, always_visible: this.alwaysVisible, open_legal_center: this.openLegalCenter }); }; PSBrowseWrapComponent.prototype.ngAfterViewInit = function () { // With everything initialized, create and load in the BrowseWrap _ps('create', this.accessId, this.createOptions); _ps('load', this.groupKey, this.loadOptions); }; PSBrowseWrapComponent.prototype.ngOnDestroy = function () { // Let _ps know that the group is not showing _ps.getByKey(this.groupKey).rendered = false; }; PSBrowseWrapComponent.ɵfac = function PSBrowseWrapComponent_Factory(t) { return new (t || PSBrowseWrapComponent)(); }; PSBrowseWrapComponent.ɵcmp = i0.ɵɵdefineComponent({ type: PSBrowseWrapComponent, selectors: [["ps-browse-wrap"]], inputs: { accessId: "accessId", groupKey: "groupKey", linkText: "linkText", alwaysVisible: "alwaysVisible", badgeText: "badgeText", position: "position", openLegalCenter: "openLegalCenter", link: "link" }, decls: 2, vars: 3, consts: [[3, "href", "id"]], template: function PSBrowseWrapComponent_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "a", 0); i0.ɵɵtext(1); i0.ɵɵelementEnd(); } if (rf & 2) { i0.ɵɵproperty("href", ctx.link, i0.ɵɵsanitizeUrl)("id", ctx.targetSelector); i0.ɵɵadvance(1); i0.ɵɵtextInterpolate(ctx.linkText); } }, encapsulation: 2 }); return PSBrowseWrapComponent; }()); /*@__PURE__*/ (function () { i0.ɵsetClassMetadata(PSBrowseWrapComponent, [{ type: i0.Component, args: [{ selector: 'ps-browse-wrap', template: "<a [href]=\"link\" [id]=\"targetSelector\">{{ linkText }}</a>", styles: [ /* Add your own styles here */] }] }], function () { return []; }, { accessId: [{ type: i0.Input }], groupKey: [{ type: i0.Input }], linkText: [{ type: i0.Input }], alwaysVisible: [{ type: i0.Input }], badgeText: [{ type: i0.Input }], position: [{ type: i0.Input }], openLegalCenter: [{ type: i0.Input }], link: [{ type: i0.Input }] }); })(); var PSModule = /** @class */ (function () { function PSModule() { } PSModule.forRoot = function () { return { ngModule: PSModule, providers: [] }; }; PSModule.ɵmod = i0.ɵɵdefineNgModule({ type: PSModule }); PSModule.ɵinj = i0.ɵɵdefineInjector({ factory: function PSModule_Factory(t) { return new (t || PSModule)(); }, imports: [[ common.CommonModule ]] }); return PSModule; }()); (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(PSModule, { declarations: [PSClickWrapComponent, PSBrowseWrapComponent], imports: [common.CommonModule], exports: [PSClickWrapComponent, PSBrowseWrapComponent] }); })(); /*@__PURE__*/ (function () { i0.ɵsetClassMetadata(PSModule, [{ type: i0.NgModule, args: [{ imports: [ common.CommonModule ], declarations: [ PSClickWrapComponent, PSBrowseWrapComponent ], exports: [ PSClickWrapComponent, PSBrowseWrapComponent ] }] }], null, null); })(); exports.PSModule = PSModule; exports.PSClickWrapComponent = PSClickWrapComponent; exports.PSBrowseWrapComponent = PSBrowseWrapComponent; Object.defineProperty(exports, '__esModule', { value: true }); }));