diff --git a/assets/js/ajax-file-upload.js b/assets/js/ajax-file-upload.js index f723b1aa5..409b5e657 100644 --- a/assets/js/ajax-file-upload.js +++ b/assets/js/ajax-file-upload.js @@ -42,6 +42,13 @@ jQuery(function($) { fail: function (e, data) { var $file_field = $( this ); var $form = $file_field.closest( 'form' ); + + if ( data.errorThrown ) { + alert( data.errorThrown ); + } + + data.context.remove(); + $form.find(':input[type="submit"]').removeAttr( 'disabled' ); }, done: function (e, data) { diff --git a/assets/js/ajax-file-upload.min.js b/assets/js/ajax-file-upload.min.js index 017092cb2..d8c407fef 100644 --- a/assets/js/ajax-file-upload.min.js +++ b/assets/js/ajax-file-upload.min.js @@ -1 +1 @@ -jQuery(function(a){a(".wp-job-manager-file-upload").each(function(){a(this).fileupload({dataType:"json",dropZone:a(this),url:job_manager_ajax_file_upload.ajax_url.toString().replace("%%endpoint%%","upload_file"),maxNumberOfFiles:1,formData:{script:!0},add:function(b,c){var d=a(this),e=d.closest("form"),f=d.parent().find(".job-manager-uploaded-files"),g=[],h=a(this).data("file_types");if(h){var i=new RegExp("(.|/)("+h+")$","i");c.originalFiles[0].name.length&&!i.test(c.originalFiles[0].name)&&g.push(job_manager_ajax_file_upload.i18n_invalid_file_type+" "+h)}g.length>0?alert(g.join("\n")):(e.find(':input[type="submit"]').attr("disabled","disabled"),c.context=a('').appendTo(f),c.submit())},progress:function(b,c){var d=a(this),e=(d.parent().find(".job-manager-uploaded-files"),parseInt(c.loaded/c.total*100,10));c.context.val(e)},fail:function(b,c){var d=a(this),e=d.closest("form");e.find(':input[type="submit"]').removeAttr("disabled")},done:function(b,c){var d=a(this),e=d.closest("form"),f=d.parent().find(".job-manager-uploaded-files"),g=d.attr("multiple")?1:0,h=["jpg","gif","png","jpeg","jpe"];c.context.remove(),a.each(c.result.files,function(b,c){if(c.error)alert(c.error);else{if(a.inArray(c.extension,h)>=0){var e=a.parseHTML(job_manager_ajax_file_upload.js_field_html_img);a(e).find(".job-manager-uploaded-file-preview img").attr("src",c.url)}else{var e=a.parseHTML(job_manager_ajax_file_upload.js_field_html);a(e).find(".job-manager-uploaded-file-name code").text(c.name)}a(e).find(".input-text").val(c.url),a(e).find(".input-text").attr("name","current_"+d.attr("name")),g?f.append(e):f.html(e)}}),e.find(':input[type="submit"]').removeAttr("disabled")}})})}); \ No newline at end of file +jQuery(function(a){a(".wp-job-manager-file-upload").each(function(){a(this).fileupload({dataType:"json",dropZone:a(this),url:job_manager_ajax_file_upload.ajax_url.toString().replace("%%endpoint%%","upload_file"),maxNumberOfFiles:1,formData:{script:!0},add:function(b,c){var d=a(this),e=d.closest("form"),f=d.parent().find(".job-manager-uploaded-files"),g=[],h=a(this).data("file_types");if(h){var i=new RegExp("(.|/)("+h+")$","i");c.originalFiles[0].name.length&&!i.test(c.originalFiles[0].name)&&g.push(job_manager_ajax_file_upload.i18n_invalid_file_type+" "+h)}g.length>0?alert(g.join("\n")):(e.find(':input[type="submit"]').attr("disabled","disabled"),c.context=a('').appendTo(f),c.submit())},progress:function(b,c){var d=a(this),e=(d.parent().find(".job-manager-uploaded-files"),parseInt(c.loaded/c.total*100,10));c.context.val(e)},fail:function(b,c){var d=a(this),e=d.closest("form");c.errorThrown&&alert(c.errorThrown),c.context.remove(),e.find(':input[type="submit"]').removeAttr("disabled")},done:function(b,c){var d=a(this),e=d.closest("form"),f=d.parent().find(".job-manager-uploaded-files"),g=d.attr("multiple")?1:0,h=["jpg","gif","png","jpeg","jpe"];c.context.remove(),a.each(c.result.files,function(b,c){if(c.error)alert(c.error);else{if(a.inArray(c.extension,h)>=0){var e=a.parseHTML(job_manager_ajax_file_upload.js_field_html_img);a(e).find(".job-manager-uploaded-file-preview img").attr("src",c.url)}else{var e=a.parseHTML(job_manager_ajax_file_upload.js_field_html);a(e).find(".job-manager-uploaded-file-name code").text(c.name)}a(e).find(".input-text").val(c.url),a(e).find(".input-text").attr("name","current_"+d.attr("name")),g?f.append(e):f.html(e)}}),e.find(':input[type="submit"]').removeAttr("disabled")}})})}); \ No newline at end of file diff --git a/assets/js/jquery-fileupload/jquery.fileupload.js b/assets/js/jquery-fileupload/jquery.fileupload.js index a45f18bf9..91b72546f 100755 --- a/assets/js/jquery-fileupload/jquery.fileupload.js +++ b/assets/js/jquery-fileupload/jquery.fileupload.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload Plugin 5.42.3 + * jQuery File Upload Plugin * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan @@ -277,7 +277,8 @@ // The following are jQuery ajax settings required for the file uploads: processData: false, contentType: false, - cache: false + cache: false, + timeout: 0 }, // A list of options that require reinitializing event listeners and/or @@ -983,7 +984,10 @@ fileSet, i, j = 0; - if (limitSize && (!filesLength || files[0].size === undefined)) { + if (!filesLength) { + return false; + } + if (limitSize && files[0].size === undefined) { limitSize = undefined; } if (!(options.singleFileUploads || limit || limitSize) || @@ -1042,13 +1046,19 @@ _replaceFileInput: function (data) { var input = data.fileInput, - inputClone = input.clone(true); + inputClone = input.clone(true), + restoreFocus = input.is(document.activeElement); // Add a reference for the new cloned file input to the data argument: data.fileInputClone = inputClone; $('
').append(inputClone)[0].reset(); // Detaching allows to insert the fileInput on another form // without loosing the file input value: input.after(inputClone).detach(); + // If the fileInput had focus before it was detached, + // restore focus to the inputClone. + if (restoreFocus) { + inputClone.focus(); + } // Avoid memory leaks with the detached file input: $.cleanData(input.unbind('remove')); // Replace the original file input element in the fileInput @@ -1464,4 +1474,4 @@ }); -})); \ No newline at end of file +})); diff --git a/assets/js/jquery-fileupload/jquery.iframe-transport.js b/assets/js/jquery-fileupload/jquery.iframe-transport.js index b7581f23f..a7d34e0e2 100755 --- a/assets/js/jquery-fileupload/jquery.iframe-transport.js +++ b/assets/js/jquery-fileupload/jquery.iframe-transport.js @@ -1,5 +1,5 @@ /* - * jQuery Iframe Transport Plugin 1.8.3 + * jQuery Iframe Transport Plugin * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2011, Sebastian Tschan diff --git a/readme.txt b/readme.txt index 0a38f32ac..e4fdee93e 100644 --- a/readme.txt +++ b/readme.txt @@ -146,6 +146,7 @@ You can view (and contribute) translations via the [translate.wordpress.org](htt * Fix - Handle WP 4.3 signup notification. * Fix - Map mime types to those that WordPress knows. * Fix - Alert text color. +* Tweak - Improved uploader error handling and updated library. * Tweak - Improve job_manager_user_can_post_job and job_manager_user_can_edit_job capability handling in job-submit.php * Tweak - Clear transients in batches of 500. * Tweak - Removed transifex and translations - translation will take place on https://translate.wordpress.org/projects/wp-plugins/wp-job-manager diff --git a/wp-job-manager.php b/wp-job-manager.php index c394af6ac..4608c4ad6 100644 --- a/wp-job-manager.php +++ b/wp-job-manager.php @@ -133,7 +133,7 @@ public function frontend_scripts() { if ( apply_filters( 'job_manager_ajax_file_upload_enabled', true ) ) { wp_register_script( 'jquery-iframe-transport', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.iframe-transport.js', array( 'jquery' ), '1.8.3', true ); - wp_register_script( 'jquery-fileupload', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.fileupload.js', array( 'jquery', 'jquery-iframe-transport', 'jquery-ui-widget' ), '5.42.3', true ); + wp_register_script( 'jquery-fileupload', JOB_MANAGER_PLUGIN_URL . '/assets/js/jquery-fileupload/jquery.fileupload.js', array( 'jquery', 'jquery-iframe-transport', 'jquery-ui-widget' ), '9.11.2', true ); wp_register_script( 'wp-job-manager-ajax-file-upload', JOB_MANAGER_PLUGIN_URL . '/assets/js/ajax-file-upload.min.js', array( 'jquery', 'jquery-fileupload' ), JOB_MANAGER_VERSION, true ); ob_start();