? ajaxsubmit/ajaxsubmit_ics.patch
Index: ajaxsubmit/ajaxsubmit.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/jstools/ajaxsubmit/ajaxsubmit.js,v
retrieving revision 1.10
diff -u -p -r1.10 ajaxsubmit.js
--- ajaxsubmit/ajaxsubmit.js	27 Jun 2007 15:36:29 -0000	1.10
+++ ajaxsubmit/ajaxsubmit.js	12 Feb 2008 12:56:24 -0000
@@ -3,6 +3,16 @@
 /**
  * Attaches the ajaxsubmit behaviour to forms.
  */
+// develCuy: Handles scrolling
+function ajaxsubmit_name_focus(name) {
+  if(window.location.href.indexOf('#')==-1){
+    window.location.href=window.location.href+'#'+name;
+  }else{
+    var _section = window.location.href.indexOf('#');
+    window.location.href=window.location.href.substring(0,_section)+'#'+name;
+  }
+  document.close();
+}
 Drupal.behaviors.ajaxSubmit = function (context) {
   $('form.ajaxsubmit:not(.ajaxsubmit-processed)').each(function () {
     if (this.ajaxsubmit_target) {
@@ -83,9 +93,6 @@ Drupal.ajaxsubmit.prototype.onsubmit = f
  * Handler for the form redirection completion.
  */
 Drupal.ajaxsubmit.prototype.oncomplete = function (data) {
-  // Remove progressbar
-  $(this.progress.element).remove();
-  this.progress = null;
   $(this.target).html(data['message']);
   if (data['errors']) {
     for (id in data['errors']) {
@@ -95,8 +102,42 @@ Drupal.ajaxsubmit.prototype.oncomplete =
   }
   // Set preview.
   if (data['preview']) {
+    // develCuy: Display and fix focus
+    $('#comment-form #edit-comment').css({display:'none'});
     $(this.target).html($(this.target).html() + data['preview']);
+    setTimeout("$('#comment-form #edit-comment').css({display:''});ajaxsubmit_name_focus('comment-')", 50);
+    // Remove progressbar
+    $(this.progress.element).remove();
+  }else{
+  // develCuy: reload comments thread
+    var backend_Hook = function (data) {
+      // Display and fix focus
+      try{
+      _display = $('#comments').css('display');
+      $('#comments').html(data);
+      // Reattach behaviors
+      Drupal.attachBehaviors();
+      // Fix rendering and focus
+      //$('#comments').css({display:'none'});
+      setTimeout("/*$('#comments').css({display:'"+_display+"'});*/ajaxsubmit_name_focus('new')", 50);
+      // Remove progressbar
+    }catch(e){}
+    }
+    // Get basepath
+    var _basepath = this.form.ajaxsubmit_basepath.value;
+    // Process Target URL(form action)
+    var _url = $(this.form).attr('action');
+    _url = '/'+_url.substr(_basepath.length);
+    _url = _basepath+'ajaxsubmit/backend/'+'comment'+'/'+'thread'+_url;
+    $.ajax({
+      dateType: 'json',
+      type: 'GET',
+      url: _url,
+      success: backend_Hook
+    });
   }
+  // Clean progressbar
+  this.progress = null;
   // Redirect.
   if (data['destination']) {
     window.location = Drupal.url(data['destination']);
Index: ajaxsubmit/ajaxsubmit.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/jstools/ajaxsubmit/ajaxsubmit.module,v
retrieving revision 1.12
diff -u -p -r1.12 ajaxsubmit.module
--- ajaxsubmit/ajaxsubmit.module	9 Aug 2007 14:42:37 -0000	1.12
+++ ajaxsubmit/ajaxsubmit.module	12 Feb 2008 12:56:24 -0000
@@ -34,6 +34,10 @@
 function ajaxsubmit_form_alter($form_id, &$form) {
   if (in_array($form_id, array_filter(variable_get('ajaxsubmit_forms', array())))) {
     $form['#ajaxsubmit'] = TRUE;
+    $form['ajaxsubmit_basepath'] = array(
+      '#type' => 'hidden',
+      '#value' => base_path()
+    );
   }
   if ($form['#ajaxsubmit']) {
     // If we're using ajaxsubmit and the form's already been submitted, redirect.
@@ -109,6 +113,13 @@ function ajaxsubmit_menu($may_cache) {
       'type' => MENU_CALLBACK,
       'callback' => 'ajaxsubmit_progress'
      );
+    $items[] = array(
+      'path' => 'ajaxsubmit/backend',
+      'title' => t('ICS backend'),
+      'access' => user_access('access content'),
+      'type' => MENU_CALLBACK,
+      'callback' => 'ajaxsubmit_ics'
+    );
   }
   return $items;
 }
@@ -174,4 +185,33 @@ function ajaxsubmit_progress() {
   $percentage = floor(($_SESSION[$form_id . '_total'] - $_SESSION[$form_id . '_remaining']) / $_SESSION[$form_id . '_total'] * 100);
   $message = ($percentage == 100) ? t('Submit complete') : t('Submit in progress');
   print drupal_to_js(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message));
-}
\ No newline at end of file
+}
+
+/**
+ * ICS: Render and return requested HTML 
+ * 
+ */
+function ajaxsubmit_ics($module, $action){
+  // 
+  switch($module) {
+    case 'comment':
+      switch($action) {
+        case 'thread':
+          // Get variables
+          $_node_id = arg(6);
+          /* For replies, have to create submit form when click reply link
+          $_comment_id = arg(7);
+           */
+          $_comment_id = 0;
+          
+          // Prepare data
+          $_node = node_load($_node_id);
+          
+          // Return HTML
+          print comment_render($_node, $_comment_id);
+          break;
+      }
+      break;
+  }
+  exit();
+}
