Friday, August 20, 2010

JQuery Samples

Change mailto links with Subject details in SharePoint

<script type="text/javascript" src="_layouts/jQuery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.bgiframe-2.1.1.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.ui.core.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.ui.widget.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.ui.mouse.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.ui.button.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.ui.draggable.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.ui.position.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.ui.resizable.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.ui.dialog.js"></script>
<script type="text/javascript" src="_layouts/jQuery/jquery.effects.core.js"></script>
<script type="text/javascript" src="_layouts/jQuery/SPAPI_Lists.js"></script>
<script type="text/javascript" src="_layouts/jQuery/SPAPI_Core.js"></script>

<script type="text/javascript">
$(function() {
$("a[href^=mailto:]").each(function(){
var sEmailAddress = $(this).text();
var subStr = "";
var objParentRow = $(this).parent().parent();
$('.ms-vb-icon', objParentRow).each(function(column)
{
var UrlForID = $(this).children().attr('href');
var ID = UrlForID .split('?')[1].split('=')[1];


// Return all items in the default view of MyList
var lists = new SPAPI_Lists('http://siteurl:1659/web1/');
var queryStr = '<Query><Where><Eq><FieldRef Name=\'ID\' /><Value Type=\'Counter\'>' + ID + '</Value></Eq></Where></Query>';

var items = lists.getListItems('Work_master', '{7C3F44F3-25DF-48AC-B183-89C0F97C86C9}' , queryStr, '<ViewFields><FieldRef Name=\'ID\' /><FieldRef Name=\'Work_x0020_ID\' /><FieldRef Name=\'Customer_x0020_Name\' /><FieldRef Name=\'Work_x0020_Type_x0020_ID\' /></ViewFields>', '100', '<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc></QueryOptions>' );
if (items.status == 200)
{
var rows = items.responseXML.getElementsByTagName('z:row');
$(items.responseXML).find("z\\:row").each(function()
{
var projId = $(this).attr("ows_Work_x0020_ID") ;
var ptypeId = $(this).attr("ows_Work_x0020_Type_x0020_ID");
var finalPtypeID = ptypeId.split(';#')[1];

var Custname = $(this).attr("ows_Customer_x0020_Name");
subStr = projId + " - " + Custname + " - " + finalPtypeID;

});
}
else
{
}

});

var currentUrl = $(this).attr('href');
var setUrl = $(this).attr('href') + '?subject=' + subStr;
$(this).attr('href',setUrl);
});
});
</script>

============================================
Replace HTML content using Jquery
============================================

var TDS = $(".ms-vb2");
TDS.each(function()
{
if(this.innerHTML=='kpipepperslarge-0.gif')
{
var cred = "";
var str=this.innerHTML.replace(this.innerHTML, cred);
$(this).html(str);
}
if(this.innerHTML=='kpipepperslarge-1.gif')
{
var cred = "";
var str=this.innerHTML.replace(this.innerHTML, cred);
$(this).html(str);
}
if(this.innerHTML=='kpipepperslarge-2.gif')
{
var cred = "";
var str=this.innerHTML.replace(this.innerHTML, cred);
$(this).html(str);
}
if(this.innerHTML=='No')
{
var cred = " ";
var str=this.innerHTML.replace(this.innerHTML, cred);
$(this).html(str);
}
});


==============================================


JQuery builder and testing Trick--

Go to http://api.jquery.com/html/ and choose the similar JQ you want to build.

Copy paste chosen JQ to JQuery Editor here -

Modify and test as needed.

Implement the same to your own webpage.

DOne


GOOD LINKS

No comments: