Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions assets/js/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@
}
}

function triggerDownload(blob, filename) {
var link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}

Comment on lines +85 to +93
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function triggerDownload(blob, filename) {
var link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}

This function already exists and just got copy and pasted to the top

function submit_download() {
$('#download-button').html('<i class="glyphicon glyphicon-send"></i> Sending Request...').addClass('disabled');

Expand All @@ -105,13 +114,20 @@
if (matches != null && matches[1])
filename = matches[1].replace(/['"]/g, "");
}

var jsBlob = new Blob([data], { type: "text/javascript" });
var configData = JSON.stringify({ version: form_data.version, modules: form_data.modules }, null, 2);

triggerDownload(jsBlob, filename);
triggerDownload(new Blob([configData], { type: "application/json" }), "prebid-config.json");

triggerDownload(new Blob([configData], { type: "application/json" }), "prebid-config.json")
if (window.pako) {
try {
var gz = pako.gzip(data);
var kb = (gz.length / 1024).toFixed(1);
document.getElementById('package-size').innerText = 'Estimated gzipped size: ' + kb + ' kB';
} catch(e) {
console.log('pako gzip failed', e);
}
}
Comment on lines +122 to +130
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this after the download has a weird UX. I understand that in order to calculate the gzipped size, we first need to have the file itself. Still it's so tiny at the bottom, I could hardly find it.

We can add this, but not sure of the value it adds 😁

if (form_data["removedModules"].length > 0) {
alert(
"The following modules were removed from your download because they aren't present in Prebid.js version " +
Expand Down
3 changes: 3 additions & 0 deletions download.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ a.tip:hover span {
</style>

<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.4/pako.min.js"></script>
<script src="/assets/js/download.js"></script>

<style>
Expand Down Expand Up @@ -119,6 +120,8 @@ These modules may require accounts with a service provider.<br/>

<button id="download-button" type="button" class="btn btn-lg btn-primary">Get Prebid.js! </button>

<div id="package-size" style="margin-top:10px"></div>

</div>

</form>
Expand Down