var Formoid = (function () { var API_URL = 'https://formoid.net/api/push'; function $ajax(url, settings) { return new Promise(function (resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open(settings.type, url); xhr.onload = function () { if (xhr.status !== 200) { return reject(new Error('Incorrect server response.')); } resolve(xhr.responseText); }; xhr.onerror = function () { var message = 'Failed to query the server. '; if ('onLine' in navigator && !navigator.onLine) { message += 'No connection to the Internet.'; } else { message += 'Check the connection and try again.'; } reject(new Error(message)); }; xhr.send(settings.data); }) }; var prop = function (name, args) { name = '__' + name + '__'; if (args.length) { this[name] = args[0]; return this; } return this[name]; }; var Form = function (settings) { settings = settings || {}; this.__email__ = settings.email || ''; this.__title__ = settings.title || ''; this.__data__ = settings.data || []; }; Form.prototype.email = function (value) { return prop.call(this, 'email', arguments); }; Form.prototype.title = function (value) { return prop.call(this, 'title', arguments); }; Form.prototype.data = function (value) { return prop.call(this, 'data', arguments); }; Form.prototype.send = function (data) { return $ajax(API_URL, { type: 'POST', data: JSON.stringify({ email: this.__email__, form: { title: this.__title__, data: (arguments.length ? data : this.__data__) } }) }) .then(function(responseText) { var data; try { data = JSON.parse(responseText); } catch (e) { throw new Error('Incorrect server response.'); } if (data.error) { throw new Error(data.error); } return data.response; }); }; return { Form: function (settings) { return new Form(settings); } } })(); const formModalDOM = document.createElement('div'); let formModal; formModalDOM.classList.add('modal'); formModalDOM.setAttribute('tabindex', -1); formModalDOM.style.overflow = 'hidden'; if (typeof bootstrap !== 'undefined') { if (bootstrap.Tooltip.VERSION.startsWith(5)) { //bs5 formModalDOM.innerHTML = `