SP.SOD.executeFunc("callout.js","Callout",function(){varitemCtx={};itemCtx.Templates={};itemCtx.BaseViewID='Callout';// Define the list template type
itemCtx.ListTemplateType=101;itemCtx.Templates.Footer=function(itemCtx){// context, custom action function, show the ECB menu (boolean)
returnCalloutRenderFooterTemplate(itemCtx,AddCustomAction,true);};SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);});functionAddCustomAction(renderCtx,calloutActionMenu){// Add your custom action
calloutActionMenu.addAction(newCalloutAction({text:"Custom Action",tooltip:'This is your custom action',onClickCallback:function(){console.log('Callback from custom action');}}));// Show the default document library actions
CalloutOnPostRenderTemplate(renderCtx,calloutActionMenu);// Show the follow action
calloutActionMenu.addAction(newCalloutAction({text:Strings.STS.L_CalloutFollowAction,tooltip:Strings.STS.L_CalloutFollowAction_Tooltip,onClickCallback:function(calloutActionClickEvent,calloutAction){varcallout=GetCalloutFromRenderCtx(renderCtx);if(!(typeof(callout)==='undefined'''callout===null))callout.close();SP.SOD.executeFunc('followingcommon.js','FollowSelectedDocument',function(){FollowSelectedDocument(renderCtx);});}}));}
With this piece of code you can add a custom callout action for all documents, so what we need to implement is a check to see if the document is for example a PDF document. This information can be retrieved from the renderCtx object like this, and to be more specific, if you click to open the callout the renderCtx object contains all the information about the current item:
The file type can be retrieved like this:
1
renderCtx.CurrentItem.File_x0020_Type
Once you know the file type, you could implement the check like this:
SP.SOD.executeFunc("callout.js","Callout",function(){varitemCtx={};itemCtx.Templates={};itemCtx.BaseViewID='Callout';// Define the list template type
itemCtx.ListTemplateType=101;itemCtx.Templates.Footer=function(itemCtx){// context, custom action function, show the ECB menu (boolean)
returnCalloutRenderFooterTemplate(itemCtx,AddCustomAction,true);};SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);});functionAddCustomAction(renderCtx,calloutActionMenu){// Check if the current item is a PDF document
if(renderCtx.CurrentItem.File_x0020_Type.toLowerCase()==="pdf"){// Add your custom action
calloutActionMenu.addAction(newCalloutAction({text:"PDF Action",tooltip:'This is a PDF action',onClickCallback:function(){console.log('Callback from the PDF action');}}));}// Show the default document library actions
CalloutOnPostRenderTemplate(renderCtx,calloutActionMenu);// Show the follow action
calloutActionMenu.addAction(newCalloutAction({text:Strings.STS.L_CalloutFollowAction,tooltip:Strings.STS.L_CalloutFollowAction_Tooltip,onClickCallback:function(calloutActionClickEvent,calloutAction){varcallout=GetCalloutFromRenderCtx(renderCtx);if(!(typeof(callout)==='undefined'''callout===null))callout.close();SP.SOD.executeFunc('followingcommon.js','FollowSelectedDocument',function(){FollowSelectedDocument(renderCtx);});}}));}
On the highlighted line a check is in place to see if the current item is a PDF document, if that statement is true, the custom action gets added, otherwise nothing will be shown.