我正在使用 Aviary 在线编辑图像。通常我有一个本地文件,我可以点击、编辑和保存。
保存后,图像的src
路径会从本地“uploadedimage.jpg”更改为长的临时 URL,例如:
http://featherfiles.aviary.com/2013-07-01/kvs78lgyil6sxlc5/69318ad57a1d490d8215cc1097cf6c32.png
编辑完成后,我试图让 JavaScript 获取更新的 URL。我尝试设置“settimeout”参数,但它仍然不断获取图像的原始本地 URL。
<!-- Load Feather code -->
<script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script>
<!-- Instantiate Feather -->
<script type='text/javascript'>
var featherEditor = new Aviary.Feather({
apiKey: 'apikey',
apiVersion: 2,
tools: 'all',
appendTo: '',
onSave: function (imageID, newURL) {
var img = document.getElementById(imageID);
img.src = newURL;
setTimeout(function(){fillform()}, 5000);
},
onError: function(errorObj) {
alert(errorObj.message);
}
});
function launchEditor(id) {
featherEditor.launch({
image: id
});
return false;
}
</script>
<div id='injection_site'></div>
<%= form_for @post, :html => { :class => 'form-horizontal' } do |f| %>
<img id='image1' <%= image_tag @post.productimage_url.to_s %>
<% end %>
<!-- Add an edit button, passing the HTML id of the image and the public URL of the image -->
<p><input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' onclick="return launchEditor('image1');" /></p>
<script type="text/javascript" language="JavaScript">
var bob = document.getElementById('image1').src;
var fillform = function ()
{
setTimeout(function(){document.getElementById("textbox1").value=bob}, 3000);
}
</script>
myformfield: <input type="text" name="name_textbox" id="textbox1" />