Finalize media upload javascripts
This commit is contained in:
43
js/admin.js
43
js/admin.js
@ -14,25 +14,52 @@ window.cwv2Admin = {};
|
||||
app.cache = function() {
|
||||
app.$c = {
|
||||
window: $(window),
|
||||
// fooSelector: $( '.foo' ),
|
||||
imgUploadBtn: $( '.upload_image_button' ),
|
||||
};
|
||||
};
|
||||
|
||||
// Combine all events
|
||||
app.bindEvents = function() {
|
||||
// app.$c.window.on( 'load', app.doFoo );
|
||||
app.$c.imgUploadBtn.on( 'click', app.handleImageUploader );
|
||||
};
|
||||
|
||||
// Do we meet the requirements?
|
||||
app.meetsRequirements = function() {
|
||||
// Basically check
|
||||
// return app.$c.fooSelector.length;
|
||||
return app.$c.imgUploadBtn.length;
|
||||
};
|
||||
|
||||
// Some function
|
||||
// app.doFoo = function() {
|
||||
// do stuff
|
||||
// };
|
||||
/**
|
||||
* Handles Media Uploads
|
||||
*
|
||||
* @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
|
||||
$( app.init );
|
||||
|
2
js/admin.min.js
vendored
2
js/admin.min.js
vendored
@ -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);
|
Reference in New Issue
Block a user