only _blank links while downloading. fixed safari link after download

This commit is contained in:
Danny Coates 2017-08-05 09:40:57 -07:00
parent 432a39d313
commit 859554ce21
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
8 changed files with 74 additions and 60 deletions

View file

@ -1,5 +1,4 @@
const testPilotGA = require('testpilot-ga');
const { sendEvent } = require('./utils');
const Raven = require('raven-js');
if (navigator.doNotTrack !== '1' && window.RAVEN_CONFIG) {
@ -12,6 +11,37 @@ const analytics = new testPilotGA({
tid: window.GOOGLE_ANALYTICS_ID
});
function sendEvent() {
return analytics.sendEvent
.apply(analytics, arguments)
.catch(() => 0);
}
function findMetric(href) {
switch (href) {
case 'https://www.mozilla.org/':
return 'mozilla';
case 'https://www.mozilla.org/about/legal':
return 'legal';
case 'https://testpilot.firefox.com/about':
return 'about';
case 'https://testpilot.firefox.com/privacy':
return 'privacy';
case 'https://testpilot.firefox.com/terms':
return 'terms';
case 'https://www.mozilla.org/privacy/websites/#cookies':
return 'cookies';
case 'https://github.com/mozilla/send':
return 'github';
case 'https://twitter.com/FxTestPilot':
return 'twitter';
case 'https://www.mozilla.org/firefox/new/?scene=2':
return 'download-firefox';
default:
return 'other';
}
}
const ua = navigator.userAgent.toLowerCase();
if (
ua.indexOf('firefox') > -1 &&
@ -26,5 +56,8 @@ if (
});
}
window.analytics = analytics;
window.Raven = Raven;
module.exports = {
Raven,
sendEvent,
findMetric
}

View file

@ -1,20 +1,17 @@
require('./common');
const { Raven, findMetric, sendEvent } = require('./common');
const FileReceiver = require('./fileReceiver');
const { notify, findMetric, sendEvent, gcmCompliant } = require('./utils');
const { notify, gcmCompliant } = require('./utils');
const bytes = require('bytes');
const Storage = require('./storage');
const storage = new Storage(localStorage);
const links = require('./links');
const $ = require('jquery');
require('jquery-circle-progress');
const Raven = window.Raven;
$(document).ready(function() {
gcmCompliant()
.then(function() {
//link back to homepage
$('.send-new').attr('href', window.location.origin);
$('.send-new').click(function() {
sendEvent('recipient', 'restarted', {
@ -46,7 +43,8 @@ $(document).ready(function() {
function download() {
// Disable the download button to avoid accidental double clicks.
$('#download-btn').attr('disabled', 'disabled');
links.setOpenInNewTab(true);
storage.totalDownloads += 1;
const fileReceiver = new FileReceiver();
@ -181,7 +179,8 @@ $(document).ready(function() {
.catch(err => {
Raven.captureException(err);
return Promise.reject(err);
});
})
.then(() => links.setOpenInNewTab(false));
}
})
.catch(err => {

19
frontend/src/links.js Normal file
View file

@ -0,0 +1,19 @@
let links = []
document.addEventListener('DOMContentLoaded', function () {
links = document.querySelectorAll('a:not([target])')
})
function setOpenInNewTab(bool) {
if (bool === false) {
links.forEach(l => l.removeAttribute('target'));
}
else {
links.forEach(l => l.setAttribute('target', '_blank'));
}
}
module.exports = {
setOpenInNewTab
}

View file

@ -1,12 +1,10 @@
/* global MAXFILESIZE EXPIRE_SECONDS */
require('./common');
const { Raven, findMetric, sendEvent } = require('./common');
const FileSender = require('./fileSender');
const {
copyToClipboard,
notify,
gcmCompliant,
findMetric,
sendEvent,
ONE_DAY_IN_MS
} = require('./utils');
const bytes = require('bytes');
@ -16,8 +14,6 @@ const storage = new Storage(localStorage);
const $ = require('jquery');
require('jquery-circle-progress');
const Raven = window.Raven;
if (storage.has('referrer')) {
window.referrer = storage.referrer;
storage.remove('referrer');

View file

@ -79,41 +79,10 @@ function gcmCompliant() {
}
}
function findMetric(href) {
switch (href) {
case 'https://www.mozilla.org/':
return 'mozilla';
case 'https://www.mozilla.org/about/legal':
return 'legal';
case 'https://testpilot.firefox.com/about':
return 'about';
case 'https://testpilot.firefox.com/privacy':
return 'privacy';
case 'https://testpilot.firefox.com/terms':
return 'terms';
case 'https://www.mozilla.org/privacy/websites/#cookies':
return 'cookies';
case 'https://github.com/mozilla/send':
return 'github';
case 'https://twitter.com/FxTestPilot':
return 'twitter';
case 'https://www.mozilla.org/firefox/new/?scene=2':
return 'download-firefox';
default:
return 'other';
}
}
function isFile(id) {
return /^[0-9a-fA-F]{10}$/.test(id);
}
function sendEvent() {
return window.analytics.sendEvent
.apply(window.analytics, arguments)
.catch(() => 0);
}
function copyToClipboard(str) {
const aux = document.createElement('input');
aux.setAttribute('value', str);
@ -143,8 +112,6 @@ module.exports = {
hexToArray,
notify,
gcmCompliant,
findMetric,
isFile,
sendEvent,
ONE_DAY_IN_MS
};