Finalize media upload javascripts

This commit is contained in:
Jay Wood
2016-09-30 12:02:31 -04:00
parent c895896915
commit e300d0888a
2 changed files with 36 additions and 9 deletions

View File

@ -14,25 +14,52 @@ window.cwv2Admin = {};
app.cache = function() { app.cache = function() {
app.$c = { app.$c = {
window: $(window), window: $(window),
// fooSelector: $( '.foo' ), imgUploadBtn: $( '.upload_image_button' ),
}; };
}; };
// Combine all events // Combine all events
app.bindEvents = function() { app.bindEvents = function() {
// app.$c.window.on( 'load', app.doFoo ); app.$c.imgUploadBtn.on( 'click', app.handleImageUploader );
}; };
// Do we meet the requirements? // Do we meet the requirements?
app.meetsRequirements = function() { app.meetsRequirements = function() {
// Basically check return app.$c.imgUploadBtn.length;
// return app.$c.fooSelector.length;
}; };
// Some function /**
// app.doFoo = function() { * Handles Media Uploads
// do stuff *
// }; * @returns {boolean}
*/
app.handleImageUploader = function() {
var btnObj = $( this );
window.uploadID = btnObj.data( 'target-id' );
if ( window.file_frame ) {
window.file_frame.open();
return true;
}
window.file_frame = wp.media.frames.file_frame = wp.media( {
title: btnObj.data( 'uploader-title' ),
button: {
text: btnObj.data( 'uploader-btn-txt' )
},
multiple: false,
} );
window.file_frame.on( 'select', function() {
var attachment = window.file_frame.state().get( 'selection' ).first().toJSON();
$( '#' + window.uploadID ).val( attachment.url );
window.console.log( attachment );
});
window.file_frame.open();
};
// Engage // Engage
$( app.init ); $( app.init );

2
js/admin.min.js vendored
View File

@ -1 +1 @@
window.cwv2Admin={},function(window,$,app){app.init=function(){app.cache(),app.meetsRequirements()&&app.bindEvents()},app.cache=function(){app.$c={window:$(window)}},app.bindEvents=function(){},app.meetsRequirements=function(){},$(app.init)}(window,jQuery,window.cwv2Admin); window.cwv2Admin={},function(window,$,app){app.init=function(){app.cache(),app.meetsRequirements()&&app.bindEvents()},app.cache=function(){app.$c={window:$(window),imgUploadBtn:$(".upload_image_button")}},app.bindEvents=function(){app.$c.imgUploadBtn.on("click",app.handleImageUploader)},app.meetsRequirements=function(){return app.$c.imgUploadBtn.length},app.handleImageUploader=function(){var btnObj=$(this);return window.uploadID=btnObj.data("target-id"),window.file_frame?(window.file_frame.open(),!0):(window.file_frame=wp.media.frames.file_frame=wp.media({title:btnObj.data("uploader-title"),button:{text:btnObj.data("uploader-btn-txt")},multiple:!1}),window.file_frame.on("select",function(){var attachment=window.file_frame.state().get("selection").first().toJSON();$("#"+window.uploadID).val(attachment.url),window.console.log(attachment)}),void window.file_frame.open())},$(app.init)}(window,jQuery,window.cwv2Admin);