Skip to content

Commit 11fbad7

Browse files
authored
Merge pull request #1418 from mloyd/conditional-auto-download
Add check for page's referrer before auto download.
2 parents 221ee2a + 0b1f22b commit 11fbad7

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

app/assets/javascripts/application.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,24 @@ var Downloads = {
238238
Downloads.observeGUIOSFilter();
239239
Downloads.observePopState();
240240
Downloads.filterGUIS();
241+
Downloads.triggerAutoDownload();
242+
},
243+
244+
triggerAutoDownload: function() {
245+
var ref = document.referrer;
246+
var src = $('#auto-download-link').attr('href');
247+
248+
if (this.shouldAutoDownload(ref, src)) {
249+
$('.downloading .hide').show();
250+
document.location = src;
251+
}
252+
},
253+
254+
shouldAutoDownload: function(ref, src) {
255+
if (!ref || !src) {
256+
return false;
257+
}
258+
return ref.indexOf(document.location.origin) === 0;
241259
},
242260

243261
getOSFilter: function() {

app/assets/stylesheets/downloads.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,7 @@
121121
display: none;
122122
color: $orange;
123123
}
124+
125+
.downloading .hide {
126+
display: none;
127+
}

app/views/downloads/download_windows.html.erb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
<div id="main">
1010
<h1>Downloading Git</h1>
1111
<div class="callout downloading">
12-
<h3>Your download is starting...</h3>
12+
<h3 class="hide">Your download is starting...</h3>
1313
<p>
1414
<%= raw "You are downloading the latest (<strong>#{@download.version.name}</strong>) <strong>#{@bitness}</strong> version of <strong>Git for Windows</strong>. This is the most recent <a href='#{@project_url}'>maintained build</a>. It was released <strong>#{time_ago_in_words @download.release_date} ago</strong>, on #{@download.release_date.strftime("%Y-%m-%d")}." %>
1515
</p>
1616
<p>
17-
<%= raw "<strong>If your download hasn't started, <a href=\"#{@download.url}\">click here to download manually</a>.</strong>" %>
17+
<%= raw "<strong><a id=\"auto-download-link\" href=\"#{@download.url}\">Click here to download manually</a><span class=\"hide\">, if your download hasn't started.</span></strong>" %>
1818
</p>
1919
<h3>Other Git for Windows downloads</h3>
2020
<h4>Git for Windows Setup</h4>
@@ -34,7 +34,6 @@
3434
<p class="small">
3535
<%= raw "The current source code release is version <strong>#{@latest.name}</strong>. If you want the newer version, you can build it from <a href=\"#{@source_url}\">the source code</a>." %>
3636
</p>
37-
<iframe frameborder="0" height="1" src="<%= @download.url %>" width="1"></iframe>
3837
</div>
3938
<h2>Now What?</h2>
4039
<p>
@@ -64,4 +63,3 @@
6463
</li>
6564
</ul>
6665
</div>
67-

app/views/downloads/downloading.html.erb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
<div id="main">
1010
<h1>Downloading Git</h1>
1111
<div class="callout downloading">
12-
<h3>Your download is starting...</h3>
12+
<h3 class="hide">Your download is starting...</h3>
1313
<p>
1414
<%= raw "You are downloading version <strong>#{@download.version.name}</strong> of Git for the <strong>#{@platform.capitalize}</strong> platform. This is the most recent <a href='#{@project_url}'>maintained build</a> for this platform. It was released <strong>#{time_ago_in_words @download.release_date} ago</strong>, on #{@download.release_date.strftime("%Y-%m-%d")}." %>
1515
</p>
1616
<p>
17-
<%= raw "<strong>If your download hasn't started, <a href=\"#{@download.url}\">click here to download manually</a>.</strong>" %>
17+
<%= raw "<strong><a id=\"auto-download-link\" href=\"#{@download.url}\">Click here to download manually</a><span class=\"hide\">, if your download hasn't started.</span></strong>" %>
1818
</p>
1919
<p class="small">
2020
<%= raw "The current source code release is version <strong>#{@latest.name}</strong>. If you want the newer version, you can build it from <a href=\"#{@source_url}\">the source code</a>." %>
2121
</p>
2222
</div>
23-
<iframe frameborder="0" height="1" src="<%= @download.url %>" width="1"></iframe>
2423
<h2>Now What?</h2>
2524
<p>
2625
Now that you have downloaded Git, it's time to start using it.
@@ -49,4 +48,3 @@
4948
</li>
5049
</ul>
5150
</div>
52-

0 commit comments

Comments
 (0)