Tuesday, 8 May 2012

JQuery & SharePoint 2010

As  the way I'm experiencing SharePoint through Internet resources, sometimes it takes me a while until I found the right steps to do something.
For using JQuery in SP2010, there are heaps of good resources out there. but I had to mix several of them, to understand what exactly I should do to be able to start using it in my environment.
Here is a summary of what I learned:

What is JQuery?
they say "JQuery is a new kind of JavaScript Library"
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

Install/Add it to SharePoint:
As far as I understand, there is no need for any type of installation. But to be able to use the JQuery in your code, you need to have a reference to where the JQuery library is.
I already found three ways to access to this library, and I leave it to your choice, which one is the best. there are lots of debates out there, so you may search it for yourself.

Please do remember, at the time of this post the latest version is 1.7.2
You can find the latest version from jquery.com

1. CDN Hosted JQuery. (reference to an on-line place, where the library is hosted.)
A number of large enterprises provide hosted copies of jQuery on existing CDN networks that are available for public use. Below are links to the CDN-hosted copies of jQuery that you may hotlink to. 

2. 14 Hive folder
If you have access to the SharePoint server, you can save the "Minified version" or the "Full version" in this address and then link to it from your code.
14 hive\TEMPLATE\LAYOUTS\_CustomJScripts 
(if you don't know how to go to 14 Hive, it may be better idea not to do any change on your server and use the library method. by the way, it is here: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14)
3. SharePoint Library
Just create a resources library in your root site and upload your JQuery files there.

As it seems, the method of using SharePoint library is the simplest of three. for 14 Hive, you need to have access to your server and if you use CDN, well it is an online resource so it means your site or better say, your codes are only working when you have Internet access. what if Internet is temporary down but you need your Intranet to stay live, or what if one of those big guys who'se hosted the library (like google or microsoft) decides to do not support JQuery anymore. Are you willing to go through all of your codes and change the references everywhere.

Just saying, think about it and decide wisely depend on your situation.

I will continue these post, along with my own tests and will keep you posted anything I find on the way.