1 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
2 |
|
3 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
4 |
|
5 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
6 |
|
7 |
|
8 | import React from 'react';
|
9 | import PropTypes from 'prop-types';
|
10 | import isRequiredIf from 'react-proptype-conditional-require';
|
11 | import PSSnippet from './PSSnippet';
|
12 |
|
13 | var PSBrowseWrap = function (_React$Component) {
|
14 | _inherits(PSBrowseWrap, _React$Component);
|
15 |
|
16 | function PSBrowseWrap(props) {
|
17 | _classCallCheck(this, PSBrowseWrap);
|
18 |
|
19 | var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
|
20 |
|
21 | var _this$props = _this.props,
|
22 | psScriptUrl = _this$props.psScriptUrl,
|
23 | groupKey = _this$props.groupKey,
|
24 | accessId = _this$props.accessId;
|
25 |
|
26 | if (!PSSnippet.isSnippetLoaded(psScriptUrl)) {
|
27 | PSSnippet.injectSnippet(psScriptUrl);
|
28 | }
|
29 | _this.targetSelector = 'psbw-' + groupKey;
|
30 | _ps('create', accessId);
|
31 | return _this;
|
32 | }
|
33 |
|
34 | PSBrowseWrap.prototype.componentDidMount = function componentDidMount() {
|
35 | var _props = this.props,
|
36 | groupKey = _props.groupKey,
|
37 | position = _props.position,
|
38 | badgeText = _props.badgeText,
|
39 | alwaysVisible = _props.alwaysVisible,
|
40 | openLegalCenter = _props.openLegalCenter;
|
41 |
|
42 | _ps('load', groupKey, {
|
43 | target_selector: this.targetSelector,
|
44 | position: position,
|
45 | badge_text: badgeText,
|
46 | always_visible: alwaysVisible,
|
47 | open_legal_center: openLegalCenter
|
48 | });
|
49 | };
|
50 |
|
51 | PSBrowseWrap.prototype.componentWillUnmount = function componentWillUnmount() {
|
52 | var groupKey = this.props.groupKey;
|
53 |
|
54 | _ps.getByKey(groupKey).rendered = false;
|
55 | };
|
56 |
|
57 | PSBrowseWrap.prototype.isSnippetLoaded = function isSnippetLoaded() {
|
58 | var psScriptUrl = this.props.psScriptUrl;
|
59 |
|
60 | var scripts = document.getElementsByTagName('script');
|
61 | for (var i = 0; i < scripts.length; i += 1) {
|
62 | if (scripts[i].src.indexOf(psScriptUrl) !== -1) return true;
|
63 | }
|
64 | return false;
|
65 | };
|
66 |
|
67 | PSBrowseWrap.prototype.render = function render() {
|
68 | var _props2 = this.props,
|
69 | link = _props2.link,
|
70 | linkText = _props2.linkText;
|
71 |
|
72 | return React.createElement(
|
73 | 'a',
|
74 | { href: link, id: this.targetSelector },
|
75 | linkText
|
76 | );
|
77 | };
|
78 |
|
79 | return PSBrowseWrap;
|
80 | }(React.Component);
|
81 |
|
82 | PSBrowseWrap.MUST_PROVIDE_LINK_IF_OPEN_LEGAL_CENTER_FALSE = 'PSBrowseWrap Error: You must provide a link prop if openLegalCenter is passed false';
|
83 |
|
84 | PSBrowseWrap.propTypes = process.env.NODE_ENV !== "production" ? {
|
85 | accessId: PropTypes.string.isRequired,
|
86 | alwaysVisible: PropTypes.bool,
|
87 | badgeText: PropTypes.string,
|
88 | groupKey: PropTypes.string.isRequired,
|
89 | link: isRequiredIf(PropTypes.string, function (props) {
|
90 | return props.hasOwnProperty('openLegalCenter') && props.openLegalCenter === false;
|
91 | }, PSBrowseWrap.MUST_PROVIDE_LINK_IF_OPEN_LEGAL_CENTER_FALSE),
|
92 | linkText: PropTypes.string.isRequired,
|
93 | openLegalCenter: PropTypes.bool,
|
94 | position: PropTypes.oneOf(['middle', 'left', 'right', 'auto']),
|
95 | psScriptUrl: PropTypes.string
|
96 | } : {};
|
97 |
|
98 | PSBrowseWrap.defaultProps = {
|
99 | psScriptUrl: '//vault.pactsafe.io/ps.min.js',
|
100 | position: 'auto',
|
101 | link: '#',
|
102 | openLegalCenter: true
|
103 | };
|
104 |
|
105 | export default PSBrowseWrap; |
\ | No newline at end of file |