Skip to content

Instantly share code, notes, and snippets.

@diegoliv
Created March 21, 2014 13:04
Show Gist options
  • Save diegoliv/9685733 to your computer and use it in GitHub Desktop.
Save diegoliv/9685733 to your computer and use it in GitHub Desktop.
Checando o evento 'close' do wp.media (versão 3.6+) / Checking the 'close' event of wp.media (version 3.6+)
//se o frame já existe, abre-o novamente
if ( typeof( custom_uploader ) !== "undefined" ) {
custom_uploader.close();
}
//Cria o frame da janela de mídia
var custom_uploader = wp.media.frames.customHeader = wp.media({
title: "Select An Image",
library: {
type: 'image'
},
button: {
text: "insert image"
},
});
//callback quando seleciona uma imagem
custom_uploader.on( 'select', function() {
console.log( 'selected an image' );
});
//callback quando fecha a janela - seja através do botão "fechar" ou usando a tecla "ESC"
custom_uploader.on( 'close', function(){
console.log( 'close modal' );
} );
//Abre a janela de mídia
custom_uploader.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment