Skip to content

Instantly share code, notes, and snippets.

@mutuadavid93
Last active May 24, 2023 17:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutuadavid93/5bdc700d25e61e5fa9241624961074d5 to your computer and use it in GitHub Desktop.
Save mutuadavid93/5bdc700d25e61e5fa9241624961074d5 to your computer and use it in GitHub Desktop.
/*********************************
*
* JSOM: WAKE SHAREPOINT MODAL:
*
********************************/
// Create your Link and Then give it an ID:
// Pass the the Id and List name into spModal() below:
// That is it, Dynamic SharePoint Modal it's.
function spModal(listName, linkID) {
var curCtx = new SP.ClientContext();
var oList = curCtx.get_web().get_lists().getByTitle(listName);
curCtx.load(oList);
curCtx.executeQueryAsync(
function() {
// Confirm List Template is a Library:
if (oList.get_baseType() === Number(1)) {
var curSite = _spPageContextInfo.webAbsoluteUrl;
var relativeUrl = _spPageContextInfo.webServerRelativeUrl;
var modalUrl = curSite+ "/_layouts/15/Upload.aspx?List={"+oList.get_id()+"}&RootFolder="+
relativeUrl+"/"+listName+"&Source="+curSite+"/"+listName+"/Forms/AllItems.aspx&IsDlg=1";
// Configure the Modal Window":
$("#"+linkID).on("click", function(event) {
event.preventDefault();
var options = SP.UI.$create_DialogOptions();
options.title = "New Document";
options.autoSize = true;
options.url = modalUrl;
SP.UI.ModalDialog.showModalDialog(options);
}); // Click Handler
} // End If
},
function(sender, args) {
console.log("Oops! Error: " + args.get_message());
},
);
} // spModal
// Init ALl Modal Windows:
spModal("Manuals_Library", "Manuals_LinkId");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment