From 859554ce21b9cdcbb1cab3af272ae2c1c4885706 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Sat, 5 Aug 2017 09:40:57 -0700 Subject: [PATCH] only _blank links while downloading. fixed safari link after download --- frontend/src/common.js | 39 ++++++++++++++++++++++++++++++++--- frontend/src/download.js | 15 +++++++------- frontend/src/links.js | 19 +++++++++++++++++ frontend/src/upload.js | 6 +----- frontend/src/utils.js | 33 ----------------------------- views/download.handlebars | 2 +- views/layouts/main.handlebars | 16 +++++++------- views/unsupported.handlebars | 4 ++-- 8 files changed, 74 insertions(+), 60 deletions(-) create mode 100644 frontend/src/links.js diff --git a/frontend/src/common.js b/frontend/src/common.js index 5b8c3330..7baa52b0 100644 --- a/frontend/src/common.js +++ b/frontend/src/common.js @@ -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 +} diff --git a/frontend/src/download.js b/frontend/src/download.js index 34540811..a93ae36d 100644 --- a/frontend/src/download.js +++ b/frontend/src/download.js @@ -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 => { diff --git a/frontend/src/links.js b/frontend/src/links.js new file mode 100644 index 00000000..5f5a4840 --- /dev/null +++ b/frontend/src/links.js @@ -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 +} diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 9d3171c2..290cfdf6 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -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'); diff --git a/frontend/src/utils.js b/frontend/src/utils.js index 599ef80c..b6d0280c 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -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 }; diff --git a/views/download.handlebars b/views/download.handlebars index b0801422..dc7b0085 100644 --- a/views/download.handlebars +++ b/views/download.handlebars @@ -35,5 +35,5 @@ - + diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index 15a1fdce..1bd8c63d 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -36,7 +36,7 @@
{{{body}}} @@ -44,15 +44,15 @@ diff --git a/views/unsupported.handlebars b/views/unsupported.handlebars index 8f745e35..b4b2f8cf 100644 --- a/views/unsupported.handlebars +++ b/views/unsupported.handlebars @@ -8,8 +8,8 @@ {{else}}
Unfortunately this browser does not support the web technology that powers Firefox Send. You’ll need to try another browser. We recommend Firefox!
- - + +
Firefox
Free Download