mythofechelon
mythofechelon

Reputation: 3782

ZeroClipboard just isn't working

Originally, this post was regarding my attempts to inject ZeroClipboard into web pages by and for use by my Chrome extension, but I've dumbed the scenario down and down and down in a seemingly futile attempt to identify the issue and I still can't get it to work.

I'm even having difficulty getting the actual, documented "Minimal Example" on ZeroClipboard's own GitHub to work (admittedly, I've modded the source to actually be HTML5-valid, but the exact original didn't work either). Even test.html, which is included in the tar.gz archive, doesn't work!

"Minimal Example": Code

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    </head>
    <body>
        <input type="button" id="d_clip_button" data-clipboard-text="Copy Me!" value="Copy To Clipboard" />
        <script src="ZeroClipboard.js"></script>
        <script>
            var clip = new ZeroClipboard( document.getElementById('d_clip_button') );
        </script>
    </body>
</html>

"Minimal Example": Console Output

Uncaught TypeError: object is not a function  index.html:11

Info

 

Either I'm missing something really, really obvious here or ZeroClipboard's documentation / functionality is abysmal.

Upvotes: 5

Views: 12201

Answers (5)

user3559718
user3559718

Reputation: 81

Try the 2.2.1-dev version: http://datatables.net/download/build/dataTables.tableTools.nightly.js?_=60133663e907c73303e914416ea258d8 I think it should be resolve there. I would also point out that new $.fn.dataTable.TableTools(...) is now the preferred form. The TableTools global is still in 2.2.x, but will be removed in 2.3+.

Upvotes: 0

mLar
mLar

Reputation: 3067

you will need to specify the path to the swf file :

 var clip = new ZeroClipboard( document.getElementById('d_clip_button'),{moviePath: "/path/ZeroClipboard.swf"} );

Upvotes: 1

Nicolas BADIA
Nicolas BADIA

Reputation: 5852

For me, the problem was that the variable module was already defined by the framework I use and not meant to be use like ZeroClipboard do. In fact, if you look at the end of the ZeroClipboard.js file, here is what you can see:

  if (typeof module !== "undefined") {
    module.exports = ZeroClipboard;
  } else if (typeof define === "function" && define.amd) {
    define(function() {
      return ZeroClipboard;
    });
  } else {
    window.ZeroClipboard = ZeroClipboard;
  }

I just replaced this by the following code to fix the issue:

window.ZeroClipboard = ZeroClipboard;

Upvotes: 0

Uwe Keim
Uwe Keim

Reputation: 40736

What I've just found out:

That didn't match. I've got a similar error than the original poster of this question.

After I used the example from GitHub I've succeeded.

Conclusion:

Either use both the example and download from Google Code or (which I would prefer), both the example and download from GitHub.

Upvotes: 2

Jay
Jay

Reputation: 4686

For loading an external script, inserting a SCRIPT element into the page body will not immediately load and execute the script. The appendChild will return immediately, and the script will be loaded after the current script execution returns from all functions and goes into idle state.

For this, the SCRIPT element's onload property can be used to execute a code once the external script is loaded.

function inject_zeroClipboard(){
    var path_Root_zeroClipboard = chrome.extension.getURL("plugins/zeroClipboard");
    var element_Head = document.getElementsByTagName('head')[0];
    var element_zeroClipboard = document.createElement("script");
    element_zeroClipboard.src = path_Root_zeroClipboard + "/ZeroClipboard.js";

    element_zeroClipboard.onload = function() {
        ZeroClipboard.setMoviePath(path_Root_zeroClipboard + "/ZeroClipboard10.swf");
        var clip = new ZeroClipboard.Client();
        clip.glue("element_Example");
        clip.addEventListener("click", function(){
            clip.setText(data_Example);
        });
    };

    element_Head.appendChild(element_zeroClipboard);
}

Upvotes: -1

Related Questions