Last active
December 10, 2019 03:07
-
-
Save marineko/41c6b2f91d7870d2c70e434dc657e861 to your computer and use it in GitHub Desktop.
Open Office document or PDF in new tab via file type icon click on SharePoint library view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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