Created
May 23, 2015 18:38
-
-
Save pingram3541/f35e9fd738aa59de45cc to your computer and use it in GitHub Desktop.
BeTheme Muffin Options - Upload Field - Src Path to Relative URL - older wp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MfnUpload(){ | |
(function($) { | |
var header_clicked = false; | |
var item_clicked = ''; | |
jQuery("img[src='']").attr("src", mfn_upload.url); | |
jQuery('.mfn-opts-upload').click(function() { | |
item_clicked = jQuery(this); | |
header_clicked = true; | |
formfield = jQuery(this).attr('rel-id'); | |
preview = jQuery(this).prev('img'); | |
tb_show('', 'media-upload.php?type=image&post_id=0&TB_iframe=true'); | |
return false; | |
}); | |
// Store original function | |
window.original_send_to_editor = window.send_to_editor; | |
window.send_to_editor = function(html) { | |
if (header_clicked) { | |
imgurl = jQuery('img',html).attr('src'); | |
//convert url to relative path | |
var el = document.createElement('a'); | |
el.href = imgurl; //use el.pathname | |
jQuery(item_clicked).siblings('input').val(el.pathname); | |
jQuery(item_clicked).siblings('.mfn-opts-upload-remove').fadeIn('slow'); | |
jQuery(item_clicked).hide(); | |
jQuery(preview).attr('src' , el.pathname).fadeIn('slow'); | |
tb_remove(); | |
header_clicked = false; | |
} else { | |
window.original_send_to_editor(html); | |
} | |
} | |
jQuery('.mfn-opts-upload-remove').click(function(){ | |
jQuery(this).siblings('input').val(''); | |
jQuery(this).prev().fadeIn('slow'); | |
jQuery(this).prev().prev().fadeOut('slow', function(){jQuery(this).attr("src", mfn_upload.url);}); | |
jQuery(this).fadeOut('slow'); | |
}); | |
})(jQuery); | |
} | |
jQuery(document).ready(function($){ | |
var mfn_upload = new MfnUpload(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment