Skip to content

Commit

Permalink
Merge pull request #280 from TheCraigHewitt/release/1.19.6
Browse files Browse the repository at this point in the history
Release/1.19.6
  • Loading branch information
jonathanbossenger authored Mar 9, 2018
2 parents dbe7a5f + 0b6e77b commit 720328e
Show file tree
Hide file tree
Showing 15 changed files with 462 additions and 145 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
log
8 changes: 8 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ textarea#episode_embed_code {

.ssp-episode-details-label {
font-weight: bold;
}

#series_image_preview {
max-width: 160px;
}

#series_upload_image_button .dashicons {
vertical-align: middle;
}
2 changes: 1 addition & 1 deletion assets/css/admin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added assets/images/no-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 58 additions & 1 deletion assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
jQuery(document).ready(function($) {

// Uploading files
var file_frame;
var file_frame, series_img_frame;

jQuery.fn.ssp_upload_media_file = function( button, preview_media ) {
var button_id = button.attr('id');
Expand Down Expand Up @@ -41,6 +41,63 @@ jQuery(document).ready(function($) {
file_frame.open();
};

/* Add/Edit Series Image */
jQuery('#series_upload_image_button').click(function( event ){
event.preventDefault();
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(this);
var button_id = button.attr('id');
var preview_id = button_id.replace( '_upload', '' ).replace( '_button', '_preview' );
var field_id = button_id.replace( '_upload', '' ).replace( '_button', '_id' );

// If the media frame already exists, reopen it.
if ( series_img_frame ) {
series_img_frame.open();
return;
}

// Create the media frame.
series_img_frame = wp.media({
title: jQuery( this ).data( 'uploader_title' ),
button: {
text: jQuery( this ).data( 'uploader_button_text' ),
},
library: {
type: [ 'image' ]
},
multiple: false
});

series_img_frame.on( 'select', function() {
// Get media attachment details from the frame state
var attachment = series_img_frame.state().get('selection').first().toJSON();

// Send the attachment URL to our custom image input field.
$('#' + preview_id).attr('src', attachment.url);

// Send the attachment id to our hidden input
$('#' + field_id).val(attachment.id);
});

// Finally, open the modal on click
series_img_frame.open();
});

/* Remove/clear Series Image */
jQuery('#series_remove_image_button').click(function( event ){
event.preventDefault();
var button = $(this);
var button_id = button.attr('id');
var preview_id = button_id.replace( '_remove', '' ).replace( '_button', '_preview' );
var field_id = button_id.replace( '_remove', '' ).replace( '_button', '_id' );

if ( confirm('Are you sure?') ) {
var src = $('#' + preview_id).attr('data-src');
$('#' + preview_id).attr('src', src);
$('#' + field_id).val('');
}
});

/* ADD/EDIT EPISODE */

jQuery('#upload_audio_file_button').click(function( event ){
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions assets/js/fileupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ jQuery( document ).ready( function ( $ ) {
return isValid;
}

function sanitizeName(name) {
var punctuationlessName = name.replace(/[,\/#!$%\^&\*;:{}=\-_`'~()+"|? ]/g," ");
return punctuationlessName.replace(/\s{1,}/g,"-");
}

/**
* Of the upload_credentials object isn't available
*/
Expand All @@ -47,9 +52,6 @@ jQuery( document ).ready( function ( $ ) {
var bucket = upload_credentials.bucket;
var show_slug = upload_credentials.show_slug;
var episodes_url = upload_credentials.episodes_url;
var access_key_id = upload_credentials.access_key_id;
var policy = upload_credentials.policy;
var signature = upload_credentials.signature;

/**
* Creates instance of plupload
Expand All @@ -61,15 +63,7 @@ jQuery( document ).ready( function ( $ ) {
multi_selection: false,
container: 'ssp_upload_container',
url: 'https://' + bucket + '.s3.amazonaws.com:443/',
multipart_params: {
'key': show_slug + '/${filename}',
'Filename': show_slug + '/${filename}',
'acl': 'public-read',
'Content-Type': '',
'AWSAccessKeyId': access_key_id,
'policy': policy,
'signature': signature
}
multipart_params: {}
} );

/**
Expand Down Expand Up @@ -98,6 +92,23 @@ jQuery( document ).ready( function ( $ ) {
}
} );

/**
* Sanatizes the file name for upload
*/
uploader.bind('BeforeUpload', function (up, file) {
var file_name = sanitizeName(file.name);
var multipart_params = {
'key': upload_credentials.show_slug + '/' + file_name,
'Filename': upload_credentials.show_slug + '/' + file_name,
'acl': 'public-read',
'Content-Type': '',
'AWSAccessKeyId': upload_credentials.access_key_id,
'policy': upload_credentials.policy,
'signature': upload_credentials.signature
}
uploader.settings.multipart_params = multipart_params;
});

/**
* Show an error if anything goes wrong
*/
Expand All @@ -121,10 +132,11 @@ jQuery( document ).ready( function ( $ ) {

// we're only expecting one file to be uploaded
var file = files[ 0 ];
var file_name = sanitizeName(file.name);
var filesize_raw = file.size;
var file_size = plupload.formatSize(file.size);
var uploaded_file = 'https://s3.amazonaws.com/' + bucket + '/' + show_slug + '/' + file.name;
var episode_file = episodes_url + show_slug + '/' + file.name;
var uploaded_file = 'https://s3.amazonaws.com/' + bucket + '/' + show_slug + '/' + file_name;
var episode_file = episodes_url + show_slug + '/' + file_name;

// push podmotor_file_path to wp_ajax_ssp_store_podmotor_file
$.ajax( {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/fileupload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 720328e

Please sign in to comment.