Skip to content

Commit

Permalink
fix duplicate name + IE/Edge specific download
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmoisson committed Jun 15, 2017
1 parent 7fbffa8 commit 86a3aa9
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ <h2>Encrypted HTML</h2>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>

<script>
var htmlToDownload;

var renderTemplate = function (tpl, data) {
return tpl.replace(/{(.*?)}/g, function (_, key) {
return data && data[key] || '';
});
}
};

var renderTemplate = function (data) {
var setFileToDownload = function (data) {
var request = new XMLHttpRequest();
request.open('GET', 'password_template.html', true);
request.onload = function() {
Expand All @@ -141,6 +143,8 @@ <h2>Encrypted HTML</h2>
var downloadLink = document.querySelector('a.download');
downloadLink.href = 'data:attachment/text,' + encodeURIComponent(renderedTmpl);
downloadLink.removeAttribute('disabled');

htmlToDownload = renderedTmpl;
};
request.send();
};
Expand All @@ -165,7 +169,7 @@ <h2>Encrypted HTML</h2>

document.getElementById('encrypted_html_display').textContent = encryptedMsg;

renderTemplate(data);
setFileToDownload(data);
});

document.getElementById('toggle-extra-option')
Expand All @@ -179,6 +183,23 @@ <h2>Encrypted HTML</h2>
e.preventDefault();
document.getElementById('concept').classList.toggle('hidden');
});


document.getElementById('toggle-concept')
.addEventListener('click', function (e) {

var isIE = (navigator.userAgent.indexOf("MSIE") !== -1 ) || (!!document.documentMode === true ); // >= 10
var isEdge = navigator.userAgent.indexOf("Edge") !== -1;

// download with MS specific feature
if (htmlToDownload && (isIE || isEdge)) {
e.preventDefault();
var blobObject = new Blob([htmlToDownload]);
window.navigator.msSaveOrOpenBlob(blobObject, 'encrypted.html');
}

return true;
})
</script>


Expand Down

0 comments on commit 86a3aa9

Please sign in to comment.