Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danny-Engelman/61d53399b05cbc440ff6f45676dbfd99 to your computer and use it in GitHub Desktop.
Save Danny-Engelman/61d53399b05cbc440ff6f45676dbfd99 to your computer and use it in GitHub Desktop.
Open SharePoint document with Monaco editor (CiSaR script)
//add script with Cisar Chrome Browser extension!
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function () {
function init() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates: {
Fields: {
"MonacoEdit": { //add internal fieldname in Document Library!!
View: function (ctx, b, item) {
var fileref = item.FileRef;
var filepath = fileref.split('/');
var filename = filepath.pop();
var parent = filepath.join('/');
var uri = location.origin + parent + '/Forms/AllItems.aspx' + '?';
uri += '&file=' + filename;
uri += '&itemid=' + item.ID;
uri += '&id=' + fileref + '&parent=' + parent + '&p=5';
return String.format("<a href='{0}' target='_blank'>Open in Monaco: <b>{1}</b></a>", encodeURI(uri), filename);
}
}
}
}
});
}
RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~siteCollection/Style Library/MonacoEdit.js"), init);
init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment