Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Tuesday, November 16, 2010

Jquery In SharePoint page

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("GetAlert");

$(document).ready(function GetAlert() {
var thisUser = 'test';
alert(thisUser);
});

</script>

Monday, November 15, 2010

Getting Query parameters using Javascript

<script language='JavaScript'>
// get the current URL
var url = window.location.toString();
//get the parameters
url.match(/\?(.+)$/);
var params = RegExp.$1;
// split up the query string and store in an
// associative array
var params = params.split("&");
var queryStringList = {};

for(var i=0;i {
var tmp = params[i].split("=");
queryStringList[tmp[0]] = unescape(tmp[1]);
}

// print all querystring in key value pairs
for(var i in queryStringList)
document.write(i+" = "+queryStringList[i]+"<br/>");
</script>

Friday, November 12, 2010

Find the userId from a people picke

<script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
fields = init_fields();
// Find the userId from a people picker in DispForm
var userIdRaw = $(fields['client']).find('.ms-formbody a').attr('href');
var userId = userIdRaw.substring(userIdRaw.indexOf('=')+1);
// Here is the userId for the person in the people picker
alert(userId);

function init_fields(){
var res = {};
$("td.ms-formbody").each(function(){
if($(this).html().indexOf('FieldInternalName="')<0) return;
var start = $(this).html().indexOf('FieldInternalName="')+19;
var stopp = $(this).html().indexOf('FieldType="')-7;
var nm = $(this).html().substring(start,stopp);
res[nm] = this.parentNode;
});
return res;
}
</script>

Saturday, October 30, 2010

How to select the Inner Most Element

Today I was working on new category browser UI for the project I am working. I had to select the innermost element and append some more content into it. Basically, I had an HTML like this:

<div>Outermost element 
<div>Some Text
<div>Evenmore text
<div>Who cares anymore?
<div>Innermost Element</div>
</div>
</div>
</div>

</div>

So I needed to select the innermost div and append another div to it. There is no jQuery selector but you can use selectors that exist to achieve this goal. The innermost element would be the last div with the only-child.

$('div:only-child:last'); 
// Change background color to gray
$('div:only-child:last').css('background-color',"#ccc");