users can comment videos and can like and dislike comments => a new production version
[living-lab-site.git] / js / jquery.ui.ajax_links_maker.js
diff --git a/js/jquery.ui.ajax_links_maker.js b/js/jquery.ui.ajax_links_maker.js
new file mode 100644 (file)
index 0000000..2895e70
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * jQuery UI AJAX Links Maker 1.0.0 beta
+ * 
+ * Transforms normal anchors into AJAX anchors. The AJAX URL is took from
+ * href HTML attribute. Anchors to be transformed are found within elements
+ * listed in option linkSelectors. The AJAX content retrieved from the server
+ * is placed in the option target.
+ *
+ * Copyright 2011, Călin-Andrei Burloiu
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * Depends:
+ *   jquery.ui.core.js
+ *   jquery.ui.widget.js
+ */
+(function( $, undefined ) {
+
+$.widget( "ui.ajaxLinksMaker", {
+       version: "1.0.0 beta",
+       options: {
+               
+       },
+       
+       _create: function() {
+               var widget = this;
+               
+               for (i in widget.options.linkSelectors)
+               {
+                       var selector = widget.options.linkSelectors[i];
+
+                       $(selector + ' a', widget[0])
+                               .each(function(index) {
+                                       var url = $(this).attr('href');
+                                       
+                                       if (typeof(url) == 'undefined')
+                                               return;
+                                       
+                                       $(this)
+                                               .click(function(event) {
+                                                       event.preventDefault();
+                                                       
+                                                       $.post(
+                                                                       url,
+                                                                       function(data) {
+                                                                               $(widget.options.target).html(data);
+                                                                       });
+                                               });
+                               });
+                               
+               }
+       }
+       
+});
+
+})( jQuery );
\ No newline at end of file