cancel
Showing results for 
Search instead for 
Did you mean: 

triggering a javascript function after document library is loaded

ayubalfresco
Champ in-the-making
Champ in-the-making
Hi,

I want to trigger a javascript function after all the documents in the document library are loaded.

I have coded a custom renderer for document library to display custom text for document library. When all the contents of the document library are loaded, I want to execute a javascript on the custom text.

I tried the below code and it does not work.


$(document).ready(function () {

myjsfunction();

}


Could some one suggest me how to achieve this.
5 REPLIES 5

afaust
Legendary Innovator
Legendary Innovator
Hello,

you should not use JQuery to hook into the document library. The DOM ready event is fired before the document library is actually ready. You can use the YUI events of the document library to react to any changes or hook your custom logic into the onReady function of Alfresco.DocumentList YUI widget class. This could be done by simple prototype adjustment, i.e.
<javascript>
if (YAHOO.lang.isFunction(Alfresco.DocumentList)){
    Alfresco.DocumentList.prototype.normalOnReady = Alfresco.DocumentList.prototype.onReady;
    Alfresco.DocumentList.prototype.onReady = function()
    {
         this.normalOnReady();
         // your code
    };
}
</javascript>

Regards
Axel

ayubalfresco
Champ in-the-making
Champ in-the-making
Hi Axel,

Thank you for the clue. I implemented the logic however its getting triggered before the documents are being displayed. I want to trigger the event after all the documents have been displayed. The reason is that, I am rendering a SPAN element using custom renderer and this element will only exist after each row in the document library is displayed. Any clues please ?

Thanks
Ayub

In principal Alex is correct and the onReady event is the usual place where you can hook in your custom code. In the case of the documentLibrary some things are still loading asynchronously at the end of the onReady event (e.g. fetching the records for the dataTable, etc.)
Instead you could wait for the renderEvent to be fired. An example of how to subscribe to this can be found at line 3155 of documentlist.js, at least in my version of Alfresco (EE 4.1.1.3):


// Rendering complete event handler
this.widgets.dataTable.subscribe("renderEvent", function DL_renderEvent() {
   // Do some stuff…
}

I tried to subscribe to renderEvent, however unable to get property dataTable js error from my javascript.

can I override the entire documentlist.js from extensions directory   ?

can I override the entire documentlist.js with my new file which has the custom script from extensions directory ?