UNPKG

pactsafe-angular-sdk

Version:

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

315 lines (310 loc) 11.3 kB
import { Component, Input, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; /***** * 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: Component, args: [{ selector: 'ps-click-wrap', template: "<div [id]=\"containerName\"></div>", styles: [] },] }, ]; /** * @nocollapse */ PSClickWrapComponent.ctorParameters = function () { return []; }; PSClickWrapComponent.propDecorators = { '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 },], }; /***** * 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: Component, args: [{ selector: 'ps-browse-wrap', template: "<a [href]=\"link\" [id]=\"targetSelector\">{{ linkText }}</a>", styles: [] },] }, ]; /** * @nocollapse */ PSBrowseWrapComponent.ctorParameters = function () { return []; }; PSBrowseWrapComponent.propDecorators = { '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 = (function () { function PSModule() { } /** * @return {?} */ PSModule.forRoot = function () { return { ngModule: PSModule, providers: [] }; }; return PSModule; }()); PSModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [ PSClickWrapComponent, PSBrowseWrapComponent ], exports: [ PSClickWrapComponent, PSBrowseWrapComponent ] },] }, ]; /** * @nocollapse */ PSModule.ctorParameters = function () { return []; }; export { PSModule, PSClickWrapComponent, PSBrowseWrapComponent };