In my CakePHP application, I have a view with this markup:
<div class="copy" id="share-copy"></div>
<input type="text" value="http://site.com/v/<?php echo $imageInfo[0]['Image']['hash']; ?>" name="share" />
The share-copy
DIV is a little 16x16 div that houses the flash element for zClip. I'm using zClip like this:
$('#share-copy').zclip({
path: '/swf/ZeroClipboard.swf',
copy: $('input[name="share"]').val(),
afterCopy: function(){}
});
Now, it successfully copies the text in the input element named share
. However, when I change the text in that input element using jQuery like this:
$('input[name="share"]').attr('value', 'something');
and click zClip again, it doesn't copy the new value. How can I get zClip to copy exactly what's inside the share
input at the time of clicking?
The problem is that
$('#share-copy').zclip({
path: '/swf/ZeroClipboard.swf',
copy: $('input[name="share"]').val(),
afterCopy: function(){}
});
creates an object:
{path: '/swf/ZeroClipboard.swf', copy: $('input[name="share"]').val(), afterCopy: function(){}}
And the value of property copy
is set when the object is created, so it doesn't update.
I guess we can solve it using a function:
$('#share-copy').zclip({
path: '/swf/ZeroClipboard.swf',
copy: function(){return $('input[name="share"]').val();},
afterCopy: function(){}
});