| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | jQuery(document).on( 'click', '.wppb-rpf-add', function( event ){ |
| 5 | 5 | validate_simple_upload(); |
| 6 | 6 | }); |
| 7 | 7 | |
| 8 | - if( typeof wp.media != "undefined" ){ | |
| 8 | + if( typeof wp !== "undefined" && typeof wp.media !== "undefined" ){ | |
| 9 | 9 | // Uploading files |
| 10 | 10 | var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id |
| 11 | 11 | |
| 12 | 12 | jQuery(document).on( 'click', '.wppb_upload_button', function( event ){ |
| @@ -109,49 +109,51 @@ | ||
| 109 | 109 | // Restore the main ID when the add media button is pressed |
| 110 | 110 | jQuery('a.add_media').on('click', function() { |
| 111 | 111 | wp.media.model.settings.post.id = wp_media_post_id; |
| 112 | 112 | }); |
| 113 | + } | |
| 113 | 114 | |
| 114 | - jQuery(document).on('keypress', '.wppb-remove-upload', function(e){ | |
| 115 | - if(e.which == 13) { | |
| 116 | - jQuery(this).trigger('click'); | |
| 115 | + // Bind independently of wp.media: users without upload_files get the simple | |
| 116 | + // file input and never load the media gallery scripts. | |
| 117 | + jQuery(document).on('keypress', '.wppb-remove-upload', function(e){ | |
| 118 | + if(e.which == 13) { | |
| 119 | + jQuery(this).trigger('click'); | |
| 120 | + } | |
| 121 | + }); | |
| 122 | + | |
| 123 | + jQuery(document).on('click', '.wppb-remove-upload', function(e){ | |
| 124 | + if( confirm( 'Are you sure ?' ) ){ | |
| 125 | + /* update hidden input */ | |
| 126 | + simple_upload_button = jQuery(this).closest('li, td, p.form-row, div.form-row').find('input[type="file"]'); | |
| 127 | + if (simple_upload_button.attr('name')) { | |
| 128 | + upload_input_id = simple_upload_button.attr('name').split('_').slice(2).join('_'); | |
| 129 | + upload_input_id = upload_input_id.split('-').join('_'); | |
| 130 | + upload_input = jQuery("#" + upload_input_id); | |
| 117 | 131 | } |
| 118 | - }); | |
| 132 | + else{ | |
| 133 | + upload_input = jQuery(this).closest('li, td, p.form-row, div.form-row').find('input[type="hidden"]'); | |
| 134 | + } | |
| 135 | + removedAttachement = jQuery(this).parent().parent('.upload-field-details').data('attachment_id'); | |
| 136 | + uploadAttachemnts = upload_input.val(); | |
| 137 | + uploadAttachemntsArray = uploadAttachemnts.split(','); | |
| 138 | + newuploadAttachments = []; | |
| 139 | + for (var i = 0; i < uploadAttachemntsArray.length; i++) { | |
| 140 | + if (uploadAttachemntsArray[i] != removedAttachement) | |
| 141 | + newuploadAttachments.push(uploadAttachemntsArray[i]); | |
| 142 | + } | |
| 143 | + newuploadAttachments = newuploadAttachments.join(','); | |
| 144 | + upload_input.val(newuploadAttachments); | |
| 119 | 145 | |
| 120 | - jQuery(document).on('click', '.wppb-remove-upload', function(e){ | |
| 121 | - if( confirm( 'Are you sure ?' ) ){ | |
| 122 | - /* update hidden input */ | |
| 123 | - simple_upload_button = jQuery(this).closest('li, td, p.form-row, div.form-row').find('input[type="file"]'); | |
| 124 | - if (simple_upload_button.attr('name')) { | |
| 125 | - upload_input_id = simple_upload_button.attr('name').split('_').slice(2).join('_'); | |
| 126 | - upload_input_id = upload_input_id.split('-').join('_'); | |
| 127 | - upload_input = jQuery("#" + upload_input_id); | |
| 128 | - } | |
| 129 | - else{ | |
| 130 | - upload_input = jQuery(this).closest('li, td, p.form-row, div.form-row').find('input[type="hidden"]'); | |
| 131 | - } | |
| 132 | - removedAttachement = jQuery(this).parent().parent('.upload-field-details').data('attachment_id'); | |
| 133 | - uploadAttachemnts = upload_input.val(); | |
| 134 | - uploadAttachemntsArray = uploadAttachemnts.split(','); | |
| 135 | - newuploadAttachments = []; | |
| 136 | - for (var i = 0; i < uploadAttachemntsArray.length; i++) { | |
| 137 | - if (uploadAttachemntsArray[i] != removedAttachement) | |
| 138 | - newuploadAttachments.push(uploadAttachemntsArray[i]); | |
| 139 | - } | |
| 140 | - newuploadAttachments = newuploadAttachments.join(','); | |
| 141 | - upload_input.val(newuploadAttachments); | |
| 146 | + /* remove the attachment details */ | |
| 147 | + jQuery(this).parent().parent('.upload-field-details').next('a').show(); | |
| 148 | + simple_upload_button.show(); | |
| 149 | + simple_upload_button.val(''); | |
| 150 | + jQuery(this).parent().parent('.upload-field-details').remove(); | |
| 142 | 151 | |
| 143 | - /* remove the attachment details */ | |
| 144 | - jQuery(this).parent().parent('.upload-field-details').next('a').show(); | |
| 145 | - simple_upload_button.show(); | |
| 146 | - simple_upload_button.val(''); | |
| 147 | - jQuery(this).parent().parent('.upload-field-details').remove(); | |
| 152 | + jQuery(document).trigger( 'wppb_removed_uploaded_file' ) | |
| 148 | 153 | |
| 149 | - jQuery(document).trigger( 'wppb_removed_uploaded_file' ) | |
| 150 | - | |
| 151 | - } | |
| 152 | - }); | |
| 153 | - } | |
| 154 | + } | |
| 155 | + }); | |
| 154 | 156 | }); |
| 155 | 157 | |
| 156 | 158 | function validate_simple_upload(){ |
| 157 | 159 | jQuery("input:file").on('change', function(e){ |