Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: File API compat for IE #4376

Merged
merged 2 commits into from
Apr 17, 2018
Merged
Changes from 1 commit
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
28 changes: 24 additions & 4 deletions ui/app/components/download-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,37 @@ export default Ember.Component.extend({
return `${this.get('filename')}-${new Date().toISOString()}.${this.get('extension')}`;
}),

href: computed('data', 'mime', 'stringify', function() {
fileLike: computed('data', 'mime', 'strigify', 'download', function() {
let file;
let data = this.get('data');
const mime = this.get('mime');
let filename = this.get('download');
let mime = this.get('mime');
if (this.get('stringify')) {
data = JSON.stringify(data, null, 2);
}
if (window.navigator.msSaveOrOpenBlob) {
file = new Blob([data], { type: mime });
file.name = filename;
} else {
file = new File([data], filename, { type: mime });
}
return file;
}),

const file = new File([data], { type: mime });
return window.URL.createObjectURL(file);
href: computed('fileLike', function() {
return window.URL.createObjectURL(this.get('fileLike'));
}),

click(event) {
if (!window.navigator.msSaveOrOpenBlob) {
return;
}
event.preventDefault();
let file = this.get('fileLike');
//lol whyyyy
window.navigator.msSaveOrOpenBlob(file, file.name);

Choose a reason for hiding this comment

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

Wow, this is annoying. Makes it harder to pretend that browsers are all the same.

It would be nice to hide all this msSaveOrOpenBlob stuff in some polyfill rather than in this component, but if it's only going to be used here, I guess it's not so bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah @johncowen mentioned https://github.com/eligrey/FileSaver.js/ which may be worth looking at if this gives us any other issues. I think for now since it's just in this component we'll try this for now.

},

actionText: 'Download',
data: null,
filename: null,
Expand Down