Tuesday, October 13, 2009

jQuery scrollTo plugin

jQuery has many great plugins.
Here is another one.

scrollTo is one of my favorite ones.
It's very useful and can be use anywhere while scrolling.

It gives scrolling an animation which is good over the boring scrolling.

Here is a quick link for downloading scrollto plugin. jquery.scrollTo-1.4.2.zip
Here is a demo if you want to try it, and see how it works. Demo
Note: you will need jquery-1.3.2 to use scrollTo. jquery-1.3.2.js

Here is the official link to the jQuery website for scrollTo plugin. jQuery scrollTo Official

Monday, September 7, 2009

jQuery cookie plugin

jQuery cookie plugin makes the cookie handling so simple.

First you have to include jquery.cookie.js plugin
and your work is done..

simple code to manipulate cookie.

Set cookie
$.cookie(cookiename, cookievalue,{expires: 30});
Note: expires takes the time duration in days

Get cookie
$.cookie(cookiename);

Delete cookie
$.cookie(cookiename, null,{expires: 30});

Click here to download jquery.cookie plugin

jQuery quicksearch plugin

Here is a useful plugin to quickly search anything from your table or list.

Just add this little cod after linking the quicksearch.js

For Table:
$('table#myTable tbody tr').quicksearch({
position: 'before',
attached: 'table#myTable',
labelText: 'Quick Search : '
});

For List:
$('ul#myList').quicksearch({
position: 'before',
attached: 'ul#myList',
loaderText: '',
delay: 100
})


Click on the link to download jQuery plugin

Wednesday, September 2, 2009

Javascript XML Parsing Problem Solution in Internet Explorer

function loadXMLDoc(dname)

{

var xmlDoc;

if (navigator.userAgent.indexOf('MSIE')>=0)

// Internet Explorer

{

xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.async=false;

xmlDoc.load(dname);

return xmlDoc;

}

else

{

xmlDoc=new window.XMLHttpRequest();

xmlDoc.open("GET",dname,false);

xmlDoc.send("");

return xmlDoc.responseXML;

}

alert("Error loading document");

return null;

}

Monday, August 31, 2009

jQuery - Center a div or any control

Here is a short code to centralize your div or any html control using Jquery..
Dependency could be jquery-1.3.2.js

$('#divid').css('top',$(window).height()/2 - $('#divid').height()/2 + $(window).scrollTop());
$('#divid').css('left',$(window).width()/2 - $('#divid').width()/2 + $(window).scrollLeft());

You can use animate to get some effect to the moving operation.

$('#divid').animate({top: $(window).height()/2 - $('#divid').height()/2 + $(window).scrollTop()},500);
$('#divid').
animate({left: $(window).width()/2 - $('#divid').width()/2 + $(window).scrollLeft()},500);

Friday, August 28, 2009

Language Translation API ASP.NET

private string translateme(string stringToTranslate, string fromLanguage, string toLanguage)

{

const int bufSizeMax = 65536;

const int bufSizeMin = 8192;

try

{

// by default format? is text.

// so we don't need to send a format? key

string requestUri = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + stringToTranslate + "&langpair=" + fromLanguage + "%7C" + toLanguage;

// execute the request and get the response stream

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream responseStream = response.GetResponseStream();

// get the length of the content returned by the request

int length = (int)response.ContentLength;

int bufSize = bufSizeMin;

if (length > bufSize)

bufSize = length > bufSizeMax ? bufSizeMax : length;

// allocate buffer and StringBuilder for reading response

byte[] buf = new byte[bufSize];

StringBuilder sb = new StringBuilder(bufSize);

// read the whole response

while ((length = responseStream.Read(buf, 0, buf.Length)) != 0)

{

sb.Append(Encoding.UTF8.GetString(buf, 0, length));

}

// the format of the response is like this

// {"responseData": {"translatedText":"¿Cómo estás?"}, "responseDetails": null, "responseStatus": 200}

// so now let's clean up the response by manipulating the string

string translatedText = sb.Remove(0, 36).ToString();

return translatedText.Substring(0, translatedText.IndexOf("\"},"));

}

catch

{

return "";

}

}