UNPKG

boast-init

Version:

The initialisation script for the boast product

229 lines (212 loc) 12.3 kB
/*! * boast-init v0.1.10 - https://github.com/doopoll/boast-init#readme * MIT Licensed */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["BoastInit"] = factory(); else root["BoastInit"] = factory(); })(window, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(1); /***/ }), /* 1 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); // CONCATENATED MODULE: ./src/build.js var build = function build(element, attributes, text) { var ele = document.createElement(element); if (attributes && attributes.length > 0) { attributes.forEach(function (att) { if (att.name && att.value) { ele.setAttribute(att.name, att.value); } }); } if (text) ele.innerHTML = text; return ele; }; /* harmony default export */ var src_build = (build); // CONCATENATED MODULE: ./src/index.js /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "closeFeed", function() { return closeFeed; }); var styles = '\n.nff-default-button {\n width: 80px;\n height: 80px;\n cursor: pointer;\n border-radius: 50%;\n position: fixed;\n bottom: 30px;\n right: 50px;\n background: #122a42;\n color: white;\n font-weight: bold;\n font-family: Arial;\n font-size: 22px;\n border: none;\n display: flex;\n justify-content:center;\n box-shadow: 0px 3px 15px rgba(0,0,0,0.3);\n}\n\n.nff-iframe-display-none {\n display: none;\n}\n\n.nff-iframe-display {\n display: block;\n}\n\n\n.nff-overlay {\n position: fixed;\n top: 0;\n left: 0;\n background: rgba(17, 103, 250, 0.5);\n width: 100%;\n height: 100%;\n z-index: 10000;\n animation: appear 0.1s;\n}\n\n.nff-container {\n border: none;\n position: fixed;\n right: 0;\n top: 0;\n width: 324px;\n background: transparent;\n height: 100vh;\n z-index: 10001;\n animation: appear 0.1s;\n}\n\n@media(min-width: 420px) {\n.nff-container {\n width: 400px;\n }\n}\n.gift {\n margin: auto 0;\n padding-top: 5px;\n max-width: 50px;\n}\n '; var boastApp = { openState: false, userId: document.currentScript.attributes['data-userId'].value, defaultButton: document.currentScript.attributes['data-defaultButton'] && document.currentScript.attributes['data-defaultButton'].value }; var initStyles = function initStyles() { var style = document.createElement('style'); style.innerHTML = styles; document.querySelector('head').appendChild(style); }; var closeFeed = function closeFeed(event) { try { boastApp.openState = false; var body = document.querySelector('body'); var feed = document.querySelector('.nff-container'); feed.setAttribute('class', 'nff-iframe-display-none'); body.removeChild(document.querySelector('#nff-overlay-id')); } catch (exception) { console.log(exception); } }; var src_createFeedButton = function createFeedButton() { try { var feedButton = src_build('button', [{ name: 'class', value: 'nff-default-button' }], boastApp.buttonText); var img = src_build('img', [{ name: 'class', value: 'gift' }]); img.setAttribute('src', "data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeD0iMHB4IiB5PSIwcHgiIHZp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2LjU4NSwyMTMuODU5di05LjA1OGwtOTQuNTIzLTUxLjJsLTk0LjUyMyw1MS4ydjkuMDU4TDk0LjUyNCwxODYuMjl2LTEyLjYwM2wxNTQuMzg3LTgxLjUyNiAgbDMuMTUxLDEuNTc1bDMuMTUxLTEuNTc1TDQwOS42LDE3My4yOTN2MTIuNjAzTDM0Ni41ODUsMjEzLjg1OXoiLz4KPHBhdGggc3R5bGU9ImZpbGw6I0RDRENEQzsiIGQ9Ik0zNDYuNTg1LDIwNC44MDF2MjUxLjY2OGw2My4wMTUtMzEuNTA4VjE3My4yOTNMMzQ2LjU4NSwyMDQuODAxeiIvPgo8cGF0aCBzdHlsZT0iZmlsbDojRDFEMUQxOyIgZD0iTTk0LjUyMyw0MjUuMzU0bDYzLjAxNSwzMS41MDhWMjA1LjE5NWwtNjMuMDE1LTMxLjkwMkM5NC41MjMsMTczLjI5Miw5NC41MjMsNDI1LjM1NCw5NC41MjMsNDI1LjM1NCAgeiIvPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K"); feedButton.append(img); document.body.appendChild(feedButton); return [feedButton]; } catch (exception) { console.log(exception); } }; var src_showNewFeatureFeed = function showNewFeatureFeed(userId, origin, feed) { try { if (boastApp.openState === false) { var overlay = src_build('div', [{ name: 'class', value: 'nff-overlay' }, { name: 'id', value: 'nff-overlay-id' }]); overlay.addEventListener('click', closeFeed); var body = document.querySelector('body'); body.append(overlay); feed.setAttribute('class', 'nff-container'); boastApp.openState = true; } else { closeFeed(); } } catch (exception) { console.log(exception); } }; (function initFeed() { try { var userId = boastApp.userId, defaultButton = boastApp.defaultButton; window.addEventListener('message', function (e) { if (e.origin === 'https://getboast.co') { var task = e.data['task']; if (task = 'close') closeFeed(); } }); var feedButtons = document.getElementsByClassName('boast-button-init'); feedButtons = Array.from(feedButtons); console.log(feedButtons); initStyles(); if (!userId) throw new Error('Make sure a userId is included in the snippet'); if (defaultButton) { feedButtons = src_createFeedButton(userId); } var _origin = window.location.origin; var feedContainer = src_build('iframe', [{ name: 'class', value: 'nff-iframe-display-none' }, { name: 'id', value: 'nff-container-id' }, { name: 'src', value: 'https://getboast.co/feed/' + userId + '?origin=' + _origin }]); feedContainer.addEventListener('click', function (event) { return event.stopPropagation(); }); document.body.append(feedContainer); var _origin = window.location.href; feedButtons.forEach(function (button) { button.addEventListener('click', function () { src_showNewFeatureFeed(userId, _origin, feedContainer); }); }); } catch (exception) { console.log(exception); } })(); /***/ }) /******/ ])["default"]; });