this.$description = document.querySelector('#att-description');
this.$error_message = document.querySelector('#att-error-message');
this.$ispatch = document.querySelector('#att-ispatch');
+ this.$hide_preview = document.querySelector('#att-hide-preview');
this.$type_outer = document.querySelector('#att-type-outer');
this.$type_list = document.querySelector('#att-type-list');
this.$type_manual = document.querySelector('#att-type-manual');
this.$description.addEventListener('input', () => this.description_oninput());
this.$description.addEventListener('change', () => this.description_onchange());
this.$ispatch.addEventListener('change', () => this.ispatch_onchange());
+ this.$hide_preview.addEventListener('change', () => this.hide_preview_onchange());
this.$type_select.addEventListener('change', () => this.type_select_onchange());
this.$type_input.addEventListener('change', () => this.type_input_onchange());
/**
* Show the preview of a user-selected file. Display a thumbnail if it's a regular image (PNG, GIF, JPEG, etc.) or
- * small plaintext file.
+ * small plaintext file. Don't show the preview of SVG image because it can be a crash test.
* @param {File} file A file to be previewed.
* @param {Boolean} [is_text=false] `true` if the file is a plaintext file, `false` otherwise.
*/
this.$preview_name.textContent = file.name;
this.$preview_type.content = file.type;
this.$preview_text.textContent = '';
- this.$preview_image.src = file.type.match(/^image\/(?!vnd)/) ? URL.createObjectURL(file) : '';
+ this.$preview_image.src = file.type.match(/^image\/(?!vnd|svg)/) ? URL.createObjectURL(file) : '';
this.$preview.hidden = false;
if (is_text && file.size < 500000) {
}
}
+ /**
+ * Called whenever the "hide preview" checkbox is checked or unchecked. Change the Content Type to binary if checked
+ * so the file will always be downloaded.
+ */
+ hide_preview_onchange() {
+ const hide_preview = this.$hide_preview.checked;
+
+ this.$type_outer.querySelectorAll('[name]').forEach($input => $input.disabled = hide_preview);
+
+ if (hide_preview) {
+ this.original_type = this.$type_input.value || this.$type_select.value;
+ this.update_content_type('application/octet-stream');
+ } else if (this.original_type) {
+ this.update_content_type(this.original_type);
+ }
+ }
+
/**
* Called whenever an option is selected from the Content Type list. Select the "select from list" radio button.
*/