@pactsafe/pactsafe-angular-sdk
Version:
Angular SDK for easy Clickwrap/Browsewrap implementation leveraging PactSafe's JavaScript Library
311 lines (306 loc) • 13.4 kB
JavaScript
import { ɵɵdefineComponent, ɵɵelement, ɵɵproperty, ɵsetClassMetadata, Component, Input, ɵɵelementStart, ɵɵtext, ɵɵelementEnd, ɵɵsanitizeUrl, ɵɵadvance, ɵɵtextInterpolate, ɵɵdefineNgModule, ɵɵdefineInjector, ɵɵsetNgModuleScope, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
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 = ɵɵ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) {
ɵɵelement(0, "div", 0);
} if (rf & 2) {
ɵɵproperty("id", ctx.containerName);
} }, encapsulation: 2 });
return PSClickWrapComponent;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(PSClickWrapComponent, [{
type: Component,
args: [{
selector: 'ps-click-wrap',
template: "<div [id]=\"containerName\"></div>",
styles: [ /* Add your own styles here */]
}]
}], function () { return []; }, { accessId: [{
type: Input
}], clickWrapStyle: [{
type: Input
}], containerName: [{
type: Input
}], displayImmediately: [{
type: Input
}], displayAll: [{
type: Input
}], forceScroll: [{
type: Input
}], confirmationEmail: [{
type: Input
}], disableSending: [{
type: Input
}], testMode: [{
type: Input
}], groupKey: [{
type: Input
}], filter: [{
type: Input
}], dynamic: [{
type: Input
}], renderData: [{
type: Input
}], signerIdSelector: [{
type: Input
}], signerId: [{
type: 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 = ɵɵ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) {
ɵɵelementStart(0, "a", 0);
ɵɵtext(1);
ɵɵelementEnd();
} if (rf & 2) {
ɵɵproperty("href", ctx.link, ɵɵsanitizeUrl)("id", ctx.targetSelector);
ɵɵadvance(1);
ɵɵtextInterpolate(ctx.linkText);
} }, encapsulation: 2 });
return PSBrowseWrapComponent;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(PSBrowseWrapComponent, [{
type: Component,
args: [{
selector: 'ps-browse-wrap',
template: "<a [href]=\"link\" [id]=\"targetSelector\">{{ linkText }}</a>",
styles: [ /* Add your own styles here */]
}]
}], function () { return []; }, { accessId: [{
type: Input
}], groupKey: [{
type: Input
}], linkText: [{
type: Input
}], alwaysVisible: [{
type: Input
}], badgeText: [{
type: Input
}], position: [{
type: Input
}], openLegalCenter: [{
type: Input
}], link: [{
type: Input
}] }); })();
var PSModule = /** @class */ (function () {
function PSModule() {
}
PSModule.forRoot = function () {
return {
ngModule: PSModule,
providers: []
};
};
PSModule.ɵmod = ɵɵdefineNgModule({ type: PSModule });
PSModule.ɵinj = ɵɵdefineInjector({ factory: function PSModule_Factory(t) { return new (t || PSModule)(); }, imports: [[
CommonModule
]] });
return PSModule;
}());
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵɵsetNgModuleScope(PSModule, { declarations: [PSClickWrapComponent,
PSBrowseWrapComponent], imports: [CommonModule], exports: [PSClickWrapComponent,
PSBrowseWrapComponent] }); })();
/*@__PURE__*/ (function () { ɵsetClassMetadata(PSModule, [{
type: NgModule,
args: [{
imports: [
CommonModule
],
declarations: [
PSClickWrapComponent,
PSBrowseWrapComponent
],
exports: [
PSClickWrapComponent,
PSBrowseWrapComponent
]
}]
}], null, null); })();
export { PSModule, PSClickWrapComponent, PSBrowseWrapComponent };