(function(module, exports, __webpack_require__) {
"use strict";
var _run = __webpack_require__(1);
var _run2 = _interopRequireDefault(_run);
var _url_utils = __webpack_require__(2);
var _phone = __webpack_require__(3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
(0, _run2.default)(function () {
var validParamKeys = {
phone: 'phone',
text: 'text',
source: 'source',
data: 'data'
};
var qp = pruneQueryParams((0, _url_utils.parseQueryParams)(document.location.href), validParamKeys);
var baseUrl = encodeURI('whatsapp://send');
var fallbackBaseUrl = encodeURI('https://web.whatsapp.com/send');
// Validate phone and generate formatted
var formattedPhone = void 0;
if (qp.phone && /^[0-9]+$/g.test(qp.phone)) {
formattedPhone = (0, _phone.format)(qp.phone);
} else {
delete qp.phone;
}
// Update text text content
var shareTitle = document.querySelector('#action-title');
if (qp.text) {
var textBlock = document.querySelector('#text-block');
textBlock.textContent = qp.text;
if (qp.phone) {
shareTitle.textContent = "Send the following to __NUMBER__ on WhatsApp";
shareTitle.innerHTML = shareTitle.innerHTML.replace('__NUMBER__', '<span dir="ltr">' + formattedPhone + '</span>');
} else {
shareTitle.textContent = "Send the following on WhatsApp";
}
} else {
var textPreview = document.querySelector('#text-preview');
textPreview.parentNode.removeChild(textPreview);
if (qp.phone) {
var shareButton = document.querySelector('#action-button');
shareButton.textContent = "Message";
shareTitle.textContent = "Message __NUMBER__ on WhatsApp";
shareTitle.innerHTML = shareTitle.innerHTML.replace('__NUMBER__', '<span dir="ltr">' + formattedPhone + '</span>');
} else {
var actionButtonContainer = document.querySelector('#action-button-container');
actionButtonContainer.parentNode.removeChild(actionButtonContainer);
shareTitle.textContent = "This link is incorrect. Close this window and try a different link.";
}
}
var paramString = (0, _url_utils.encodeQueryParams)(qp);
if (!paramString) return;
var url = baseUrl + '?' + paramString;
var desktopFallbackUrl = fallbackBaseUrl + '?' + paramString;
var mobileFallbackUrl = "https://www.whatsapp.com/download/";
// Attempt to open wa uri, without fallback
open(url);
// Update the different language pages to contain the same query params
updateLocSelectors(paramString);
// Open url with fallbacks on click
var actionButton = document.querySelector('#action-button');
actionButton.addEventListener('click', function (e) {
e.stopPropagation();
open(url, desktopFallbackUrl, mobileFallbackUrl);
});
// TODO: Feature detection vs UA detection. This seems incorrect.
var UA = navigator.userAgent;
if (UA.indexOf('Android') > -1 && UA.indexOf('Mozilla/5.0') > -1 && UA.indexOf('AppleWebKit') > -1 && UA.indexOf('Chrome') > -1) {
document.querySelector('html').classList.add('browser-chrome-android');
}
});
function pruneQueryParams(params, validKeys) {
var newParams = {};
for (var key in params) {
if (validKeys[key]) newParams[key] = params[key];
}
return newParams;
}
function updateLocSelectors(paramString) {
var locSelectors = document.querySelectorAll('.lng-link[data-lng]');
var node = void 0;
for (var i = 0; i < locSelectors.length; i++) {
node = locSelectors[i];
node.setAttribute('href', node.getAttribute('href') + '&' + paramString);
}
}
function open(url, desktopFallback, mobileFallback) {
// can be: 'desktop' | 'phone' | 'script' | 'tablet' | 'unknown'
var agentType = 'desktop';
switch (agentType) {
case 'desktop':
(0, _url_utils.openUrlWithFallback)(url, desktopFallback);
break;
case 'phone':
case 'tablet':
(0, _url_utils.openUrlWithFallback)(url, mobileFallback);
break;
}
}
/***/ }),
/* 1 */