vlady
vlady

Reputation: 600

jQuery zClip isn't copying values to the clipboard

<script type="text/javascript">
jQuery(function() {
    jQuery(".process").click(function() {

    var enter = $(".enter").val();
    out = parseFloat(enter) + Math.floor((Math.random()*10)+1);

    $('.enter').attr("value", out);

    $('.process').fadeOut(0);
    $('.copy').fadeIn(0);

    });
});

jQuery(function() {
    jQuery(".copy").click(function() {

    $(".copy").zclip({
        path:'js/ZeroClipboard.swf',
        copy:function() { return $(".enter").val(); },
        afterCopy: afterCopy()
    });

    function afterCopy() {
        $(".enter").val('');
        $('.copy').fadeOut(0);
        $('.process').fadeIn(0);
    }

    });
});
</script>

<form class="form-wrapper cf" action="">
    <span>Enter A Number</span> <br />
    <input type="text" class="enter" size="15" />
    <button type="button" class="process">process</button>
    <button type="button" class="copy" style="display:none;">copy</button>
</form>

jQuery zClip plugin don't works in my code.

I want to copy the value resulting from first function [ jQuery(".process").click(function() ] several times as a loop.

jsFiddle: http://jsfiddle.net/npYBm/

Plugin page: http://www.steamdev.com/zclip/

Any solution ? Thanks.

Problem Solved

Upvotes: 1

Views: 4875

Answers (2)

Thomas
Thomas

Reputation: 8849

  1. You're copying the value of a non existent '.link' element
  2. fadeOut(0) is the same as hide()
  3. The object must be visible on load
  4. As I see it zCopy adds a click event so assigning it inside a click event is redundant

This version works but I'm not quite sure exactly why.

Upvotes: 0

Matt
Matt

Reputation: 1973

Try this,

HTML

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>

<script type="text/javascript" src="http://www.steamdev.com/zclip/js/jquery.zclip.min.js"></script>

<form class="form-wrapper cf" action="">
    <span>Enter A Number</span> <br />
    <input type="text" class="enter" size="15" />
    <a class="" id="copy-button" href="#">Copy</a>
</form>

Script

jQuery(function() {

    $("#copy-button").zclip({
        path:'http://zeroclipboard.googlecode.com/svn-history/r10/trunk/ZeroClipboard.swf',
        copy:function() {return $(".enter").val(); }
    });
});

The problem was you were placing zClip function inside click event. That is not required.

If you right click the 'copy' anchor tag, you can see flash is attached to it. I think its not happening in the case of input type submit button. That was another problem.

Upvotes: 1

Related Questions