Created
January 15, 2018 18:02
-
-
Save iOnline247/1aa8ca24d6f3904ca30dbbd8431d7986 to your computer and use it in GitHub Desktop.
SharePoint SP.SOD Helper
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
;(function() { | |
// Is MDS enabled? | |
if ("undefined" != typeof g_MinimalDownload && g_MinimalDownload && (window.location.pathname.toLowerCase()).endsWith("/_layouts/15/start.aspx") && "undefined" != typeof asyncDeltaManager) { | |
// Register script for MDS if possible | |
RegisterModuleInit("init.js", init); //MDS registration | |
init(); //non MDS run | |
} else { | |
init(); | |
} | |
function init () { | |
// Register libs. | |
RegisterSod('jquery-2.2.0.min.js', 'https://code.jquery.com/jquery-2.2.0.min.js'); | |
RegisterSod('jquery-ui-1.12.min.js', 'https://code.jquery.com/ui/1.12.0/jquery-ui.min.js'); | |
RegisterSod('datatables-1.10.11.min.js', 'https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js'); | |
RegisterSod('sieve-0.3.0.min.js', 'http://rmm5t.github.com/jquery-sieve/dist/jquery.sieve.min.js'); | |
// Register dependencies. | |
RegisterSodDep('jquery-ui-1.12.min.js', 'jquery-2.2.0.min.js'); | |
RegisterSodDep('sieve-0.3.0.min.js', 'jquery-2.2.0.min.js'); | |
// RegisterSod('script1.js', replaceUrlTokens("~sitecollection/_catalogs/masterpage/tests/script1.js")); | |
} | |
// Utils | |
// Copied from: SPClientRenderer.ReplaceUrlTokens. | |
// TODO: | |
// Needs thorough testing... | |
function replaceUrlTokens (a) { | |
if (true) { | |
var c = window._spPageContextInfo; | |
if (a == null || a == "" || c == null) return ""; | |
var k = "~site/", | |
f = "~sitecollection/", | |
e = "~sitecollectionmasterpagegallery/", | |
b = a.toLowerCase(); | |
if (b.indexOf(k) == 0) { | |
var n = h(c.webServerRelativeUrl); | |
a = n + a.substr(k.length); | |
b = n + b.substr(k.length) | |
} else if (b.indexOf(f) == 0) { | |
var m = h(c.siteServerRelativeUrl); | |
a = m + a.substr(f.length); | |
b = m + b.substr(f.length) | |
} else if (b.indexOf(e) == 0) { | |
var l = h(c.siteServerRelativeUrl); | |
a = l + "_catalogs/masterpage/" + a.substr(e.length); | |
b = l + "_catalogs/masterpage/" + b.substr(e.length) | |
} | |
var j = "{lcid}", | |
i = "{locale}", | |
g = "{siteclienttag}", | |
d = -1; | |
while ((d = b.indexOf(j)) != -1) { | |
a = a.substring(0, d) + String(c.currentLanguage) + a.substr(d + j.length); | |
b = b.replace(j, String(c.currentLanguage)) | |
} | |
while ((d = b.indexOf(i)) != -1) { | |
a = a.substring(0, d) + c.currentUICultureName + a.substr(d + i.length); | |
b = b.replace(i, c.currentUICultureName) | |
} | |
while ((d = b.indexOf(g)) != -1) { | |
a = a.substring(0, d) + c.siteClientTag + a.substr(d + g.length); | |
b = b.replace(g, c.siteClientTag) | |
} | |
return a | |
} | |
return ""; | |
function h(a) { | |
if (a == null || a == "") return ""; | |
var b = a.length; | |
return a[b - 1] == "/" ? a : a + "/" | |
} | |
} | |
}()); | |
/* | |
* Usage | |
* | |
* SP.SOD.executeFunc('jquery-ui-1.12.min.js', 'jQuery.ui', _ => console.assert(!!jQuery.ui === true, 'jQuery UI is loaded')); | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment