Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,32 @@
}
}

// @since 6.5.0 - Check if file upload field - supports {fieldname;duration} for total video duration
if (parent.classList.contains( 'super-file' )) {
text_field = false;
if (value_n === 'duration') {
var uploadFormId = 0,
uploadFormInput = form.querySelector( 'input[name="hidden_form_id"]' );
if (uploadFormInput) {
uploadFormId = uploadFormInput.value;
}
sum = 0;
if (typeof SUPER.files !== 'undefined' &&
typeof SUPER.files[uploadFormId] !== 'undefined' &&
typeof SUPER.files[uploadFormId][name] !== 'undefined') {
var fileList = SUPER.files[uploadFormId][name];
for (var fli = 0; fli < fileList.length; fli++) {
if (fileList[fli] && typeof fileList[fli]['duration'] !== 'undefined') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

['duration'] is better written in dot notation.

sum += parseFloat( fileList[fli]['duration'] );
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

['duration'] is better written in dot notation.

}
}
}
value = sum;
} else {
value = 0;
}
}

// Check if text or textarea field
if (text_field === true) {
value = (element.value) ? parseFloat( element.value ) : 0;
Expand Down
13 changes: 13 additions & 0 deletions src/assets/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,19 @@ function SUPERreCaptcha(){
var totalFiles = SUPER.files[formId][fieldName].length;
SUPER.files[formId][fieldName][totalFiles] = file;
SUPER.files[formId][fieldName][totalFiles]['url'] = src; // blob
// @since 6.5.0 - For video files, read duration via HTML5 File API before upload
if(file.type && file.type.indexOf("video/") === 0){
(function(capturedFormId, capturedFieldName, capturedIndex, capturedField, capturedForm){
var videoEl = document.createElement('video');
videoEl.preload = 'metadata';
videoEl.onloadedmetadata = function(){
URL.revokeObjectURL(videoEl.src);
SUPER.files[capturedFormId][capturedFieldName][capturedIndex]['duration'] = videoEl.duration;
SUPER.after_field_change_blur_hook({el: capturedField, form: capturedForm});
};
videoEl.src = URL.createObjectURL(file);
})(formId, fieldName, totalFiles, field, form);
}
var html = SUPER.get_single_uploaded_file_html(true, false, file.name, file.type, src);
data.context.data(data).attr('data-name',file.name).attr('title',file.name).attr('data-type',file.type).html(html);
data.context.data('file-size',file.size);
Expand Down
Loading