UNPKG

@mopinion/survey

Version:

Collect customer feedback with the Mopinion survey library

89 lines (88 loc) 6.37 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = LandingPage; var _preact = require("preact"); var _hooks = require("preact/hooks"); var _components = require("../../../components"); var _utils = require("../../../utils"); var _ConfigStore = require("../stores/ConfigStore"); var _FormStore = require("../stores/FormStore"); function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var LandingPageIframe = function (_Component) { function LandingPageIframe() { _classCallCheck(this, LandingPageIframe); return _callSuper(this, LandingPageIframe, arguments); } _inherits(LandingPageIframe, _Component); return _createClass(LandingPageIframe, [{ key: "shouldComponentUpdate", value: function shouldComponentUpdate() { return false; } }, { key: "render", value: function render(props) { return (0, _preact.h)("iframe", props); } }]); }(_preact.Component); function LandingPage() { var _advanced$landingspag; var _useFormProps = (0, _ConfigStore.useFormProps)(), formKey = _useFormProps.formKey; var advanced = (0, _ConfigStore.useAdvanced)(); var _useFormStore = (0, _FormStore.useFormStore)(), hideLandingPageForm = _useFormStore.hideLandingPageForm, actions = _useFormStore.actions; var publicSrvBody = document.querySelector('#publicSurveyBody') ? '#publicSurveyBody' : 'body'; var iframeURL = (0, _utils.getStrParam)('mail_url', (0, _utils.getPageUrl)()) || (0, _utils.getStrParam)('mail_url', (0, _utils.getCookie)(formKey)) || advanced.landingspageUrl || ''; var theme = (_advanced$landingspag = advanced.landingspageTheme) !== null && _advanced$landingspag !== void 0 ? _advanced$landingspag : 'dark'; (0, _hooks.useEffect)(function () { if (iframeURL) { (0, _utils.addClass)([document.querySelector(publicSrvBody)], 'customBackground'); (0, _utils.addClass)([document.querySelector(publicSrvBody)], theme); if (advanced.landingspageTransparency) { (0, _utils.addClass)([document.querySelector(publicSrvBody)], 'transparent'); } } }, [advanced.landingspageTransparency, iframeURL, theme, publicSrvBody]); if (!advanced.enableCustomBackground || !iframeURL.match(/^(?:(?:https?):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.​\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[​6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1​,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00​a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u​00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/gi)) { return null; } return (0, _preact.h)(_components.Portal, { into: document.querySelector(publicSrvBody) }, (0, _preact.h)("div", null, (0, _preact.h)(LandingPageIframe, { src: iframeURL, id: "mailUrl", className: "bg__mailing_Iframe", style: hideLandingPageForm ? { zIndex: 1 } : {} }), !hideLandingPageForm && (0, _preact.h)("button", { type: "button", className: "close_custom_bg ".concat(theme), onClick: function onClick() { actions.dispatch({ type: 'set_hide_landingspage_form' }); (0, _utils.removeClass)([document.querySelector(publicSrvBody)], theme); } }, advanced.landingspageClose && (0, _preact.h)("span", { className: "close_custom_bg_lbl ".concat(theme) }, advanced.landingspageClose)))); } //# sourceMappingURL=LandingPage.js.map