| 1 |
jQuery( function($) { |
| 2 |
|
| 3 |
function fv_flowplayer_s3_browser_load_assets(bucket, path) { |
| 4 |
var |
| 5 |
$this = jQuery(this), |
| 6 |
$media_frame_content = jQuery('.media-frame-content:visible'), |
| 7 |
$overlay_div = jQuery('#fv-player-shortcode-editor-preview-spinner').clone().css({ |
| 8 |
'height' : '100%' |
| 9 |
}), |
| 10 |
ajax_data = { |
| 11 |
action: "load_s3_assets", |
| 12 |
nonce: window.flowplayer_aws_s3.nonce |
| 13 |
}; |
| 14 |
|
| 15 |
$this.addClass('active').siblings().removeClass('active'); |
| 16 |
|
| 17 |
// replace content by the new S3 content |
| 18 |
$media_frame_content.html($overlay_div); |
| 19 |
|
| 20 |
if (typeof bucket === 'string' && bucket) { |
| 21 |
ajax_data['bucket'] = bucket; |
| 22 |
} |
| 23 |
if (typeof path === 'string' && path) { |
| 24 |
ajax_data['path'] = path; |
| 25 |
} |
| 26 |
|
| 27 |
jQuery.post(window.fv_flowplayer_browser.ajaxurl, ajax_data, function(ret) { |
| 28 |
var |
| 29 |
renderOptions = { |
| 30 |
'dropdownItems' : [], |
| 31 |
'dropDownNoOptionEnabledWarningMsg' : '<strong>You have no S3 buckets configured <a href="admin.php?page=fvplayer#postbox-container-tab_hosting">in settings</a> or none of them has complete settings (region, key ID and secret key).</strong>', |
| 32 |
'dropdownItemSelected' : ret.active_bucket_id |
| 33 |
}; |
| 34 |
|
| 35 |
// fill dropdown options |
| 36 |
for (var i in ret.buckets) { |
| 37 |
renderOptions.dropdownItems.push({ |
| 38 |
'value' : ret.buckets[i].id, |
| 39 |
'text' : ret.buckets[i].name |
| 40 |
}); |
| 41 |
} |
| 42 |
|
| 43 |
// add errors, if any |
| 44 |
if (ret.err) { |
| 45 |
renderOptions['errorMsg'] = ret.err; |
| 46 |
} |
| 47 |
|
| 48 |
$media_frame_content.html( renderBrowserPlaceholderHTML(renderOptions) ); |
| 49 |
|
| 50 |
// hide search, as it's not supported for AWS |
| 51 |
jQuery('#media-search-input').parent().hide(); |
| 52 |
|
| 53 |
jQuery('#browser-dropdown').on('change', function() { |
| 54 |
if (this.value >= 0) { |
| 55 |
// disable Choose button |
| 56 |
jQuery('.media-button-select').prop('disabled', 'disabled'); |
| 57 |
// load bucket contents |
| 58 |
fv_flowplayer_s3_browser_load_assets(this.value); |
| 59 |
} else { |
| 60 |
var $err_div = jQuery('.filemanager .errors'); |
| 61 |
|
| 62 |
if (!$err_div.length) { |
| 63 |
$err_div = jQuery('<div class="errors"></div>'); |
| 64 |
$err_div.insertBefore(jQuery('.filemanager .search')); |
| 65 |
$err_div.after('<hr /><br />'); |
| 66 |
} |
| 67 |
|
| 68 |
$err_div.html('<strong>Bucket is missing settings. Please make sure you assigned region, key ID and secret key to this bucket.</strong>'); |
| 69 |
return false; |
| 70 |
} |
| 71 |
}); |
| 72 |
|
| 73 |
fv_flowplayer_browser_browse( ret.items, { 'breadcrumbs' : true } ); |
| 74 |
} ); |
| 75 |
|
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
$( document ).on( "mediaBrowserOpen", function(event) { |
| 80 |
fv_flowplayer_media_browser_add_tab('fv_flowplayer_s3_browser_media_tab', 'Amazon S3', fv_flowplayer_s3_browser_load_assets); |
| 81 |
}); |
| 82 |
}); |
| 83 |
|