This code shows how to display Page Tools icons (Print this page, Email this page) in SharePoint.
Embed the entire code in a Content Editor Web Part.
<script type="text/javascript" src="http://intranet.na.kraft.com/sites/TC/jQuery/jquery-1.3.2.min.js"></script>
<style type="text/css">
img.hoverImage
{
cursor:pointer;
}
</style>
<TABLE id=PageToolsIcons width="100%" border=0>
<TBODY>
<TR>
<TD align=middle>
<TABLE>
<TBODY>
<TR>
<TD align=middle>
<IMG class=hoverImage id=printBtn alt="Printer Friendly Version" src="http://intranet.na.kraft.com/sites/TC/SiteCollectionImages/printbutton.jpg">
</TD>
<TD align=middle>
<IMG class=hoverImage id=emailFriendBtn alt="Email link to a Friend" src="http://intranet.na.kraft.com/sites/TC/SiteCollectionImages/emailbutton.jpg">
</TD>
</TR><tr><td></td><td><TABLE align=right>
<TBODY>
<TR>
<TD><A href="#"><IMG src="http://intranet.na.kraft.com/sites/TC/SiteCollectionImages/flag_icon_canada.gif" border=0></A></TD>
<TD><A href="#"><STRONG><FONT color=#0000ff><U>Francais</U></FONT></STRONG></A></TD></TR></TBODY></TABLE></td></tr>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
<SCRIPT>
$(document).ready(function()
{
var strlink = "";
$("link[rel='stylesheet']").each(function()
{
strlink += "<link rel = 'stylesheet' href='"+$(this).attr('href')+"' type='text/css'/>";
});
$("#printBtn").click(function()
{
var htmlStr ="<html><head>"+strlink+"</head><body>"+$("#MSO_ContentTable").parent().html()+"</body></html>";
var PrintingWindow = window.open("about:blank","","toolbar,width=800,height=600,scrollbars,resizable,menubar");
PrintingWindow.document.open();
PrintingWindow.document.write(htmlStr);
PrintingWindow.document.close();
PrintingWindow.focus();
PrintingWindow.document.getElementById("PageToolsIcons").style.display="none";
PrintingWindow.document.getElementById("ShareExperience").style.display="none";
//PrintingWindow.document.getElementById("Destination").style.display="none";
PrintingWindow.print();
});
$("#emailFriendBtn").click(function()
{
var eMailSoapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>E193795D-1DE9-4447-9CBE-4BBFFECE5A73</listName> \
<query> \
<Query> \
<Where> \
<Eq> \
<FieldRef Name='Title' /> \
<Value Type='Text'>" + jQuery.trim(document.title) + "</Value> \
</Eq> \
</Where> \
</Query> \
</query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Title' /> \
<FieldRef Name='Subject' /> \
<FieldRef Name='Body' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
//alert("Soap = " + eMailSoapEnv);
$.ajax({
url: "http://intranet.na.kraft.com/sites/TC/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: eMailSoapEnv,
complete: buildEMailMessage,
contentType: "text/xml; charset=\"utf-8\""
});
});
function buildEMailMessage(xData, status) {
var mailSubject, mailBody;
//alert(xData.responseXML.xml);
//Get the Item Count here
$(xData.responseXML).find("rs\\:data").each(function() {
itemCount = $(this).attr("ItemCount");
//alert("Total Number of Items = " + itemCount);
});
//Check if Item Count is 0
//If true, then there is no custom Subject and Body content
//Provide generic content
if (itemCount == 0)
{
//Create generic Subject line
mailSubject = "I found this on the My Travel and Expense site and thought you'd be interested.";
//Create generic Body text
mailBody = "I was on the My Travel and Expense intranet site and I found this page related to " + jQuery.trim(document.title) + " that I thought you would find useful:%0A%0A" + document.location.href;
}
else //Retrieve custom Subject and Body values from SharePoint List
{
//Loop through the result set returned in the SOAP
//envelope courtesy of the SharePoint Lists Web Service
$(xData.responseXML).find("z\\:row").each(function() {
//Get custom Subject line from List
mailSubject = $(this).attr("ows_Subject");
if(typeof(mailSubject) == 'undefined')
{
mailSubject = "I found this on the My Travel and Expense site and thought you'd be interested.";
}
//Get custom Body text from List
mailBody = $(this).attr("ows_Body");
if(typeof(mailBody) == 'undefined')
{
mailBody = "I was on the My Travel and Expense intranet site and I found this page related to " + jQuery.trim(document.title) + " that I thought you would find useful:";
}
//Append line break
mailBody += "%0A%0A";
//Append page Url
mailBody += document.location.href;
//alert("Subject from List = " + mailSubject);
//alert("Subject from List = " + mailBody);
});
}
//Construct mailto
var mailtoS = "mailto:%20" + "&subject=" + mailSubject + "&body=" + mailBody;
//Display the message in the newly created e-mail message
window.navigate(mailtoS);
}
});
</SCRIPT>
No comments:
Post a Comment