Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*********************************
*
* 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
You can’t perform that action at this time.