Numerous elements

I am having trouble creating multiple instances of a Zeroclipboard instance in my code, with each instance launching a popup after calling it.

<a class="xxx" href="popup.url.php" ><span >FRSDE3RD</a>
<a class="xxx" href="popup.url2.php" ><span >FRSDE3RD2</a>
<a class="xxx" href="popup.url3.php" ><span >FRSDE3RD3</a>
$(document).ready(function(){
    ZeroClipboard.setMoviePath( 'path/to/swf/ZeroClipboard.swf' );
    // setup single ZeroClipboard object for all our elements
    clip = new ZeroClipboard.Client();
    clip.setHandCursor( true );

    // assign a common mouseover function for all elements using jQuery
    $('a.xxx').mouseover( function() {
        // set the clip text to our innerHTML
        var url = $(this).attr("href");
        var code = $(this).children('span').html();
        clip.setText( $(this).children('span').html() );//this.innerHTML );

        clip.glue(this);
        clip.addEventListener('onMouseDown', function(){
            clip.reposition(this);
            clip.setText( code );
        });

        clip.addEventListener('onComplete', function(){ 
            clip.reposition(this);
            popUp(url);
        }); 


    });
});

function popUp(URL)
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=1024,height=768,left = 328,top = 141');");
}

I managed to create a copy in the functionality of the clipboard, but if I use onMouseUp, the onComplete events to trigger the pop-up function, it either fires like 4-5 pop-ups, or it doesn't fire at all.

PS I tried to adapt the solution from How to upload an Ajax response to the clipboard using jQuery and ZeroClipboard? instead of calling ajax, just copying it to the clipboard and in full screen mode a popup ... as I said, it did not work for me.

, flashblocker, , , CODE, , , 3-4, . , . ?

+3
3

:

$("a.xxx").each(function() {
  //Create a new clipboard client
  var clip = new ZeroClipboard.Client();
  clip.setHandCursor( true );

  //Glue the clipboard client to the last td in each row
  clip.glue(this);

  var url = $(this).attr("href");
  //Grab the text from the parent row of the icon
  var code = $(this).children('span').html();    
  clip.setText(code);

  //Add a complete event to let the user know the text was copied
  clip.addEventListener('complete', function(client, text) {
    //alert("Copied text to clipboard:\n" + text);
    popUp(url);
  });
});

, - .

+14

http://www.steamdev.com/zclip/, jquery, return.

jquery.zclip.js ZeroClipboard.swf

:

$(".class-to-copy").zclip({
    path: "assets/js/ZeroClipboard.swf",
    copy: function(){
        return $(this).attr("data-attribute-with-text-to-copy");
    }
});

, SWF.

0

What Andrei S answered is out of date. Just do it as follows.

<a id="test1" class="test" href="#"  data-clipboard-text="1">111</a>
<a id="test2" class="test" href="#"  data-clipboard-text="2">111</a>
<a id="test3" class="test" href="#"  data-clipboard-text="3">111</a>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="dist1/ZeroClipboard.js"></script>
<script>
var client = new ZeroClipboard( );
client.clip($(".test"));

client.on( "ready", function( readyEvent ) {
  client.on( "aftercopy", function( event ) {
    alert("Copied text to clipboard: " + event.data["text/plain"] );
  } );
});

</script>
0
source

Source: https://habr.com/ru/post/1730342/


All Articles