Adding a view to wp.media modal & getting back to gallery view

Question

I am trying to add a new view to wp.media modal. Once I finish working on the view, I should be able to get back to the gallery view on a button click. I have failed to find any proper documentation of wp.media.

So far I was able to create backbone template and parse it into html. I can use js to insert html into the media modal but that doesn’t use the wp.media api.

Below is the JS I have written.


function render(data){
        var container = $('body .media-modal-content .media-frame-content')[0];
        var template = wp.template('wmgtpanel');
        var html = template(data);
        container.innerHTML = html;
    }

$(document).ready(function(){
        $('body').on('click', '.wmgt-edit', function(e) {
            e.preventDefault();
            
            container = $('body .media-modal-content .media-frame-content')[0];
            var $this = $(this);
            var id = $this.attr('data-id');
            var promise = wp.ajax.post('wmgt-media-details', {id: id});
    
            render({loading: true});
    
            promise.done(function(data){
                render(data);
                initMap();
            });
    
            promise.fail(function(xhr, textStatus, errorThrown){
                render({error: errorThrown});
            });


        });

        
    });

ss1

ss2

With this JS I was able to insert rendered html into the modal by replacing the existing html. But once I am done with my work. I need to get back to the previous gallery state. Which I am unable to do.

Also this method is not uses wp.media api, it just parse the template and replaces html. I would like to use existing api if possible.

0
Sisir 4 months 0 Answers 12 views 0

Leave an answer