Edit File by line
/home/barbar84/www/wp-conte.../plugins/bmwxgor/assets/js
File: codedropz-uploader-dev.js
/**
[0] Fix | Delete
* CodeDropz Uploader v1.3.6.8
[1] Fix | Delete
* Copyright 2018 Glen Mongaya
[2] Fix | Delete
* CodeDrop Drag&Drop Uploader
[3] Fix | Delete
* @version 1.3.6.8
[4] Fix | Delete
* @author CodeDropz, Glen Don L. Mongaya
[5] Fix | Delete
* @license The MIT License (MIT)
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
// CodeDropz Drag and Drop Plugin
[9] Fix | Delete
(function($){
[10] Fix | Delete
$.fn.CodeDropz_Uploader = function( settings ){
[11] Fix | Delete
[12] Fix | Delete
// Generate & check nonce
[13] Fix | Delete
if( $('form.wpcf7-form').length > 0 ){
[14] Fix | Delete
const form = $('form.wpcf7-form');
[15] Fix | Delete
$.post( dnd_cf7_uploader.ajax_url, { action: '_wpcf7_check_nonce', _ajax_nonce: dnd_cf7_uploader.ajax_nonce }, function(response){
[16] Fix | Delete
if( response.success && response.data ){
[17] Fix | Delete
dnd_cf7_uploader.ajax_nonce = response.data;
[18] Fix | Delete
}
[19] Fix | Delete
});
[20] Fix | Delete
};
[21] Fix | Delete
[22] Fix | Delete
// Support multiple elements
[23] Fix | Delete
this.each( function() {
[24] Fix | Delete
[25] Fix | Delete
// Parent input file type
[26] Fix | Delete
var input = $(this);
[27] Fix | Delete
[28] Fix | Delete
// Extends options
[29] Fix | Delete
var options = $.extend({
[30] Fix | Delete
handler : input,
[31] Fix | Delete
color : "#000",
[32] Fix | Delete
background : '',
[33] Fix | Delete
server_max_error : 'Uploaded file exceeds the maximum upload size of your server.',
[34] Fix | Delete
max_file : input.data('max') ? input.data('max') : 10, // default 10
[35] Fix | Delete
max_upload_size : input.data('limit') ? input.data('limit') : '10485760', // should be a bytes it's (5MB)
[36] Fix | Delete
supported_type : input.data('type') ? input.data('type') : 'jpg|jpeg|JPG|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv|xls',
[37] Fix | Delete
text : 'Drag & Drop Files Here',
[38] Fix | Delete
separator : 'or',
[39] Fix | Delete
button_text : 'Browse Files',
[40] Fix | Delete
on_success : ''
[41] Fix | Delete
}, settings);
[42] Fix | Delete
[43] Fix | Delete
// Get storage name
[44] Fix | Delete
var dataStorageName = input.data('name') + '_count_files';
[45] Fix | Delete
[46] Fix | Delete
// File Counter
[47] Fix | Delete
localStorage.setItem( dataStorageName, 1);
[48] Fix | Delete
[49] Fix | Delete
// Template Container
[50] Fix | Delete
var cdropz_template = '<div class="codedropz-upload-handler">'
[51] Fix | Delete
+ '<div class="codedropz-upload-container">'
[52] Fix | Delete
+ '<div class="codedropz-upload-inner">'
[53] Fix | Delete
+ '<'+ dnd_cf7_uploader.drag_n_drop_upload.tag +'>'+ options.text +'</'+ dnd_cf7_uploader.drag_n_drop_upload.tag +'>'
[54] Fix | Delete
+ '<span>'+ options.separator +'</span>'
[55] Fix | Delete
+'<div class="codedropz-btn-wrap"><a class="cd-upload-btn" href="javascript:void(0)">'+ options.button_text +'</a></div>'
[56] Fix | Delete
+'</div>'
[57] Fix | Delete
+ '</div>'
[58] Fix | Delete
+ '<span class="dnd-upload-counter"><span>0</span> '+ dnd_cf7_uploader.dnd_text_counter +' '+ parseInt(options.max_file) +'</span>'
[59] Fix | Delete
+ '</div>';
[60] Fix | Delete
[61] Fix | Delete
[62] Fix | Delete
// Wrap input fields
[63] Fix | Delete
options.handler.wrapAll('<div class="codedropz-upload-wrapper"></div>');
[64] Fix | Delete
[65] Fix | Delete
// Remove special character
[66] Fix | Delete
options.supported_type = options.supported_type.replace(/[^a-zA-Z0-9| ]/g, "");
[67] Fix | Delete
[68] Fix | Delete
// Element Handler
[69] Fix | Delete
var form_handler = options.handler.parents('form'),
[70] Fix | Delete
options_handler = options.handler.parents('.codedropz-upload-wrapper'),
[71] Fix | Delete
btnOBJ = $('input[type="submit"]', form_handler );
[72] Fix | Delete
[73] Fix | Delete
// Append Format
[74] Fix | Delete
options.handler.after( cdropz_template);
[75] Fix | Delete
[76] Fix | Delete
// preventing the unwanted behaviours
[77] Fix | Delete
$('.codedropz-upload-handler', options_handler ).on( 'drag dragstart dragend dragover dragenter dragleave drop', function( e ){
[78] Fix | Delete
e.preventDefault();
[79] Fix | Delete
e.stopPropagation();
[80] Fix | Delete
})
[81] Fix | Delete
[82] Fix | Delete
// dragover and dragenter - add class
[83] Fix | Delete
$('.codedropz-upload-handler', options_handler ).on( 'dragover dragenter', function( e ){
[84] Fix | Delete
$(this).addClass('codedropz-dragover');
[85] Fix | Delete
});
[86] Fix | Delete
[87] Fix | Delete
// dragleave dragend drop - remove class
[88] Fix | Delete
$('.codedropz-upload-handler', options_handler ).on( 'dragleave dragend drop', function( e ){
[89] Fix | Delete
$(this).removeClass('codedropz-dragover');
[90] Fix | Delete
});
[91] Fix | Delete
[92] Fix | Delete
// Browse button clicked
[93] Fix | Delete
$( 'a.cd-upload-btn', options_handler ).on("click", function(e){
[94] Fix | Delete
// stops the default action of an element from happening
[95] Fix | Delete
e.preventDefault();
[96] Fix | Delete
[97] Fix | Delete
// Reset value
[98] Fix | Delete
options.handler.val(null);
[99] Fix | Delete
[100] Fix | Delete
// Click input type[file] element
[101] Fix | Delete
options.handler.click();
[102] Fix | Delete
});
[103] Fix | Delete
[104] Fix | Delete
// when dropping files
[105] Fix | Delete
$('.codedropz-upload-handler', options_handler ).on('drop', function(event){
[106] Fix | Delete
// Run the uploader
[107] Fix | Delete
DND_Setup_Uploader( event.originalEvent.dataTransfer.files, 'drop' );
[108] Fix | Delete
});
[109] Fix | Delete
[110] Fix | Delete
// Trigger when input type[file] is click/changed
[111] Fix | Delete
options.handler.on("change", function(e){
[112] Fix | Delete
// Run the uploader
[113] Fix | Delete
DND_Setup_Uploader( this.files, 'click' );
[114] Fix | Delete
});
[115] Fix | Delete
[116] Fix | Delete
// Remove accept attribute on mobile devices
[117] Fix | Delete
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
[118] Fix | Delete
input.removeAttr('accept');
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
// Setup Uploader
[122] Fix | Delete
var DND_Setup_Uploader = function( files, action ) {
[123] Fix | Delete
[124] Fix | Delete
// make sure we have files
[125] Fix | Delete
if( ! files.length > 1 ) {
[126] Fix | Delete
return;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
// gathering the form data
[130] Fix | Delete
var formData = new FormData();
[131] Fix | Delete
[132] Fix | Delete
// Append file
[133] Fix | Delete
//formData.append('supported_type', options.supported_type ); @note : removed due Vulnerability
[134] Fix | Delete
//formData.append('size_limit', options.max_upload_size );
[135] Fix | Delete
formData.append('action', 'dnd_codedropz_upload' );
[136] Fix | Delete
formData.append('type', action );
[137] Fix | Delete
formData.append('security', dnd_cf7_uploader.ajax_nonce );
[138] Fix | Delete
[139] Fix | Delete
// CF7 - upload field name & cf7 id
[140] Fix | Delete
formData.append('form_id', input.data('id'));
[141] Fix | Delete
formData.append('upload_name', input.data('name'));
[142] Fix | Delete
[143] Fix | Delete
// black list file types
[144] Fix | Delete
if( input.data('black-list') ){
[145] Fix | Delete
formData.append('blacklist-types', input.data('black-list'));
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
// remove has error
[149] Fix | Delete
$('span.has-error', options.handler ).remove();
[150] Fix | Delete
[151] Fix | Delete
// Loop files
[152] Fix | Delete
$.each( files,function( i, file ) {
[153] Fix | Delete
[154] Fix | Delete
// Reset upload file type
[155] Fix | Delete
if( typeof formData.delete !== 'undefined' ) {
[156] Fix | Delete
formData.delete('upload-file');
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
// Limit file upload
[160] Fix | Delete
if( localStorage.getItem( dataStorageName ) > options.max_file ) {
[161] Fix | Delete
if( ! $('span.has-error-msg', options_handler ).length > 0 ) {
[162] Fix | Delete
err_msg = dnd_cf7_uploader.drag_n_drop_upload.max_file_limit;
[163] Fix | Delete
options_handler.append('<span class="has-error-msg">'+ err_msg.replace('%count%', options.max_file ) +'</span>');
[164] Fix | Delete
}
[165] Fix | Delete
return false;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
// Create progress bar
[169] Fix | Delete
var progressBarID = CodeDropz_Object.createProgressBar( file ),
[170] Fix | Delete
has_error = false;
[171] Fix | Delete
[172] Fix | Delete
// File size limit - validation
[173] Fix | Delete
if( file.size > options.max_upload_size ) {
[174] Fix | Delete
$('.dnd-upload-details', $('#' + progressBarID)).append('<span class="has-error">'+ dnd_cf7_uploader.drag_n_drop_upload.large_file +'</span>');
[175] Fix | Delete
has_error = true;
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
// Validate file type
[179] Fix | Delete
regex_type = new RegExp("(.*?)\.("+ options.supported_type +")$");
[180] Fix | Delete
if ( has_error === false && !( regex_type.test( file.name.toLowerCase() ) ) ) {
[181] Fix | Delete
$('.dnd-upload-details', $('#' + progressBarID)).append('<span class="has-error">'+ dnd_cf7_uploader.drag_n_drop_upload.inavalid_type +'</span>');
[182] Fix | Delete
has_error = true;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
// Increment count
[186] Fix | Delete
localStorage.setItem( dataStorageName, ( Number( localStorage.getItem( dataStorageName ) ) + 1 ) );
[187] Fix | Delete
[188] Fix | Delete
// Make sure there's no error
[189] Fix | Delete
if( has_error === false ) {
[190] Fix | Delete
[191] Fix | Delete
// Append file
[192] Fix | Delete
formData.append('upload-file', file );
[193] Fix | Delete
[194] Fix | Delete
// Process ajax upload
[195] Fix | Delete
var dnd_ajax_upload = $.ajax({
[196] Fix | Delete
url : options.ajax_url,
[197] Fix | Delete
type : form_handler.attr('method'),
[198] Fix | Delete
data : formData,
[199] Fix | Delete
dataType : 'json',
[200] Fix | Delete
cache : false,
[201] Fix | Delete
contentType : false,
[202] Fix | Delete
processData : false,
[203] Fix | Delete
xhr : function(){
[204] Fix | Delete
//objects to interact with servers.
[205] Fix | Delete
var _xhr = new window.XMLHttpRequest();
[206] Fix | Delete
[207] Fix | Delete
// reference : https://stackoverflow.com/questions/15410265/file-upload-progress-bar-with-jquery
[208] Fix | Delete
_xhr.upload.addEventListener("progress", function(event){
[209] Fix | Delete
if ( event.lengthComputable ) {
[210] Fix | Delete
var percentComplete = ( event.loaded / event.total );
[211] Fix | Delete
var percentage = parseInt( percentComplete * 100 );
[212] Fix | Delete
[213] Fix | Delete
// Progress Loading
[214] Fix | Delete
CodeDropz_Object.setProgressBar( progressBarID, percentage - 1 );
[215] Fix | Delete
[216] Fix | Delete
}
[217] Fix | Delete
}, false);
[218] Fix | Delete
[219] Fix | Delete
return _xhr;
[220] Fix | Delete
},
[221] Fix | Delete
complete : function() {
[222] Fix | Delete
// Set progress bar to 100%
[223] Fix | Delete
CodeDropz_Object.setProgressBar( progressBarID, 100 );
[224] Fix | Delete
},
[225] Fix | Delete
success: function(response) {
[226] Fix | Delete
if( response.success ) {
[227] Fix | Delete
[228] Fix | Delete
CodeDropz_Object.setProgressBar( progressBarID, 100 );
[229] Fix | Delete
[230] Fix | Delete
// Callback on success
[231] Fix | Delete
if ( $.isFunction( options.on_success ) ) {
[232] Fix | Delete
options.on_success.call( this, input, progressBarID, response );
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
}else {
[236] Fix | Delete
$('.dnd-progress-bar', $('#' + progressBarID)).remove();
[237] Fix | Delete
$('.dnd-upload-details', $('#' + progressBarID)).append('<span class="has-error">'+ response.data +'</span>');
[238] Fix | Delete
$('input[type="submit"]', form_handler ).removeClass('disabled').prop( "disabled", false );
[239] Fix | Delete
$('#' + progressBarID ).removeClass('in-progress');
[240] Fix | Delete
}
[241] Fix | Delete
},
[242] Fix | Delete
error: function(xhr,ajax,thrownError ) {
[243] Fix | Delete
$('.dnd-progress-bar', $('#' + progressBarID)).remove();
[244] Fix | Delete
$('.dnd-upload-details', $('#' + progressBarID)).append('<span class="has-error">'+ options.server_max_error +'</span>');
[245] Fix | Delete
$('input[type="submit"]', form_handler ).removeClass('disabled').prop( "disabled", false );
[246] Fix | Delete
$('#' + progressBarID ).removeClass('in-progress');
[247] Fix | Delete
}
[248] Fix | Delete
});
[249] Fix | Delete
}
[250] Fix | Delete
});
[251] Fix | Delete
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
// CodeDropz object and functions
[255] Fix | Delete
var CodeDropz_Object = {
[256] Fix | Delete
[257] Fix | Delete
// Create progress bar
[258] Fix | Delete
createProgressBar : function( file ) {
[259] Fix | Delete
[260] Fix | Delete
// Setup progress bar variable
[261] Fix | Delete
var upload_handler = $('.codedropz-upload-handler', options_handler ),
[262] Fix | Delete
generated_ID = 'dnd-file-' + Math.random().toString(36).substr(2, 9);
[263] Fix | Delete
[264] Fix | Delete
// Setup progressbar elements
[265] Fix | Delete
var fileDetails = '<div class="dnd-upload-image"><span class="file"></span></div>'
[266] Fix | Delete
+ '<div class="dnd-upload-details">'
[267] Fix | Delete
+ '<span class="name"><span>'+ file.name +'</span><em>('+ CodeDropz_Object.bytesToSize( file.size ) +')</em></span>'
[268] Fix | Delete
+ '<a href="javascript:void(0)" title="'+ dnd_cf7_uploader.drag_n_drop_upload.delete.title +'" class="remove-file" data-storage="'+ dataStorageName +'"><span class="dnd-icon-remove"></span></a>'
[269] Fix | Delete
+ '<span class="dnd-progress-bar"><span></span></span>'
[270] Fix | Delete
+ '</div>';
[271] Fix | Delete
[272] Fix | Delete
// Append Status Bar
[273] Fix | Delete
upload_handler.after('<div id="'+ generated_ID +'" class="dnd-upload-status">'+ fileDetails +'</div>');
[274] Fix | Delete
[275] Fix | Delete
return generated_ID;
[276] Fix | Delete
},
[277] Fix | Delete
[278] Fix | Delete
// Process progressbar ( Animate progress )
[279] Fix | Delete
setProgressBar : function( statusbar, percent ) {
[280] Fix | Delete
var statusBar = $( '.dnd-progress-bar', $('#' + statusbar) );
[281] Fix | Delete
if( statusBar.length > 0 ) {
[282] Fix | Delete
// Disable submit button
[283] Fix | Delete
CodeDropz_Object.disableBtn( btnOBJ );
[284] Fix | Delete
[285] Fix | Delete
// Compute Progress bar
[286] Fix | Delete
progress_width = ( percent * statusBar.width() / 100);
[287] Fix | Delete
[288] Fix | Delete
// Set status bar in-progress
[289] Fix | Delete
$('#' + statusbar).addClass('in-progress');
[290] Fix | Delete
[291] Fix | Delete
if( percent == 100 ) {
[292] Fix | Delete
$('span', statusBar ).width('100%').text( percent + '% ' );
[293] Fix | Delete
}else {
[294] Fix | Delete
$('span', statusBar ).animate({ width: progress_width }, 10).text( percent + '% ');
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
if( percent == 100 ) {
[298] Fix | Delete
$('#' + statusbar).addClass('complete').removeClass('in-progress');
[299] Fix | Delete
}
[300] Fix | Delete
}
[301] Fix | Delete
return false;
[302] Fix | Delete
},
[303] Fix | Delete
[304] Fix | Delete
// Size Conversion
[305] Fix | Delete
bytesToSize : function( bytes ) {
[306] Fix | Delete
[307] Fix | Delete
if( bytes === 0 )
[308] Fix | Delete
return '0';
[309] Fix | Delete
[310] Fix | Delete
kBytes = (bytes / 1024);
[311] Fix | Delete
fileSize = ( kBytes >= 1024 ? ( kBytes / 1024 ).toFixed(2) + 'MB' : kBytes.toFixed(2) + 'KB' );
[312] Fix | Delete
[313] Fix | Delete
return fileSize;
[314] Fix | Delete
},
[315] Fix | Delete
[316] Fix | Delete
// Disable button
[317] Fix | Delete
disableBtn : function( BtnOJB ) {
[318] Fix | Delete
if( BtnOJB.length > 0 ) {
[319] Fix | Delete
BtnOJB.addClass('disable').prop( "disabled", true );
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
};
[323] Fix | Delete
});// end each
[324] Fix | Delete
[325] Fix | Delete
// Remove File
[326] Fix | Delete
$(document).on("click",'.dnd-icon-remove',function(e){
[327] Fix | Delete
var _self = $(this),
[328] Fix | Delete
_dnd_status = _self.parents('.dnd-upload-status'),
[329] Fix | Delete
_parent_wrap = _self.parents('.codedropz-upload-wrapper'),
[330] Fix | Delete
removeStorageData = _self.parent('a').attr('data-storage'),
[331] Fix | Delete
storageCount = Number( localStorage.getItem( removeStorageData ) );
[332] Fix | Delete
[333] Fix | Delete
// If file upload is in progress don't delete
[334] Fix | Delete
if( _dnd_status.hasClass('in-progress')) {
[335] Fix | Delete
return false;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
// Direct remove the file if there's any error.
[339] Fix | Delete
if( $( '.has-error', _dnd_status ).length > 0 ) {
[340] Fix | Delete
_dnd_status.remove(); localStorage.setItem( removeStorageData, ( storageCount - 1 ) );
[341] Fix | Delete
return false;
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
// Change text Status
[345] Fix | Delete
_self.addClass('deleting').text( dnd_cf7_uploader.drag_n_drop_upload.delete.text + '...');
[346] Fix | Delete
[347] Fix | Delete
// Request ajax image delete
[348] Fix | Delete
var delData = {
[349] Fix | Delete
path : _dnd_status.find('input[type="hidden"]').val(),
[350] Fix | Delete
action : 'dnd_codedropz_upload_delete',
[351] Fix | Delete
security : dnd_cf7_uploader.ajax_nonce
[352] Fix | Delete
};
[353] Fix | Delete
[354] Fix | Delete
$.post( settings.ajax_url, delData, function(response) {
[355] Fix | Delete
if( response.success ) {
[356] Fix | Delete
[357] Fix | Delete
// Reduce file count and status bar element.
[358] Fix | Delete
_dnd_status.remove(); localStorage.setItem( removeStorageData, ( storageCount - 1 ) );
[359] Fix | Delete
[360] Fix | Delete
// Remove error msg
[361] Fix | Delete
if( $('.dnd-upload-status', _parent_wrap ).length <= 1 ) {
[362] Fix | Delete
$('span.has-error-msg', _parent_wrap ).remove();
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
// Update Counter
[366] Fix | Delete
$('.dnd-upload-counter span', _parent_wrap ).text( Number( localStorage.getItem( removeStorageData ) ) - 1 );
[367] Fix | Delete
}
[368] Fix | Delete
});
[369] Fix | Delete
[370] Fix | Delete
// Clear message
[371] Fix | Delete
$('span.has-error-msg').remove();
[372] Fix | Delete
[373] Fix | Delete
});
[374] Fix | Delete
[375] Fix | Delete
}; // end fn.function
[376] Fix | Delete
[377] Fix | Delete
}( jQuery ));
[378] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function