jQuery(document).ready(function($){ //alert('we are ready'); var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment; $('.uploader .button').click(function(e) { //alert('clicked me'); var send_attachment_bkp = wp.media.editor.send.attachment; var button = $(this); var id = button.attr('id').replace('_button', ''); _custom_media = true; wp.media.editor.send.attachment = function(props, attachment){ if ( _custom_media ) { $("#url_"+id).val(attachment.url); $("#id_"+id).val(attachment.id); $("#img_"+id).attr('src', attachment.url).hide().fadeIn(500); } else { return _orig_send_attachment.apply( this, [props, attachment] ); }; } wp.media.editor.open(button); return false; }); $('.add_media').on('click', function(){ _custom_media = false; }); // commen image jQuery('.theme_pages .regular-image').each(function(index, element) { var imgSrc = jQuery(this).attr('src') if(imgSrc == '') { jQuery(this).hide(); } }); /* menu script */ jQuery('.theme_pages > div').eq(0).fadeIn(500); jQuery('.theme_menu li').eq(0).addClass('active'); jQuery('.theme_menu li').click(function(){ jQuery(this).addClass('active').siblings('li').removeClass('active'); var tabOn = jQuery('.theme_menu li').index(this); jQuery('.theme_pages > div').hide(); jQuery('.theme_pages > div').eq(tabOn).fadeIn(500); }); $('.gallery_uploader .button').click(function(e) { //alert('clicked me'); var send_attachment_bkp = wp.media.editor.send.attachment; var button = $(this); var id = button.attr('id').replace('_button', ''); _custom_media = true; wp.media.editor.send.attachment = function(props, attachment){ if ( _custom_media ) { jQuery("#ft_images").append('

  • '+attachment.description+'
    Delete
  • '); } else { return _orig_send_attachment.apply( this, [props, attachment] ); }; } wp.media.editor.open(button); return false; }); $('.add_media').on('click', function(){ _custom_media = false; }); });