Skip to content
Merged
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
49 changes: 39 additions & 10 deletions dist/doboard-widget-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10229,10 +10229,16 @@ class CleanTalkWidgetDoboard {
this.bindCreateTaskEvents(this);
this.bindShowLoginFormEvents();

this.fileUploader = new FileUploader(this.escapeHtml);
this.fileUploader.init();
this.fileUploader = new FileUploader(this?.escapeHtml);
if (this?.fileUploader) {
try {
this.fileUploader.init();
} catch (error) {
console.warn('File uploader init error:', error.message);
}
}

if (!this.nonRequesting && typeof this.fileUploader.makeScreenshot === 'function') {
if (!this?.nonRequesting && this?.fileUploader?.makeScreenshot && typeof this?.fileUploader?.makeScreenshot === 'function') {
const originalDisplay = widgetContainer.style.display;
widgetContainer.style.display = 'none';

Expand Down Expand Up @@ -13426,6 +13432,11 @@ class FileUploader {
*/
init() {
this.initializeElements();

if (!this.uploaderWrapper) {
return;
}

this.bindFilesInputChange();
}

Expand All @@ -13445,7 +13456,7 @@ class FileUploader {
/** @type {HTMLElement|null} */
this.errorMessage = document.getElementById('doboard_task_widget__file-upload__error');

if (!this.fileInput || !this.fileList || !this.errorMessage || this.uploaderWrapper) {
if (!this.fileInput || !this.fileList || !this.errorMessage || !this.uploaderWrapper) {
console.warn('File uploader elements not found');
}
}
Expand Down Expand Up @@ -13495,7 +13506,9 @@ class FileUploader {
event.target.value = '';

// show wrapper
this.uploaderWrapper.style.display = 'block';
if (this.uploaderWrapper && this.uploaderWrapper.style) {
this.uploaderWrapper.style.display = 'block';
}
}

/**
Expand Down Expand Up @@ -13800,7 +13813,12 @@ class FileUploader {
}

async makeScreenshot() {
if (this.files.length >= this.maxFiles || this.getTotalSize() >= this.maxTotalSize) {
if (!this.files || !Array.isArray(this.files) || this.files.length >= this.maxFiles) {
console.log('SpotFix: File count limit reached or file uploader is not fully initialized.');
return;
}

if (typeof this.getTotalSize === 'function' && this.getTotalSize() >= this.maxTotalSize) {
console.log('SpotFix: File count or total size limit reached. Automatic screenshot cancelled.');
return;
}
Expand Down Expand Up @@ -13889,13 +13907,24 @@ class FileUploader {
lastModified: Date.now(),
});

if (this.validateFile(file)) {
if (this.uploaderWrapper && this.uploaderWrapper.style.display !== 'block') {
if (typeof this.validateFile === 'function' && this.validateFile(file)) {

if (this.uploaderWrapper && this.uploaderWrapper.style && this.uploaderWrapper.style.display !== 'block') {
this.uploaderWrapper.style.display = 'block';
}

this.clearError();
this.addFile(file);
if (typeof this.clearError === 'function') {
this.clearError();
}

try {
if (typeof this.addFile === 'function') {
this.addFile(file);
}
} catch (addFileError) {
console.warn('SpotFix: Cannot add screenshot to DOM (uploader elements missing)', addFileError.message);
}

} else {
console.warn('SpotFix: Automatic screenshot was not added because the total file size would exceed the limit.');
}
Expand Down
6 changes: 3 additions & 3 deletions dist/doboard-widget-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/doboard-widget-bundle.min.js.map

Large diffs are not rendered by default.

37 changes: 30 additions & 7 deletions js/src/fileuploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class FileUploader {
*/
init() {
this.initializeElements();

if (!this.uploaderWrapper) {
return;
}

this.bindFilesInputChange();
}

Expand All @@ -54,7 +59,7 @@ class FileUploader {
/** @type {HTMLElement|null} */
this.errorMessage = document.getElementById('doboard_task_widget__file-upload__error');

if (!this.fileInput || !this.fileList || !this.errorMessage || this.uploaderWrapper) {
if (!this.fileInput || !this.fileList || !this.errorMessage || !this.uploaderWrapper) {
console.warn('File uploader elements not found');
}
Comment thread
veronika-tseleva-cleantalk marked this conversation as resolved.
}
Expand Down Expand Up @@ -104,7 +109,9 @@ class FileUploader {
event.target.value = '';

// show wrapper
this.uploaderWrapper.style.display = 'block';
if (this.uploaderWrapper && this.uploaderWrapper.style) {
this.uploaderWrapper.style.display = 'block';
}
}

/**
Expand Down Expand Up @@ -409,7 +416,12 @@ class FileUploader {
}

async makeScreenshot() {
if (this.files.length >= this.maxFiles || this.getTotalSize() >= this.maxTotalSize) {
if (!this.files || !Array.isArray(this.files) || this.files.length >= this.maxFiles) {
console.log('SpotFix: File count limit reached or file uploader is not fully initialized.');
return;
}

if (typeof this.getTotalSize === 'function' && this.getTotalSize() >= this.maxTotalSize) {
console.log('SpotFix: File count or total size limit reached. Automatic screenshot cancelled.');
return;
}
Expand Down Expand Up @@ -498,13 +510,24 @@ class FileUploader {
lastModified: Date.now(),
});

if (this.validateFile(file)) {
if (this.uploaderWrapper && this.uploaderWrapper.style.display !== 'block') {
if (typeof this.validateFile === 'function' && this.validateFile(file)) {

if (this.uploaderWrapper && this.uploaderWrapper.style && this.uploaderWrapper.style.display !== 'block') {
this.uploaderWrapper.style.display = 'block';
}

this.clearError();
this.addFile(file);
if (typeof this.clearError === 'function') {
this.clearError();
}

try {
if (typeof this.addFile === 'function') {
this.addFile(file);
}
} catch (addFileError) {
console.warn('SpotFix: Cannot add screenshot to DOM (uploader elements missing)', addFileError.message);
}

} else {
console.warn('SpotFix: Automatic screenshot was not added because the total file size would exceed the limit.');
}
Expand Down
12 changes: 9 additions & 3 deletions js/src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,16 @@ class CleanTalkWidgetDoboard {
this.bindCreateTaskEvents(this);
this.bindShowLoginFormEvents();

this.fileUploader = new FileUploader(this.escapeHtml);
this.fileUploader.init();
this.fileUploader = new FileUploader(this?.escapeHtml);
if (this?.fileUploader) {
try {
this.fileUploader.init();
} catch (error) {
console.warn('File uploader init error:', error.message);
}
}

if (!this.nonRequesting && typeof this.fileUploader.makeScreenshot === 'function') {
if (!this?.nonRequesting && this?.fileUploader?.makeScreenshot && typeof this?.fileUploader?.makeScreenshot === 'function') {
const originalDisplay = widgetContainer.style.display;
widgetContainer.style.display = 'none';

Expand Down