Tag Archives: Masterpage

Open link in SP Dialog from Global Navigation / Quick launch

Requirement

Building on my previous post about opening a link in a SP dialog window (similar to lightbox), we decided to make it so that clicking on the link under the quick launch or top navigational bar would open the page immediately in a SP dialog box. This is not possible out of the box, as SharePoint does not allow javascript in the links under the top navigation / quick launch. Here is our work around using Jquery/javascript.

The benefit of this for us is that users can now open the staff directory from anywhere on the site collection without leaving their current page as long as they have access to the top navigational bar.

Solution

This solution uses Jquery. Change the bits in bold to meet your requirements. If you want this to work on every page in the site collection, you will need to add this script to the master page. This script will:

  1. Load the Jquery library from your SharePoint site collection.
  2. Check if the link being clicked leads to a page called ‘staffdir.aspx’.
  3. Open the link to the page (http://path/to/staffdir.aspx) specified under in a SP Modal Dialog.

<script type=”text/javascript” src=”http://path/to/jquerylibrary/jquery-1.4.4.min.js”></script> <script type=”text/javascript”> $(document).ready(function(){ $(“a[href$=’staffdir.aspx‘]”).click(function() { SP.UI.ModalDialog.showModalDialog({ url: “http://path/to/staffdir.aspx“, title: “Staff Directory“, allowMaximize: true, showClose: true, width: 1200, height: 768, dialogReturnValueCallback: function (dialogResult, returnValue) {}});   return false; }); }); </script>

 

Comments ( 0 )

Dynamic banner images depending on browser resolution

Requirement

Intranet site branding requires that the v4.master masterpage be customised with a dynamically expanding banner that changes its resolution depending on the resolution of the user’s browser.

Solution

We created a simple javascript that is copied just below the

<script type="text/javascript">
	var _fV4UI = true;
	</script>

section of the master page. Note that this uses ASP literals so that the masterpage can be deployed to any site collection. ASP literals can be quite problematic when editing using SharePoint designer as the editor adds unnecessary mark up to the code, e.g. __designer:preview and __designer:values. It is recommended to insert this code using a text editor, or copy it to a .js file and call it from the masterpage. If you choose this option, you will need to copy the images/files to the _layouts folder of the webserver and update the file paths in the script.

Before you run this script you will need to copy the following files to the Site Collection \ Style Library

  1. jquery library should be copied to Site Collection/Style Library/jquery library/
  2. Banner images should be copied to Site Collection/Style Library/images and must match the image names: banner_bg1280.jpg, banner_bg1440.jpg, banner_bg1680.jpg and banner_bg1920.jpg.
<script type="text/javascript" id="s1"></script>
    <script type="text/javascript">
        var siteColl = '<asp:Literal ID="siteColl" runat="server" Text="<%$SPUrl:~sitecollection/Style Library/jquery library/jquery-1.4.4.min.js%>"></asp:Literal>';
        if (typeof (s1) != 'undefined') {
            s1.src = siteColl;
        }

        var jQueryScriptOutputted = false;
        function initJQuery() {
            //if the jQuery object isn't available
            if (typeof (jQuery) == 'undefined') {
                if (!jQueryScriptOutputted) {
                    //only output the script once..
                    jQueryScriptOutputted = true;
                    //output the script (load it from google api)
                    document.write("<scr" + "ipt type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></scr" + "ipt>");
                }
                setTimeout("initJQuery()", 50);
            } else {
                $(function () {

                    $(document).ready(function () {
                        function adjustCSS() {
                            $('.s4-titletable').hide();
                            var pageWidth = $(window).width();
                            if (pageWidth < 1277) {
                                $('.s4-titletable').css({ 'background-image': "url(" + "<asp:Literal runat='server' Text='<%$SPUrl:~sitecollection/Style%20Library/Images/banner_bg1280.jpg%>' />" + ")", 'height': '145px', 'background-repeat': 'no-repeat', 'background-position': 'center top' }).fadeIn();
                            }
                            else if (pageWidth > 1400 && pageWidth < 1671) {
                                $('.s4-titletable').css({ 'background-image': "url(" + "<asp:Literal runat='server' Text='<%$SPUrl:~sitecollection/Style%20Library/Images/banner_bg1440.jpg%>' />" + ")", 'height': '145px', 'background-repeat': 'no-repeat', 'background-position': 'center top' }).fadeIn();
                            }
                            else if (pageWidth > 1600 && pageWidth < 1901) {
                                $('.s4-titletable').css({ 'background-image': "url(" + "<asp:Literal runat='server' Text='<%$SPUrl:~sitecollection/Style%20Library/Images/banner_bg1680.jpg%>' />" + ")", 'height': '145px', 'background-repeat': 'no-repeat', 'background-position': 'center top' }).fadeIn();
                            }
                            else if (pageWidth > 1901) {
                                $('.s4-titletable').css({ 'background-image': "url(" + "<asp:Literal runat='server' Text='<%$SPUrl:~sitecollection/Style%20Library/Images/banner_bg1920.jpg%>' />" + ")", 'height': '145px', 'background-repeat': 'no-repeat', 'background-position': 'center top' }).fadeIn();
                            }
                            else {
                                $('.s4-titletable').css({ 'background-image': "url(" + "<asp:Literal runat='server' Text='<%$SPUrl:~sitecollection/Style%20Library/Images/banner_bg1280.jpg%>' />" + ")", 'height': '145px', 'background-repeat': 'no-repeat', 'background-position': 'center top' }).fadeIn();
                            }
                        } $(function () {
                            $(".menu-item").hover(function () {
                                $(this).stop().attr('title', '');
                            },
		function () {
		    $(this).stop().attr();
		});
                        });

                        adjustCSS();
                        $(window).resize(function () { adjustCSS() });

                    });

                });
            }
        }
        initJQuery();
     </script>
Comments ( 0 )

Hide the Site Settings Drop down menu

Requirement

Some times you might want to hide the site settings drop down menu, especially if it is a publishing site and you want to hide the menu from your readers.

Solution

Modify your site’s master page and add the bold lines:

Css Class =”ms-siteactionscontainer s4-notdlg”>
<Sharepoint:SPSecurityTrimmedControl runat=”server” Permissions=”AddListItems”>

..

..

..

</SharePoint:SiteActions></span>

</SharePoint:SPSecurityTrimmedControl>
<asp:ContentPlaceHolder id=”PlaceHolderGlobalNavigation runat=”server”>

 

 

Testing

This will hide the Site Settings menu from all users who do not have ‘Manage Web’ permissions to your site, a.k.a administrators.

Here is a list of permissions you can use.

ManagePermissions
ViewUsageData
ManageSubwebs
ManageWeb
AddAndCustomizePages
ApplyThemeAndBorder
ApplyStyleSheets
CreateGroups
BrowseDirectories
CreateSSCSite
ViewPages
EnumeratePermissions
BrowseUserInfo
ManageAlerts
UseRemoteAPIs
UseClientIntegration
Open
EditMyUserInfo

Applies to

SharePoint 2010

 

Comments ( 0 )