Skip to content

Instantly share code, notes, and snippets.

@beckettkev
beckettkev / Registering your Script - SP.SOD
Created May 13, 2015 19:01
SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs - How to register your script with SP.SOD
if (typeof Sys != "undefined" && Sys && Sys.Application) {
Sys.Application.notifyScriptLoaded();
}
if (typeof SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs =="function") {
SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs("NameOfMyScriptGoesHere.min.js");
}
SP.SOD.executeOrDelayUntilScriptLoaded(function () {
//your code goes here
}, "NameOfMyScriptGoesHere.min.js");
$.SubscriptionEvent('myDisplayTemplateLoadingCheck').publish("DisplayTemplateName");
var _totalLoadedTemplates = 0;
var _requiredAmountOfTemplates = 3; //Let's say you need 3 templates to load before you run your code
$.SubscriptionEvent('myDisplayTemplateLoadingCheck').subscribe ( function (data ) {
totalLoadedTemplates += 1;
if (_totalLoadedTemplates === _requiredAmountOfTemplates) {
//your code goes here
}
});
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="AwesomeSiteJS" Location="ScriptLink" ScriptBlock="document.write('&lt;script src=&quot;~sitecollection/Style Library/Awesome.min.js&quot;&gt;&lt;/' + 'script&gt;');"Sequence="10" />
</Elements>
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="AwesomeSiteJS" Location="ScriptLink" ScriptBlock="if (document.getElementsByTagName('Body')[0].className.trim().toLowerCase().indexOf('custommaster') > -1) { document.write('&lt;script src=&quot;~sitecollection/Style Library/AwesomeSite.min.js&quot;&gt;&lt;/' + 'script&gt;');}" Sequence="10" />
</Elements>
function Set-AvailableAndDefaultPageLayouts
{
param (
[Microsoft.SharePoint.Client.ClientContext]$clientContext,
[Microsoft.SharePoint.Client.Web]$web,
[array]$pageLayoutUrls,
[string]$defaultPageLayoutUrl
)
process
{
$pageLayoutUrls = @("/_catalogs/masterpage/ArticleContentPage.aspx","/_catalogs/masterpage/RedirectPageLayout.aspx")
$defaultPageLayoutUrl ="/_catalogs/masterpage/ArticleContentPage.aspx"
Set-AvailableAndDefaultPageLayouts -clientContext $clientContext -web $web -pageLayoutUrls $pageLayoutUrls -defaultPageLayoutUrl$defaultPageLayoutUrl
function Set-WelcomePage
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true, Position=1)]
$clientContext,
[Parameter(Mandatory=$true, Position=2)]
$web,
[Parameter(Mandatory=$true, Position=3)]
Set-WelcomePage -clientContext $clientContext -web $web -welcomePageUrl 'Pages/AmazingWikiPageWithPicturesAndLinksAndFreeStuff.aspx'