|
9 | 9 | $(".adapters .col-md-4").show(); |
10 | 10 | setPrepickedModules(); |
11 | 11 |
|
| 12 | + var configInput = document.getElementById('configFileInput'); |
| 13 | + if (configInput) { |
| 14 | + configInput.addEventListener('change', function(event) { |
| 15 | + var file = event.target.files[0]; |
| 16 | + if (!file) return; |
| 17 | + var reader = new FileReader(); |
| 18 | + reader.onload = function(e) { |
| 19 | + try { |
| 20 | + var cfg = JSON.parse(e.target.result); |
| 21 | + applyConfig(cfg); |
| 22 | + } catch (err) { |
| 23 | + alert('Invalid configuration file'); |
| 24 | + } |
| 25 | + }; |
| 26 | + reader.readAsText(file); |
| 27 | + }); |
| 28 | + } |
| 29 | + |
12 | 30 | document.getElementById('download-button').addEventListener('click', function (event) { |
13 | 31 | event.preventDefault(); |
14 | 32 | submit_download(); |
|
79 | 97 | setTimeout(function () { |
80 | 98 | $('#download-button').html('<i class="glyphicon glyphicon-download-alt"></i> Download Prebid.js').removeClass('disabled'); |
81 | 99 | }, 5000); |
82 | | - // Try to find out the filename from the content disposition `filename` value |
83 | 100 | var filename = "prebid" + form_data["version"] + ".js"; |
84 | | - // this doens't work in our current jquery version. |
85 | 101 | var disposition = jqXHR.getResponseHeader("Content-Disposition"); |
86 | 102 | if (disposition && disposition.indexOf("attachment") !== -1) { |
87 | 103 | var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/; |
88 | 104 | var matches = filenameRegex.exec(disposition); |
89 | 105 | if (matches != null && matches[1]) |
90 | 106 | filename = matches[1].replace(/['"]/g, ""); |
91 | 107 | } |
92 | | - // The actual download |
93 | | - var blob = new Blob([data], { type: "text/javascript" }); |
94 | | - var link = document.createElement("a"); |
95 | | - link.href = window.URL.createObjectURL(blob); |
96 | | - link.download = filename; |
97 | | - document.body.appendChild(link); |
98 | | - link.click(); |
99 | | - document.body.removeChild(link); |
| 108 | + |
| 109 | + var jsBlob = new Blob([data], { type: "text/javascript" }); |
| 110 | + var configData = JSON.stringify({ version: form_data.version, modules: form_data.modules }, null, 2); |
| 111 | + |
| 112 | + triggerDownload(jsBlob, filename); |
| 113 | + triggerDownload(new Blob([configData], { type: "application/json" }), "prebid-config.json"); |
| 114 | + |
100 | 115 | if (form_data["removedModules"].length > 0) { |
101 | 116 | alert( |
102 | 117 | "The following modules were removed from your download because they aren't present in Prebid.js version " + |
|
112 | 127 | }); |
113 | 128 | } |
114 | 129 |
|
| 130 | + function triggerDownload(blob, filename) { |
| 131 | + var link = document.createElement("a"); |
| 132 | + link.href = window.URL.createObjectURL(blob); |
| 133 | + link.download = filename; |
| 134 | + document.body.appendChild(link); |
| 135 | + link.click(); |
| 136 | + document.body.removeChild(link); |
| 137 | + } |
| 138 | + |
115 | 139 | const renameModules = (function() { |
116 | 140 | const RENAMES = [ |
117 | 141 | [ |
|
206 | 230 | }); |
207 | 231 | } |
208 | 232 |
|
| 233 | + function applyConfig(cfg) { |
| 234 | + if (!cfg) return; |
| 235 | + if (cfg.version) { |
| 236 | + var versionOption = document.querySelector('#version_selector option[value="' + cfg.version + '"]'); |
| 237 | + if (versionOption) { |
| 238 | + versionOption.selected = true; |
| 239 | + searchParams.set("version", cfg.version); |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + if (Array.isArray(cfg.modules)) { |
| 244 | + var moduleCheckboxes = document.querySelectorAll('.module-check-box'); |
| 245 | + moduleCheckboxes.forEach(function(cb){ cb.checked = false; }); |
| 246 | + cfg.modules.forEach(function(module){ |
| 247 | + var cb = document.getElementById(module); |
| 248 | + if (cb) cb.checked = true; |
| 249 | + }); |
| 250 | + if (cfg.modules.length) { |
| 251 | + searchParams.set("modules", cfg.modules.join(',')); |
| 252 | + } else { |
| 253 | + searchParams.delete("modules"); |
| 254 | + } |
| 255 | + window.history.replaceState(null, "", window.location.pathname + "?" + searchParams.toString()); |
| 256 | + } |
| 257 | + } |
| 258 | + |
209 | 259 | function setPrepickedVersion() { |
210 | 260 | var version = searchParams.get("version"); |
211 | 261 | if (version) { |
|
0 commit comments