Skip to content

Commit fdf6a60

Browse files
MelissaAutumnSancus
authored andcommitted
Re-implement downloaded=true check for autodownload.js. (Fixes #411)
This check is needed to prevent a second download from occurring if they came from a link that previously started a download.
1 parent 8dfcbc4 commit fdf6a60

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

assets/js/common/autodownload.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@
55
(function($) {
66
'use strict';
77

8+
/**
9+
* Check to see if we can start an autodownload
10+
* @returns {boolean}
11+
*/
12+
function canAutodownload () {
13+
var isIELT9 = window.Mozilla.Client.platform === 'windows' && /MSIE\s[1-8]\./.test(navigator.userAgent);
14+
15+
// IE11 safe check for determining if we've already downloaded Thunderbird
16+
var lowercaseQuery = window.location.search.toLowerCase();
17+
var isDownloaded = /([?|&]+downloaded=true)/.test(lowercaseQuery) === true;
18+
19+
return !isDownloaded && !isIELT9;
20+
}
21+
822
// Only do this on the autodownload page.
923
if ($('body').attr('id') == 'thunderbird-download') {
10-
var isIELT9 = window.Mozilla.Client.platform === 'windows' && /MSIE\s[1-8]\./.test(navigator.userAgent);
24+
if (!canAutodownload()) {
25+
return;
26+
}
1127
var downloadURL;
1228
var downloadChannelRegex = /download_channel=(esr|beta|daily)/;
1329
var downloadChannel = downloadChannelRegex.exec(window.location.search);
@@ -37,16 +53,13 @@
3753
// Track auto downloads - trackLink( url, linkType )
3854
window._paq.push(['trackLink', downloadURL, 'download'])
3955

40-
// If user is not on an IE that blocks JS triggered downloads, start the
41-
// platform-detected download a second after DOM ready event. We don't rely on
56+
// Start the platform-detected download a second after DOM ready event. We don't rely on
4257
// the window load event as we have third-party tracking pixels.
43-
if (!isIELT9) {
44-
$(function() {
45-
setTimeout(function() {
46-
window.location.href = downloadURL;
47-
}, 1000);
48-
});
49-
}
58+
$(function() {
59+
setTimeout(function() {
60+
window.location.href = downloadURL;
61+
}, 1000);
62+
});
5063
}
5164
}
5265
})(window.jQuery);

0 commit comments

Comments
 (0)