1document.addEventListener( 'wpcf7mailsent', function( event ) { 2 $(".cf7-drop-upload").val(""); 3 $(".cf7-drop-statusbar").remove(); 4}, false ); 5function cf7_sendFileToServer(formData,status){ 6 //var uploadURL = cf7_dropfiles.url_plugin + "frontend/upload.php"; //Upload URL 7 var uploadURL = cf7_dropfiles.ajax_url; //Upload URL 8 var extraData ={}; //Extra Data. 9 var jqXHR=jQuery.ajax({ 10 xhr: function() { 11 var xhrobj = jQuery.ajaxSettings.xhr(); 12 if (xhrobj.upload) { 13 xhrobj.upload.addEventListener('progress', function(event) { 14 var percent = 0; 15 var position = event.loaded || event.position; 16 var total = event.total; 17 if (event.lengthComputable) { 18 percent = Math.ceil(position / total * 100); 19 } 20 //Set progress 21 status.setProgress(percent); 22 }, false); 23 } 24 return xhrobj; 25 }, 26 url: uploadURL, 27 type: "POST", 28 contentType:false, 29 processData: false, 30 cache: false, 31 data: formData, 32 success: function(data){ 33 status.setProgress(100); 34 if( data.status =="ok" ) { 35 status.name_upload(data.text); 36 var name = jQuery(".cf7-drop-upload").val(); 37 if(name == "" ) { 38 name = data.text; 39 }else{ 40 name = name +"|"+data.text; 41 } 42 jQuery(".cf7-drop-upload").val(name); 43 }else{ 44 if( !data.text ) { 45 //alert(data); 46 status.text("Error: POST Content-Length limit"); 47 }else{ 48 status.text(data.text); 49 } 50 51 } 52 53 } 54 }); 55 56 status.setAbort(jqXHR); 57} 58 59var rowCount=0; 60function cf7_createStatusbar(obj){ 61 rowCount++; 62 var row="odd"; 63 if(rowCount %2 ==0) row ="even"; 64 65 66 67 this.statusbar = jQuery("<div class='cf7-drop-statusbar "+row+"'></div>"); 68 this.filename = jQuery("<div class='cf7-drop-filename'></div>").appendTo(this.statusbar); 69 this.size = jQuery("<div class='cf7-drop-filesize'></div>").appendTo(this.statusbar); 70 this.progressBar = jQuery("<div class='cf7-drop-progressBar'><div></div></div>").appendTo(this.statusbar); 71 this.abort = jQuery('<div class="cf7-drop-abort"><a href="#">Abort</a></div>').appendTo(this.statusbar); 72 this.remove = jQuery('<div style="display:none" class="cf7-drop-remove"><a href="#">Remove</a></div>').appendTo(this.statusbar); 73 obj.after(this.statusbar); 74 75 this.text = function(txt){ 76 this.progressBar.addClass("cf7-text-error").html(txt); 77 this.remove.hide(); 78 } 79 this.name_upload = function(txt){ 80 this.remove.attr('data-name', txt); 81 } 82 83 this.setFileNameSize = function(name,size) 84 { 85 var sizeStr=""; 86 var sizeKB = size/1024; 87 if(parseInt(sizeKB) > 1024) 88 { 89 var sizeMB = sizeKB/1024; 90 sizeStr = sizeMB.toFixed(2)+" MB"; 91 } 92 else 93 { 94 sizeStr = sizeKB.toFixed(2)+" KB"; 95 } 96 97 this.filename.html(name); 98 this.size.html(sizeStr); 99 } 100 this.setProgress = function(progress){ 101 var progressBarWidth =progress*this.progressBar.width()/ 100; 102 this.progressBar.find('div').animate({ width: progressBarWidth }, 10).html(progress + "% "); 103 if(parseInt(progress) >= 100) 104 { 105 this.abort.hide(); 106 this.remove.show(); 107 } 108 } 109 110 this.setAbort = function(jqxhr){ 111 var sb = this.statusbar; 112 this.abort.click(function() 113 { 114 jqxhr.abort(); 115 sb.hide(); 116 }); 117 } 118} 119function cf7_handleFileUpload(files,obj){ 120 121 var max = obj.attr("data-max"); 122 var name = jQuery(".cf7-drop-upload").val(); 123 var count = (name.match(/\|/g) || []).length; 124 if(name != "" ){ 125 count++; 126 } 127 if( max == "" ){ 128 max = 0; 129 } 130 var max_limit = max - count + 1; 131 if ( max != 0 && parseInt(files.length)>=max_limit){ 132 alert("You can only upload a maximum of "+max+" files"); 133 }else{ 134 for (var i = 0; i < files.length; i++) { 135 var fd = new FormData(); 136 fd.append('file', files[i]); 137 fd.append('size', obj.data("size") ); 138 fd.append('type', obj.data("type") ); 139 fd.append('action', "cf7_dropfiles_upload" ); 140 var status = new cf7_createStatusbar(obj); //Using this we can set progress. 141 status.setFileNameSize(files[i].name,files[i].size); 142 cf7_sendFileToServer(fd,status); 143 144 } 145 } 146} 147jQuery(document).ready(function($){ 148 149 var obj = jQuery(".cf7-dragandrophandler"); 150 obj.on('dragenter', function (e) 151 { 152 e.stopPropagation(); 153 e.preventDefault(); 154 jQuery(this).css('border', '2px solid #0B85A1'); 155 }); 156 obj.on('dragover', function (e) 157 { 158 e.stopPropagation(); 159 e.preventDefault(); 160 }); 161 obj.on('drop', function (e) 162 { 163 164 jQuery(this).css('border', '2px dotted #0B85A1'); 165 e.preventDefault(); 166 var files = e.originalEvent.dataTransfer.files; 167 //We need to send dropped files to Server 168 cf7_handleFileUpload(files,obj); 169 }); 170 jQuery(document).on('dragenter', function (e) 171 { 172 e.stopPropagation(); 173 e.preventDefault(); 174 }); 175 jQuery(document).on('dragover', function (e) 176 { 177 e.stopPropagation(); 178 e.preventDefault(); 179 obj.css('border', '2px dotted #0B85A1'); 180 }); 181 jQuery(document).on('drop', function (e) 182 { 183 e.stopPropagation(); 184 e.preventDefault(); 185 }); 186 obj.find('a').on('click', function (e) 187 { 188 //e.stopPropagation(); 189 e.preventDefault(); 190 $(this).closest(".cf7-dragandrophandler-container").find('.input-uploads').click(); 191 }); 192 193 obj.closest(".cf7-dragandrophandler-container").find('.input-uploads').on('change', function (e) 194 { 195 var files = this.files; 196 //We need to send dropped files to Server 197 cf7_handleFileUpload(files,obj); 198 }); 199 200 $("body").on("click",".cf7-drop-remove a",function(e){ 201 e.preventDefault(); 202 var cr_name = $(this).closest('.cf7-drop-remove').data("name") ; 203 var data = { 204 'action': 'cf7_dropfiles_remove', 205 'name': cr_name 206 }; 207 var name = $('.cf7-drop-upload').val().split("|"); 208 209 for (var i=name.length-1; i>=0; i--) { 210 if (name[i] === cr_name) { 211 name.splice(i, 1); 212 } 213 } 214 215 $('.cf7-drop-upload').val( name.join("|") ); 216 $(this).closest('.cf7-drop-statusbar').remove(); 217 jQuery.post(cf7_dropfiles.ajax_url, data, function(response) { 218 219 }); 220 221 }) 222});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.