SharePoint Designer 2010 Using Hot Spots Picture Tool

This is an easy to use and very useful feature in SharePoint designer 2010 that I’m almost too embarrassed to say I just found out about recently, although I’ve been working with SharePoint designer 2010 intensively.


Okay so let’s take for example a scenario which I believe to be a very common in which this ability can come very handy, suppose you are required to create an hierarchy tree for the different divisions or mangers in your company, where each different branch of your tree is supposed to be linked to a different site or pop up window.

You have two options:

  1. Build one from scratch using html – which should take you a while…
  2. Create a simple image file using Visio\PowerPoint or any other software and then add the different links to it using Hot Spots with SharePoint designer 2010 which should take you no more than a few minutes.

So this is what you need to do once you’ve created your image file:

  1. Add a content editor or Html form Web Part to your page and add your image in it (This is important! if you add your picture on a wiki type page\zone you won’t be able to add hot spots on it!).
  2. Edit your page using SharePoint designer 2010 (If your page is a publishing page you’ll need to detach it form it’s layout in order to edit it).
  3. View your page in the “Design” view.
  4. Left click your image in the design view.
  5. Now on the ribbon of the designer you should see  the Picture Tools tab:

    Picture Tools Hot Spots

    Picture Tools Hot Spots

 

6. Click on “Format” beneath the Picture Tools tab.

7.  Click on the Hot Spots Icon and choose the shape of the area you want to link.

8. Mark around the area you want to link, add the URL you want to link to.

9. You also have the option to add a ScreenTip, choose a target frame for example: if you want your link to open in a new window, and add parameters If you’re using a query string.

Image with Hot Spot Example

Image with Hot Spot Example

 

Creating a Color Coded Calendar by category using JS in SharePoint 2010

So this is a very common customization, nice and easy way to make your Team site calendar a bit smarter,  and more colorful obviously…
Follow these stages:

  1. Create a new Calendar list.
  2. Go to your new calendar list settings and change the choices in the category column to the ones you want.
  3. Create a new column named ‘CategoryTitle‘ of a Calculated (calculation based on other columns) type.
  4. Insert this formula in the formula window of your new column: =”|||”&Category&”|||”&Title
  • If you want to base your colors on a different type ‘Choice’ column and not using the OOTB “Category” column, simply change this formula to:

=”|||”&[Your Custom Column Name Here]&”|||”&Title

  1. Modify the default  OOTB calendar view simply named ‘Calendar’ so that your monthly view title will be based on your newly created column ‘CategoryTitle’.

    Change Calender Month View Title

    Change Calender Month View Title

  2. Download the most recent Jquery file, or the one I added to this post.
  3. Download the JS file I added to this post named ColorCalendar.js.
  4. Open the ColorCalendar.js file and change the name of the Categories to the ones you have in your Category Choices.
  5. Change the color HEX codes to the colors you want for each category, you can find different color codes in this link – W3Schools CSS Color Chart.
  6. Here is the JS Code – Remember to change the Category names to the ones you’ve entered and the colors to the ones you want –

{code type=javascript}_spBodyOnLoadFunctionNames.push(‘WaitForCalendarToLoad’);

var SEPARATOR = “|||”;

function WaitForCalendarToLoad() {
// we will slightly rewrite this existing function as defined originally in SP.UI.ApplicationPages.Calendar.debug.js
var pwold$4a = SP.UI.ApplicationPages.CalendarNotify.$4a;
SP.UI.ApplicationPages.CalendarNotify.$4a = function () {
pwold$4a();
ColourCalendar();
}
}

function ColourCalendar() {

if($(‘a:contains(‘ + SEPARATOR + ‘)’) != null)
{
$(‘a:contains(‘ + SEPARATOR + ‘)’).each(
function (i) {
$box = $(this).parents(‘div[title]’);
var colour = GetColourCodeFromCategory(GetCategory(this.innerHTML));
this.innerHTML = GetActualText(this.innerHTML);
$($box).attr(“title”, GetActualText($($box).attr(“title”)));
$box.css(‘background-color’, colour);
});
}
}

function GetActualText(originalText) {
var parts = originalText.split(SEPARATOR);
return parts[0] + parts[2];
}

function GetCategory(originalText) {
var parts = originalText.split(SEPARATOR);
return parts[1];
}

function GetColourCodeFromCategory(category) {
var colour = null;
switch (category.trim().toLowerCase()) {
case ‘category1’:
//green
colour = ‘#FF7F00’;
break;
case ‘category2’:
//yellow
colour = ‘#EEEE00’;
break;
case ‘category3’:
//blue
colour = ‘#63B8FF’;
break;
}
return colour;
}{/code}

7. Upload the Jquery and JS files to your Site assets Library.

8. Edit either your “Lists/Calendar/calendar.aspx” page or any other page containg a data view web part with your calendar view, and add a hidden content editor web part on that page with refrences to the Jquery file and the JS file in the content editor HTML, as such –

{code type=javascript}<script src=”/sites/YourSiteNameHere/SiteAssets/CalendarColorsJSFiles/ColorCalendar.js” type=”text/javascript”></script><script src=”/sites/YourSiteNameHere/SiteAssets/CalendarColorsJSFiles/jquery-1.7.2.min.js” type=”text/javascript”></script>{/code}

9. The final result should look some like this:

Final result calendar with coded colors

Final result calendar with coded colors

10. Here are the JS files: JS files

15/01/2013 – Update

1. Make sure all your category names in the Javascript code are writen in lowercase letters.

2. Today I had a request to apply different text colors along with different background colors for each category, these are only the functions (part of the same code above) that i’ve changed in order to get this effect:

{code type=javascript}

function ColourCalendar() {
if(jQuery(‘a:contains(‘ + SEPARATOR + ‘)’) != null)
{
jQuery(‘a:contains(‘ + SEPARATOR + ‘)’).each(function (i) {
$box = jQuery(this).parents(‘div[title]’);
var colours = GetColourCodeFromCategory(GetCategory(this.innerHTML));
var colour = colours[0];
//colour += “!important”;
var Fontcolour = colours[1];
this.innerHTML = GetActualText(this.innerHTML);
jQuery($box).attr(“title”, GetActualText(jQuery($box).attr(“title”)));
$box.css(‘background-color’, colour);
$box.children().css(‘color’, Fontcolour);
// I’ve added this condition since the font color did not catch on to a a:link unless i used !important
//if (Fontcolour == ‘white’)
//{
//$(‘a:link’, $box).css(“cssText”, “color: white !important;”);
//}

});
}
}

function GetColourCodeFromCategory(category) {

var colour = null;
var Fontcolour = null;
switch (category.trim().toLowerCase()) {
case ‘category1’:
colour = ‘green’;
Fontcolour = ‘black’;
break;
case ‘category2’:
colour = ‘blue’;
Fontcolour = ‘white’;
break;
case ‘category3’:
colour = ‘yellow’;
Fontcolour = ‘black’;
break;
}
return [colour, Fontcolour];

}

{/code}

g.p

08-05-2014 – Update

If you have an updated version of SP2010 you have to change:
SP.UI.ApplicationPages.CalendarNotify.$4a
to
SP.UI.ApplicationPages.CalendarNotify.$4b

*Thanks Kent for pointing this out.