sharepointsharepoint-2013pageload

Expand/Collapse Works for First Two Web Parts Only


I am trying to Maximize/Minimize a Document list Web Part.

I used the following code from http://blog.pathtosharepoint.com/2008/10/25/expandcollapse-buttons-for-your-web-parts/

and it works for my first two Web Parts but not my other two. All I did was include their titles within my coding as a change. Therefore, there shouldn't be any issue with the display.

Any suggestions on what can cause this?

The only changes I made after the first 2 were working was I added 2 more title1 to include the other 2 Web Parts.

As you can see, the bottom 2 don't fully minimize on page load enter image description here

fYI: inside the coding.. the titles are changed to "... Orders" but the ... is in place of the actual name

<script type="text/javascript">

// Expand/Collapse Buttons

function WPToggle(thisId, ImageId)
{
if (document.getElementById(thisId).style.display=="none")
{
document.getElementById(thisId).style.display="";
document.getElementById(ImageId).src = "/_layouts/images/minus.gif";
}
else
{
document.getElementById(thisId).style.display="none";
document.getElementById(ImageId).src = "/_layouts/images/plus.gif";
}
}

function ExpandCollapseBody()
{
var i = 1;
var WPid = "WebPartWPQ1" ;
var WPtitleid = "WebPartTitleWPQ1" ;
var Toggleid = "ToggleImage1" ;
do
{
try
{

title1 = document.getElementById(WPtitleid).getAttribute("title");
if (title1 == "... Orders" || title1 == "... Orders" || title1 =="... Orders" || title1 == "... Orders")
{
document.getElementById(WPtitleid).innerHTML = '<IMG id="' + Toggleid + '" onClick="WPToggle(\'' + WPid + '\',\'' + Toggleid + 
'\')" alt="Expand/Collapse" style="margin:6px 5px 0px 2px; float:left; cursor:pointer;" src="/_layouts/images/minus.gif" />' + 
document.getElementById(WPtitleid).innerHTML ;
document.getElementById(Toggleid).src = "/_layouts/images/plus.gif";
}
}
catch(err) {}
i = i + 1;
WPid = "WebPartWPQ" + i ;
WPtitleid = "WebPartTitleWPQ" + i;
Toggleid = "ToggleImage" + i;
} while (document.getElementById(WPid))
}

_spBodyOnLoadFunctionNames.push("ExpandCollapseBody()");

</script>

I guess I see that by default, the more I add more webparts they start at expanded rather than collapse....


Solution

  • I see. I need the following condition of Chrome: minimize for the Web Part

    enter image description here