Archive for February, 2011

Almost 3 years ago Scottgu announced that Microsoft would begin offering product support for jQuery. Now Microsoft is playing a great role on contributing to jQuery plugin. From past 8 to 9 months they were striving on 3 major jQuery plugins.

They were:

          1. Templating

          2. Data-Linking

          3. Globalization
The good news is Templating plugin created by Microsoft is going to be added officially as a new feature in jQuery 1.5 version 

1) Client side templating (jquery.tmpl.js)

Say suppose you want to get a set of data and display stuffs in structured manner then use template. Initially we used to concatenate the strings and display the data that was very slow process.
Below is one example how to use the template plugin. In below code we are displaying the product object data in UI. The data inside the product can be fetched from server by calling $.ajax
Above script is html its type sets to text / html that says the browser not to interpreted
Content within. It injects the HTML. Braces indicating the placeholder for knowing more about the template plugin please read.

<form runat="server" id="form1">
<div id="productContainer"></div>
<script id="productTemplate" type="text/html"><div>
<h3>${name} = $(formatCurrency(price)})</h3>
<img&nbsp;src ="Products/${picture}"/>
{{html description}}

Above script is html its type sets to text / html that says the browser not to interpreted
Content within. It injects the HTML. Braces indicating the placeholder for knowing more about the template plugin please read.


<Script type="text/javascript">
//Array of products
var products = [
{name : "Apple",price : 3.44, picture : "Apple.png", description: "<i><b>Super</b></i> delicious"}
,{name : "Bacon",price : 4.55, picture : "Bacon.png", description: "Quality bacon"}
,{name : "Ice Cream",price : 12.00, picture : "IceCream.png", description: "Low fat ice cream."}

//render the array of products
tmpl method returns the fragment of html and append to productcontainer.
function formatCurrency(num) {
num = isNaN(num) || num === '' || num === null ? 0.00 : num ;
return "$" + parsefloat(num).tofixed(2);

2) Data Linking (jquery.datalink.js)

Data linking plugin gives the easy way to synchronized to UI field and data object. Its easy way to track the changes in happened in the UI elements and vice versa. Initially we used to check the each form input element which changed and then update the javascript object and then send it to server for update. Now we don’t need to bother about the changes happened in the UI element. The moment any UI element is changed the javascript object will get automatically updated and vice versa. By default linkdata plugin does two-way data binding.

Jquery.datalink.js uses jQuery 1.4.3 version therefore please makes sure that you are including this version of jquery while using datalink plugin.

Let’s look at the below example. Here we have 2 input fields which are linked with a javascript object say product. Now any changes made in product object will reflect in UI automatically and vice versa is true.

product Name : <input name="name" id="name" type="text"/>
product price : <input name="price" id="price" type="text"/>
<script class="hiddenSpellError"><!--mce:1--></script>
<script class="hiddenSpellError"><!--mce:2--></script>
//link product form to product object
var product = {}

//changes to product object will be sync'ed&nbsp;with product form
$(product).data("name","Ice Cream");

//changes to product form will be synced with product object
$("#btnSave").click(function ( ) {
//show product object
alert([, product.price]);

3) Jquery glob (jquery.glob.js)

Globalization plugin can be used to localize the website to any region.
You want to globalize or localize your own plugin then use this plugin.
1.Supports over 350 different cultures, including country-specific cultures and language, country-neutral cultures.

2.Culture information for each culture is available through a simple data structure, accessible to plugins for their own purposes.

3.Supports formatting dates to any of these cultures, including those that have non-Gregorian calendars, Gregorian calendars with a year offset, and calendars with multiple Eras.

4.Supports formatting numbers to strings as numbers, currency, or percentages, to any of these cultures, including those with very special formatting rules, such as number group sizes that differ between currency and percentages, or have a different number of digits.

5.Supports parsing dates and numbers from the culture specific string representation of them back into JavaScript dates and numbers.

6.Supports localization through a localize() API that handles selecting the best known match automatically.

7.Supports the Accept-Language header value as-is, to select the culture best suited to the user per their browser settings.

8.Extensibility allows for plugins to access and add to the culture information, including cultures it does not already support.

9.Retrofitted the jQueryUI DatePicker plugin to use this plugin, rather than its existing globalization support. This was fairly simple to do and immediately opens up the range of cultures supported by the plugin to the full set of cultures supported by jQuery.glob.js.

Let’s see below example we want to use the date picker and make it globalize so that in any country if we use this then it will show the calendar on their language.

<select id="<span class=">selectCulture"></select>
<option> Loading...</option>
<div id="picker">
//populate select list
var select = $("#selectCulture").get(0);
select.options.length = 0;
$.each($.cultures, function ( ) {
select.options[select.options.length] = new Option (this.englishName,;

$("#selectCulture").change(function () {
//set culture form select list

//Destroy and create datepicker
changeYear : true
<span style="font-family: <span class=;">Calibri</span>; font-size: large;"> 

Menu Widget

Posted: February 6, 2011 in jQuery
Tags: ,

I was trying to make my own menu widget using jQuery and  I came with this below Widget.

//Menu Widget created by Rupesh
(function ($) {

    JDQMenu = {

        options: {

          items: { "Reports":[{

                      "File" : { "Report1":"#","Report2":"#","Report3":"#" }

                      ,"Edit" : { "Report4":"#",  "Report5":"#" }

                      ,"Report" : { "Report6":"#",  "Report7":"#" }

                      ,"Help" : {"How to see Reports":"#"}


                  ,"Clients" : [{

                      "Search" : { "Client1":"#","Client2":"#","v3":"#" }

                      ,"Edit" : { "Client4":"#",  "Client5":"#" }

                      ,"Help" : {"How to see Clients":"#"}


                  ,"Tools" : [{

                      "View": { "Tool1":"#","Tool2":"#","Tool3":"#"}

                       ,"Help" : {"How to find Tools":"#"}



            ,selected_menu : "Reports"


        ,_init : function ( ) {

           this._create_menu( );


        ,_create_menu : function ( ) {

           var that= this,el = that.element,itms=that.options.items,sel=$.trim(that.options.selected_menu);

           if( sel !="default") {

           //save element in widget cache

            var data = $(this).data(sel);

                //refresh the menu


                //take element from inner widget cache data

                if(data) {


                } else {

                    if( itms[sel] ) {

                        var menu_itms = itms[sel][0];

                        $.each(menu_itms , function ( i,v ) {

                            el.append( $("
	<li>").append( $("<a>",{"class":"menu_trigger", "href":"#","text":i}) ).append("") );</a></li>







                //Show the menu by triggering it




        ,show_menu : function (el) {

            el  = el.replace("#",'');

            this.options.selected_menu = el;

            this._create_menu( );



    $.widget("ui.JDQMenu", JDQMenu);    

})( jQuery );

Now for using this widget you just have to add one ul element and call our JDQMenu widget’s.

<ul id="menu">
<script type="text/javascript?