Open Select File Dialog Box When Opening WP Media Uploader
Question
In front end i have button to upload image. I am trying to open select file dialog box when opening an Wp media dialog box through jQuery. This code works fine when we click button second time. But not working when we click the button first time. I think issue is because of AJAX request, As may be code executed when all content not loaded on page. What modification should i do on below code.
$('.wpfepp-thumbnail-link').click(function(e)
{
e.preventDefault();
var clicked = $(this);
custom_uploader = wp.media.frames.file_frame = wp.media({
title: wpfepp.chooseimg,
button: {
text: wpfepp.chooseimg
},
multiple: false
});
custom_uploader.on('select', function() {
attachment =
custom_uploader.state().get('selection').first().toJSON();
wpfepp_forms.get( $(clicked).closest('.wpfepp-form') ).load_thumb(attachment.id);
});
/* Code to trigger click for Select file dialog box*/
if(custom_uploader.open())
{
jQuery(".button-hero").trigger('click');
}
});
0
ajax, jquery, media, uploads
3 years
2019-10-29T11:10:54-05:00
2019-10-29T11:10:54-05:00 0 Answers
78 views
0
Leave an answer