cis notified web server of a job completion; upload form interface and validation...
[living-lab-site.git] / js / jquery.ui.ajax_links_maker.js
1 /*
2  * jQuery UI AJAX Links Maker 1.0.0 beta
3  * 
4  * Transforms normal anchors into AJAX anchors. The AJAX URL is took from
5  * href HTML attribute. Anchors to be transformed are found within elements
6  * listed in option linkSelectors. The AJAX content retrieved from the server
7  * is placed in the option target.
8  *
9  * Copyright 2011, Călin-Andrei Burloiu
10  * Dual licensed under the MIT or GPL Version 2 licenses.
11  * http://jquery.org/license
12  *
13  * Depends:
14  *   jquery.ui.core.js
15  *   jquery.ui.widget.js
16  */
17 (function( $, undefined ) {
18
19 $.widget( "ui.ajaxLinksMaker", {
20         version: "1.0.0 beta",
21         options: {
22                 
23         },
24         
25         _create: function() {
26                 var widget = this;
27                 
28                 for (i in widget.options.linkSelectors)
29                 {
30                         var selector = widget.options.linkSelectors[i];
31
32                         $(selector + ' a', widget[0])
33                                 .each(function(index) {
34                                         var url = $(this).attr('href');
35                                         
36                                         if (typeof(url) == 'undefined')
37                                                 return;
38                                         
39                                         $(this)
40                                                 .click(function(event) {
41                                                         event.preventDefault();
42                                                         
43                                                         $.post(
44                                                                         url,
45                                                                         function(data) {
46                                                                                 $(widget.options.target).html(data);
47                                                                         });
48                                                 });
49                                 });
50                                 
51                 }
52         }
53         
54 });
55
56 })( jQuery );