August 16, 2010

Highlight the Keyword in SharePoint Page

Hi All,

I got a script which is used to highlight the Keyword present on the SharePoint Page. We can use the following script in Content Editor Web part.

Script ....

<script language=JavaScript>
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag)
{
// the highlightStartTag and highlightEndTag parameters are optional
if ((!highlightStartTag) || (!highlightEndTag)) {
highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
highlightEndTag = "</font>";
}

var newText = "";
var i = -1;
var lcSearchTerm = searchTerm.toLowerCase();
var lcBodyText = bodyText.toLowerCase();

while (bodyText.length > 0) {
i = lcBodyText.indexOf(lcSearchTerm, i+1);
if (i < 0) {
newText += bodyText;
bodyText = "";
} else {
// skip anything inside an HTML tag
if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
// skip anything inside a <script> block
if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
bodyText = bodyText.substr(i + searchTerm.length);
lcBodyText = bodyText.toLowerCase();
i = -1;
}
}
}
}

return newText;
}
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
// if the treatAsPhrase parameter is true, then we should search for
// the entire phrase that was entered; otherwise, we will split the
// search string so that each word is searched for and highlighted
// individually
<!-- Codes by Quackit.com -->


if (treatAsPhrase) {
searchArray = [searchText];
} else {
searchArray = searchText.split(" ");
}

if (!document.body || typeof(document.body.innerHTML) == "undefined") {
if (warnOnFailure) {
alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
}
return false;
}

var bodyText = document.body.innerHTML;
for (var i = 0; i < searchArray.length; i++) {
bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
}

document.body.innerHTML = bodyText;
return true;
}
function searchPrompt(defaultText, treatAsPhrase, textColor, bgColor)
{
// This function prompts the user for any words that should
// be highlighted on this web page
if (!defaultText) {
defaultText = "";
}

// we can optionally use our own highlight tag values
if ((!textColor) || (!bgColor)) {
highlightStartTag = "";
highlightEndTag = "";
} else {
highlightStartTag = "<font style='color:" + textColor + "; background-color:" + bgColor + ";'>";
highlightEndTag = "</font>";
}

if (treatAsPhrase) {
promptText = "Please enter the phrase you'd like to search for:";
} else {
promptText = "Please enter the words you'd like to search for, separated by spaces:";
}

searchText = prompt(promptText, defaultText);

if (!searchText) {
alert("No search terms were entered. Exiting function.");
return false;
}

return highlightSearchTerms(searchText, treatAsPhrase, true, highlightStartTag, highlightEndTag);
}

function highlightGoogleSearchTerms(referrer)
{
// <body onload='highlightGoogleSearchTerms(document.referrer);'>

//var referrer = document.referrer;
if (!referrer) {
return false;
}

var queryPrefix = "q=";
var startPos = referrer.toLowerCase().indexOf(queryPrefix);
if ((startPos < 0) || (startPos + queryPrefix.length == referrer.length)) {
return false;
}

var endPos = referrer.indexOf("&", startPos);
if (endPos < 0) {
endPos = referrer.length;
}

var queryString = referrer.substring(startPos + queryPrefix.length, endPos);
// fix the space characters
queryString = queryString.replace(/%20/gi, " ");
queryString = queryString.replace(/\+/gi, " ");
// remove the quotes (if you're really creative, you could search for the
// terms within the quotes as phrases, and everything else as single terms)
queryString = queryString.replace(/%22/gi, "");
queryString = queryString.replace(/\"/gi, "");

return highlightSearchTerms(queryString, false);
}

function testHighlightGoogleSearchTerms()
{
var referrerString = "http://www.google.com/search?q=javascript%20highlight&start=0";
referrerString = prompt("Test the following referrer string:", referrerString);
return highlightGoogleSearchTerms(referrerString);
}

</script>

<input type ="text" id ="txtSearch">
<input type = "button" id= "btnClick" Value="Highlight" onClick="highlightSearchTerms(txtSearch.value);">

Outlook Access Web Parts

Outlook Web Access web parts are meant for use on SharePoint My Sites.

Each Outlook Web Access web part has the following required fields:
Mail server address
Mailbox

Now, for end users, the Mailbox field is pretty easy, since it only requires their email address. Unfortunately, it seems that the Mail server address field seems to be the main reason that a lot of people don’t use these web parts. Most end users don’t know their email server name.

Here’s how to set the Mail server address field to auto-populate for a single user:

1. In Central Admin, go to your Shared Services Administration site.
2. Click on User Profiles & Properties
3. Click View User Profiles
4. Find your own account name
5. Edit your profile
6. Scroll down to the Outlook Web Access URL field. This is the one to fill in.

Here’s how to determine what URL goes in here. You do need to know the server name of at least one email server in your company. Log into your Outlook Web Access, and look at the URL after you’ve logged in. It probably looks like https://email.company.com/exchange
For ours, I simply change it to http, and replace email.company.com with an email server name. It doesn’t have to even be my mailbox server, it can be any mail server in the same domain. So, the result is http://servername/exchange

7. Save your profile
8. Go to your My Site, and when you add OWA web parts, the Mail server address field will already be filled in.
9. Also, as a bonus, you’ll notice that there’s a new link at the top of your My Site, called “My OWA”. This link will take you directly to OWA, without having to log in!

Okay, so that took care of one user, how do we get everyone’s Outlook Web Access URL field to populate? In SSP, User Profile & Properties, View Profile Properties, edit that field. It appears that the only way this will work is to connect to some data source. Pick a custom field in Active Directory to map to, use a script to automatically fill in all user AD accounts with http://servername/exchange, and you’re good to go.