Active fixed width master page in SharePoint 2010.


This is something that we’ve used for a while and has been very handy for fixed width designs . You might Know that making a master page fixed width for an intranet has its down falls like looking in list view when there are more headings than the page width will allow (you’ll have the list sticking out of the right hand side of the page)

I found the original code on another blog but have changed it after using it for a few projects.

The jquery works by looking for the outer tag that has the width on and checking this width against the .s4-ca content tag. If the content is wider than the outer tag it will add an inline class to the tag. Remeber that the jquery factors in the s4-leftpanel to the final width so if it has been removed make sure the page has the style of #s4-leftpanel {width:0px;} otheriwse it will factor in the width from the style sheet

I’ve normally used the #s4-bodyContainer tag as it tends to be the outer most tag with the page width. you can use any class or id you like as long as it’s the one that has the outer width.

The .ms-dialog code at the bottom is to prevent the dialog box expanding to the same width as the page.

Make sure you download and reference the latest jquery library for this to work

<script type=”text/javascript”>

        $(document).ready(function () {

            //Elements with the potential to be too wide.
            elements = $(“.s4-ca div table:first-child“);
            leftPanelWidth = $(“#s4-leftpanel“).width();

            //For each Elements
            $(elements).each(function () {

                //if it’s wider than the side width
                if ($(this).width() > ($(“#s4-bodyContainer“).width() – leftPanelWidth)) {
                    //Calculate the new width taking the left nav into account
                    newWidth = leftPanelWidth + $(this).width() + 50;
                    //Set the width!
                    $(“#s4-bodyContainer“).attr(“style”, “width:” + newWidth + “px!important”)
                    $(“.ms-dialog #s4-bodyContainer“).attr(“style”, “width:auto!important”)
                }
            });
        });

    </script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s