From ea3819859952af9fc7391316dd2b4aaca266dddc Mon Sep 17 00:00:00 2001
From: James Andres <james.andres@gmail.com>
Date: Fri, 22 Feb 2013 11:24:25 -0500
Subject: [PATCH] Disabling ajax_comments on full comment pages.

---
 ...at-Edit-link-works-after-Cancel-or-Save-i.patch | 26 ++++++++++++++++++++++
 ajax_comments.module                               | 18 ++++++++++-----
 ajax_comments.patch                                | 19 ++++++++++++++++
 3 files changed, 58 insertions(+), 5 deletions(-)
 create mode 100644 Ensuring-that-Edit-link-works-after-Cancel-or-Save-i.patch
 create mode 100644 ajax_comments.patch

diff --git a/Ensuring-that-Edit-link-works-after-Cancel-or-Save-i.patch b/Ensuring-that-Edit-link-works-after-Cancel-or-Save-i.patch
new file mode 100644
index 0000000..5e41794
--- /dev/null
+++ b/Ensuring-that-Edit-link-works-after-Cancel-or-Save-i.patch
@@ -0,0 +1,26 @@
+From 8bd1b812a6ff86dda377d53446cef05897a9f763 Mon Sep 17 00:00:00 2001
+From: James Andres <james.andres@gmail.com>
+Date: Fri, 22 Feb 2013 10:13:02 -0500
+Subject: [PATCH] Ensuring that 'Edit' link works after 'Cancel' or 'Save' in
+ all cases.
+
+---
+ ajax_comments.module | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/ajax_comments.module b/ajax_comments.module
+index e384f45..b167b73 100644
+--- a/ajax_comments.module
++++ b/ajax_comments.module
+@@ -498,7 +498,7 @@ function ajax_comments_edit($comment) {
+   $form = drupal_render($form_build);
+ 
+   // Replace comment with form.
+-  $commands[] = ajax_command_replace('#comment-wrapper-' . $comment->cid . ' >.comment', $form);
++  $commands[] = ajax_command_replace('#comment-wrapper-' . $comment->cid . ' .comment:first', $form);
+ 
+   return array('#type' => 'ajax', '#commands' => $commands);
+ }
+-- 
+1.8.1.3
+
diff --git a/ajax_comments.module b/ajax_comments.module
index b167b73..67fdba5 100644
--- a/ajax_comments.module
+++ b/ajax_comments.module
@@ -65,6 +65,13 @@ function ajax_comments_menu() {
 }
 
 /**
+ * Returns TRUE when currently on a full comment page.
+ */
+function ajax_comments_is_comment_page() {
+  return arg(0) == 'comment' && is_numeric(arg(1));
+}
+
+/**
  * Implements hook_preprocess_node().
  *
  * AJAXify "Add new comment" link when there is no default form.
@@ -77,7 +84,7 @@ function ajax_comments_preprocess_node(&$variables) {
 
   $node = $variables['node'];
 
-  if (!ajax_comments_node_type_active($node->type)) {
+  if (!ajax_comments_node_type_active($node->type) || ajax_comments_is_comment_page()) {
     return;
   }
 
@@ -97,7 +104,7 @@ function ajax_comments_preprocess_node(&$variables) {
  */
 function ajax_comments_form_comment_form_alter(&$form, &$form_state, $form_id) {
   // Check to see if this node type uses ajax comments.
-  if (!ajax_comments_node_type_active($form['#node']->type)) {
+  if (!ajax_comments_node_type_active($form['#node']->type) || ajax_comments_is_comment_page()) {
     return;
   }
 
@@ -128,8 +135,9 @@ function ajax_comments_form_comment_confirm_delete_alter(&$form, &$form_state, $
   $comment = $form['#comment'];
   $node = node_load($comment->nid);
 
-  // Check to see if this node type uses ajax comments.
-  if (!ajax_comments_node_type_active($node->type)) {
+  // Check to see if this node type uses ajax comments or if we are on a full
+  // comment page.
+  if (!ajax_comments_node_type_active($node->type) || ajax_comments_is_comment_page()) {
     return;
   }
 
@@ -308,7 +316,7 @@ function ajax_comments_delete_js($form, &$form_state) {
 function ajax_comments_comment_view($comment, $view_mode, $langcode) {
   $active = ajax_comments_node_type_active(substr($comment->node_type, strlen('comment_node_')));
 
-  if (!$active) {
+  if (!$active || ajax_comments_is_comment_page()) {
     return;
   }
 
diff --git a/ajax_comments.patch b/ajax_comments.patch
new file mode 100644
index 0000000..1f1927b
--- /dev/null
+++ b/ajax_comments.patch
@@ -0,0 +1,19 @@
+commit 8bd1b812a6ff86dda377d53446cef05897a9f763
+Author: James Andres <james.andres@gmail.com>
+Date:   Fri Feb 22 10:13:02 2013 -0500
+
+    Ensuring that 'Edit' link works after 'Cancel' or 'Save' in all cases.
+
+diff --git a/ajax_comments.module b/ajax_comments.module
+index e384f45..b167b73 100644
+--- a/ajax_comments.module
++++ b/ajax_comments.module
+@@ -498,7 +498,7 @@ function ajax_comments_edit($comment) {
+   $form = drupal_render($form_build);
+ 
+   // Replace comment with form.
+-  $commands[] = ajax_command_replace('#comment-wrapper-' . $comment->cid . ' >.comment', $form);
++  $commands[] = ajax_command_replace('#comment-wrapper-' . $comment->cid . ' .comment:first', $form);
+ 
+   return array('#type' => 'ajax', '#commands' => $commands);
+ }
-- 
1.8.1.3

