cancel
Showing results for 
Search instead for 
Did you mean: 

Add event listener to custom action

michaelp
Confirmed Champ
Confirmed Champ
Hi guys,

I am looking for the right javascript file in which the actions are created for each node presented in the document library.

What I want to do: for each action "custom copy" on the document library I want to add an event listener like:


var newEventListenerX = new zcProto(YUI-ID, record.jsNode.nodeRef);

// Prototype
function zcProto(id, link) {
   this.id = id;
   this.link = link;
   var zclip = new ZeroClipboard(document.getElementById(id));
   zclip.on("ready", function() {
      zclip.on("aftercopy", function(event) {
      });
   });
   zclip.on("copy", function (event) {
      var clipboard = event.clipboardData;
      clipboard.setData("text/plain", link);
   });
}


The listeners should always be unique because on every node the "custom copy" action should copy another string (like the nodeRef of the node).

Can someone tell me the right place where I can add the listeners during the loading process of the html site?

Thank you all in advance!
2 REPLIES 2

s_palyukh
Star Contributor
Star Contributor
As I understood you want to create custom action in document library. If this is true then you do it by incorrect way.
Alfresco has great functional to add custom actions to the  document library. Take a look at the following post http://www.marversolutions.com/wordpress/2012/04/15/adding-document-library-actions-in-alfresco-4-0/

This is both true and false - I want to creat a custom action -yes- but here I have to overlay the *html element* which gets rendered "onload" (I can't imagine this is achieved by pure configuration?). The javascript class for custom actions are executed only when the user clicks the action but I have to execute some javascript while the page gets loaded - to overlay the flash object on top of the "button" which source code looks like:


// browser source code of the default "delete document" action
<span id="yui-gen188">Delete Document</span>

// so for this example I have to execute the following code while the page gets loaded (during the "onload" event of the page)
// this will define the listener and its properties to save to the client's system clipboard
new zcProto("yui-gen188", nodes[node].nodeRef);

// if the user than clicks on the button in reality the user clicks the invisible flash object on top of the button which triggers the listener
// which will save the node's nodeRef to the clipoard (or any other properties of the node)


I also have to access the node's properties because the action should automatically save some properties in the client's system clipboard, see ZeroClipboard (https://github.com/zeroclipboard/zeroclipboard). If I would put this code into the action's javascript file the user would have to click the action at least 2 times > 1. time the flash object gets rendered over the button 2. time the flash object's listener loads the content to the clipboard.

This is a bit more complex I think Smiley Wink
Thanks, Michael