JQuery get an image url with execCommand('InsertImage',true);
having some trouble with this - for some reason - prob. just me NE how what I need to do for a very basic RTE is grab an image url from some form of popup preferably a modal with an input field for the url that then uses execCommand('InsertImage'); to put the image into an editable div - the RTE is using an editable div in an iframe not a textarea.
If not clear this is the "route"
- click on "image" button in the RTE menu
- This opens a modal (JQuery)
- The modal is populated with thumbnails
- User clicks on thumbnail Click sets the value of a hidden input field (JQuery)
- User clicks a submit button (on the modal) that then triggers the execCommand('InsertImage') command.
so I guess my code would be something like: (pre wrapped with doc.ready etc.)
$('#getimagemodal').live('click',function(){
$('#imagemodal').fadeIn('slow').load('imagethumbs.php', function(){
$('.imageclass').live('click',function(){
$('#imageinput').val($(this).attr('src'));
$('#setimage').live('click',function(){
document.getElementById("fraRTE").contentWindow.document.execCommand('InsertImage',true,$('#imageinput').val(); )
});
});
})开发者_开发知识库;
}
But I am not sure and I cannot get the image src to transfer. Suggestions please Thanks in
Oh - it is being done this way as a user has a pre-existing image library not on the main server so imagethumbs.php will load the image thumbs via the library API. I ned the "clck action" rather than just a "insert src" type prompt.
OK got it to work like this:
$('#getimagemodal').live('click',function(){
$('#imagemodal').fadeIn('slow').load('../admin/imagethumbs.php', function(){
$('.imageclass').live('click',function(){
$('#imageinput').val($(this).attr('src'));
$('#setimage').live('click',function(){
var img = $('#imageinput').val();
$('#imageinput').val();
addImage(img);
$('#imagemodal').fadeOut('slow').empty();
return false;
});
});
});
});
精彩评论