I inherited a piece of code on our sharepoint site and understand it basically, but I am lost in the PHP. The code is an accordion: https://jqueryui.com/accordion/ And it takes a value of 1 or 0 to determine which is shown by default.
I want this value to change each day (ignoring end of months), so I made a function which sets 1 or 0 if the day of month is odd or even.
My issue is using the output of my function as the value for this other function. I think I'll need to do some concatenation but I'm confused where the JQuery begins and PHP ends
Code below, it is not replicable because this is also fed by two additional SharePoint webparts which generate the content of each accordion piece, so I only included the meat of the code.
Look for $checkActive this is used in my function and is my desired value for the final lines
jQuery(document).ready(function($) {
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (inDesignMode == "1")
{
}
else
{
//Put the WebPart Title for all the Web Parts you wish
//to put into the jQuery UI Accordion into the array below.
//Accordian(["MY TO-DO LIST","MY COLLABORATION","MY TEAMSITES"]);
//Accordian(["MY FAVORITES","MY TEAMSITES","MY COLLABORATION"]);
Accordian(["MY COLLABORATION","IN THE NEWS"]);
}
});
function Accordian(webPartTitles)
{
for(index in webPartTitles)
{
var title = webPartTitles[index];
$("#accordian").append('<h3>'+title+'</h3>');
var addedToAccordion = 'false';
$("span:contains('"+title+"')").each(function(){
if ($(this).html() == title && addedToAccordion == 'false' ){
if($(this).closest("span").closest("[id^='MSOZoneCell_WebPart']").contents().length > 0)
{
$(this).closest("span").hide().closest("[id^='MSOZoneCell_WebPart']").contents().appendTo($("#accordianTemp"));
addedToAccordion = 'true';
$("span:contains('"+title+"Link')").each(function(){
if ($(this).html() == title + "Link"){
if($(this).closest("span").closest("[id^='MSOZoneCell_WebPart']").contents().length > 0)
{
$(this).closest("span").hide().closest("[id^='MSOZoneCell_WebPart']").contents().appendTo($("#accordianTemp"));
}
}
});
}
}
});
$("#accordian").append("<div>" + $("#accordianTemp").html() + "</div>");
$("#accordianTemp").empty();
}
$dw = date( "j", time());
$checkActive = ($dw % 2 == 0) ? '1' : '0'; // If the day number is Odd, we will show My Collaboration
the active value below is what normally accepts 1 or 0 but I want it to take my variable value
$("#accordian").find("div").remove( ".ms-webpart-chrome-title" );
$("#accordian").accordion({ heightStyle: "content" }, {active:$checkActive });
}</script>