Open Office document or PDF in new tab via file type icon click on SharePoint library view.
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() { | |
function getBaseHtml(ctx) { | |
return SPClientTemplates["_defaultTemplates"].Fields.default.all.all[ctx.CurrentFieldSchema.FieldType][ctx.BaseViewID](ctx); | |
} | |
function init() { | |
var overrideCtx = {}; | |
overrideCtx.Templates = {}; | |
overrideCtx.Templates.Fields = { | |
'DocIcon': { | |
'View': function CustomIcon(ctx, field, listItem, listSchema) { | |
var str = ""; | |
var itemApp = ctx.CurrentItem["File_x0020_Type.mapapp"]; | |
if (ctx.CurrentItem.FSObjType == '1'|| itemApp == '' && ctx.CurrentItem.File_x0020_Type != "pdf") { | |
str = (ComputedFieldWorker.DocIcon(ctx, field, listItem, listSchema)); | |
} else if(itemApp != ""){ | |
str = '<a href="' + ctx.CurrentItem.FileRef + '" onmousedown="return VerifyHref(this,event,\'' + listSchema.DefaultItemOpen + '\',\'' + listItem["HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon"] + '\',\'' + listItem["serverurl.progid"] + '\')" target="_blank">' + ComputedFieldWorker.DocIcon(ctx, field, listItem, listSchema) + '</a>'; | |
} else { | |
str = '<a href="' + ctx.CurrentItem.FileRef + '" onmousedown="return VerifyHref(this,event,\''+ listSchema.DefaultItemOpen + '\',\'\',\'\')" target="_blank">' + ComputedFieldWorker.DocIcon(ctx, field, listItem, listSchema) + '</a>' | |
} | |
return str; | |
} | |
} | |
}; | |
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx); | |
} | |
RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~siteCollection/SiteAssets/OpenFileViaIcon.js"), init); | |
init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment