I'm having incredible difficulty attempting to make a jQuery script run when a page is published. I have utilized a multitude of variants of ExecuteOrDelayUntilScriptLoaded
and SP.SOD
functions to no avail. Everything always works in Edit Mode, but never during Display. As I have publishing features turned on, whenever I debug on a published page I can see that SP.js is actually already loaded regardless if my script calls for it or not. I am all out of ideas as to why this does not run. Please look at one iteration of the code below.
$(document).ready(function () {
SP.SOD.executeOrDelayUntilScriptLoaded(newQuick, "SP.js");
function newQuick() {
var context = SP.ClientContext.get_current();
var parent = $("#zz12_V4QuickLaunchMenu > ul > li:has('ul')");
parent.find("span.menu-item-text:first").append(" <i class='fa fa-angle-down' aria-hidden='true'></i>");
parent.closest("li").find("> ul").hide();
parent.click(function(){
var childUL = $(this).closest("li").find("> ul");
var isVisible = childUL.is(":visible");
if (isVisible) {
childUL.slideUp();
}
else {
childUL.slideDown();
}
});
}
});
If it helps, this is how the code is referenced in my custom masterpage:
<!--SPM:<SharePoint:CssRegistration runat="server" ID="CssRegistration1" Name="<% $SPUrl:~sitecollection/_catalogs/masterpage/drkBlue/css/drkblue.css %>" after="corev15.css" />-->
<!--SPM:<SharePoint:ScriptLink runat="server" ID="jQuery" Language="javascript" Name="~sitecollection/_catalogs/masterpage/drkBlue/js/jquery-3.1.1.min.js" OnDemand="false" />-->
<!--SPM:<SharePoint:ScriptLink runat="server" ID="accordion" Language="javascript" Name="~sitecollection/_catalogs/masterpage/drkBlue/js/accordion.js" OnDemand="false" />-->
<link rel="stylesheet" href="/ecms/_catalogs/masterpage/drkBlue/font/font-awesome/css/font-awesome.min.css"/>