pactsafe-angular-sdk
Version:
Angular SDK for easy Clickwrap/Browsewrap implementation leveraging PactSafe's JavaScript Library
324 lines (317 loc) • 12.2 kB
JavaScript
(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) :
(factory((global['pactsafe-angular-sdk'] = global['pactsafe-angular-sdk'] || {}),global._angular_core,global._angular_common));
}(this, (function (exports,_angular_core,_angular_common) { 'use strict';
/*****
* Click-wrap component
* Easily plug into your existing angular project to get the functionality of our JavaScript library
* Consult the readme for a more in-depth description
*
* Author: Justin Willoughby
* 6/14/2017
*/
var PSClickWrapComponent = (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');
}
}
/**
* @return {?}
*/
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
});
};
/**
* @return {?}
*/
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);
}
};
/**
* @return {?}
*/
PSClickWrapComponent.prototype.ngOnDestroy = function () {
// Let _ps know that the group is not showing
_ps.getByKey(this.groupKey).rendered = false;
};
return PSClickWrapComponent;
}());
PSClickWrapComponent.decorators = [
{ type: _angular_core.Component, args: [{
selector: 'ps-click-wrap',
template: "<div [id]=\"containerName\"></div>",
styles: []
},] },
];
/**
* @nocollapse
*/
PSClickWrapComponent.ctorParameters = function () { return []; };
PSClickWrapComponent.propDecorators = {
'accessId': [{ type: _angular_core.Input },],
'clickWrapStyle': [{ type: _angular_core.Input },],
'containerName': [{ type: _angular_core.Input },],
'displayImmediately': [{ type: _angular_core.Input },],
'displayAll': [{ type: _angular_core.Input },],
'forceScroll': [{ type: _angular_core.Input },],
'confirmationEmail': [{ type: _angular_core.Input },],
'disableSending': [{ type: _angular_core.Input },],
'testMode': [{ type: _angular_core.Input },],
'groupKey': [{ type: _angular_core.Input },],
'filter': [{ type: _angular_core.Input },],
'dynamic': [{ type: _angular_core.Input },],
'renderData': [{ type: _angular_core.Input },],
'signerIdSelector': [{ type: _angular_core.Input },],
'signerId': [{ type: _angular_core.Input },],
};
/*****
* Browse-wrap component
* Easily plug into your existing angular project to get the functionality of our JavaScript library
* Consult the readme for a more in-depth description
*
* Author: Justin Willoughby
* 6/14/2017
*/
var PSBrowseWrapComponent = (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');
}
}
/**
* @return {?}
*/
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
});
};
/**
* @return {?}
*/
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);
};
/**
* @return {?}
*/
PSBrowseWrapComponent.prototype.ngOnDestroy = function () {
// Let _ps know that the group is not showing
_ps.getByKey(this.groupKey).rendered = false;
};
return PSBrowseWrapComponent;
}());
PSBrowseWrapComponent.decorators = [
{ type: _angular_core.Component, args: [{
selector: 'ps-browse-wrap',
template: "<a [href]=\"link\" [id]=\"targetSelector\">{{ linkText }}</a>",
styles: []
},] },
];
/**
* @nocollapse
*/
PSBrowseWrapComponent.ctorParameters = function () { return []; };
PSBrowseWrapComponent.propDecorators = {
'accessId': [{ type: _angular_core.Input },],
'groupKey': [{ type: _angular_core.Input },],
'linkText': [{ type: _angular_core.Input },],
'alwaysVisible': [{ type: _angular_core.Input },],
'badgeText': [{ type: _angular_core.Input },],
'position': [{ type: _angular_core.Input },],
'openLegalCenter': [{ type: _angular_core.Input },],
'link': [{ type: _angular_core.Input },],
};
var PSModule = (function () {
function PSModule() {
}
/**
* @return {?}
*/
PSModule.forRoot = function () {
return {
ngModule: PSModule,
providers: []
};
};
return PSModule;
}());
PSModule.decorators = [
{ type: _angular_core.NgModule, args: [{
imports: [
_angular_common.CommonModule
],
declarations: [
PSClickWrapComponent,
PSBrowseWrapComponent
],
exports: [
PSClickWrapComponent,
PSBrowseWrapComponent
]
},] },
];
/**
* @nocollapse
*/
PSModule.ctorParameters = function () { return []; };
exports.PSModule = PSModule;
exports.PSClickWrapComponent = PSClickWrapComponent;
exports.PSBrowseWrapComponent = PSBrowseWrapComponent;
Object.defineProperty(exports, '__esModule', { value: true });
})));