docbrown/app/assets/javascripts/initializers/initializePWAFunctionality.js
Nick Taylor 39618f66a2 Fixed some more Frontend Lint Issues (#3792)
* Removed a file that is not used.

* Fixed some lint issues

* Fixed some more lint issues
2019-08-23 10:21:28 -04:00

38 lines
1.3 KiB
JavaScript

'use strict';
function initializePWAFunctionality() {
if (window.matchMedia('(display-mode: standalone)').matches) {
document
.getElementById('pwa-nav-buttons')
.classList.add('pwa-nav-buttons--showing');
document.getElementById('app-back-button').onclick = e => {
e.preventDefault();
window.history.back();
};
document.getElementById('app-forward-button').onclick = e => {
e.preventDefault();
window.history.forward();
};
document.getElementById('app-refresh-button').onclick = e => {
e.preventDefault();
window.location.reload();
};
var isTouchDevice = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|DEV-Native-ios/i.test(
navigator.userAgent,
);
if (!isTouchDevice) {
var domain = window.location.protocol + '//' + window.location.host;
var links = document.getElementsByTagName('a');
// eslint-disable-next-line no-plusplus
for (var i = 0, max = links.length; i < max; i++) {
var a = links[i];
if (a.href.indexOf(domain + '/') === 0 || a.href.indexOf('/') === 0) {
// Is internal link. Do nothing right now.
} else {
a.setAttribute('target', '_blank');
a.setAttribute('rel', 'noopener noreferrer');
}
}
}
}
}