Deleting last comment sometimes also delete "add new comment" form (default form bottom of the page)
I think this is erorr in ajax_comments_comment_view_alter()/ajax_comments_entity_prepare_view() and i think we can use native drupal comment module div's without this functions (without adding own div's, only add classes and id's to existing divs).
I will try to make it on this week.

UPDATED:
Motivation:
- Decrease chance to be broken by other modules/themes. Refactoring ajax logic from using html IDs to classes
- Makes comment form id/class more obvious (based on node and comment, not on the current time).

As result with this patch ajax_comments:
- compatible with Views module. Displaying comments for nodes in views work fine (delete, edit and cancel - flat and threaded)
- compatible with Comment goodness module.
- compatible with Display Suite module
- has NodeJS integration

Also fixes:
#2312957: Issues when comments has a file/image field.
#2293275: Replying to a comment in a flat list.
#2327353: Set focus on comment field
#2288281: Reply link callback not found error 404

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

formatC'vt’s picture

Title: Deleting last comment sometimes also delete "add comment" form » Make 7.x-1.x-dev version work. Part 2.
Status: Needs work » Needs review
FileSize
37.43 KB

I'm done big work, and make it work, again =)
Motivation:
- Decrease chance to be broken by other modules/themes. Refactoring ajax logic from using html IDs to classes
- Makes comment form id/class more obvious (based on node and comment, not on the current time).

As result with this patch ajax_comments:
- compatible with Views module. Displaying comments for nodes in views work fine (delete, edit, cancel - flat and threaded)
- compatible with Comment goodness module. Also in combination Views + Comment goodness. Warning: Comment goodnes doesn't work with jQuery update module (see #2294195: .live() is not a function error) and broke ajax calls.
- compatible with Display Suite module

also i do some code cleanup (delete unused functions and commented code)

formatC'vt’s picture

- Add unique buttons IDs (need for Views with enabled AJAX)
- Set focus on comment text field (#2327353: Set focus on comment field)

formatC'vt’s picture

Status: Needs review » Needs work

this patch with bug in "Show reply form on the same page as comments" mode (and form caching bug in this mode). I try to fix it on this week.

formatC'vt’s picture

Issue summary: View changes
Status: Needs work » Needs review
Related issues: +#2288281: Reply link callback not found error 404
FileSize
41.27 KB

- fix bug with "Show reply form on the same page as comments" option - #2288281: Reply link callback not found error 404

andypost’s picture

  1. +++ b/ajax_comments.admin.inc
    @@ -23,11 +23,11 @@ function ajax_comments_settings() {
    -  $form['ajax_comments_scroll'] = array(
    +  $form['ajax_comments_disable_scroll'] = array(
    ...
    -    '#default_value' => variable_get('ajax_comments_scroll', ''),
    +    '#default_value' => variable_get('ajax_comments_disable_scroll', ''),
    

    I see no reason in this!
    Once you change variables you should provide hook_update_N() to convert variables.
    This change breaks BC and causing other contrib modules to update - please aware that!

  2. +++ b/ajax_comments.js
    @@ -1,98 +1,92 @@
    +$.fn.ajaxCommentsScrollToElement = function() {
    ...
    +$.fn.ajaxCommentsAddDummyDivAfter = function() {
    ...
    +$.fn.ajaxCommentsAddDummyDivInto = function() {
    ...
    +$.fn.ajaxCommentsReplace = function() {
    ...
    +$.fn.ajaxCommentsBefore = function() {
    ...
    +$.fn.ajaxCommentsAfter = function() {
    ...
    +$.fn.ajaxCommentsPrepend = function() {
    

    The common practice to place this functions into Drupal.ajaxComments.*

    see http://cgit.drupalcode.org/drupal/tree/modules/contextual/contextual.js?...

  3. +++ b/ajax_comments.js
    @@ -1,98 +1,92 @@
    +    } catch (e) {
    +        alert('ajaxComments-ScrollToElementError: ' + e.name);
    ...
    +    } catch (e) {
    +        alert('ajaxComments-AddDummyDivAfter: ' + e.name);
    ...
    +    } catch (e) {
    +        alert('ajaxComments-AddDummyDivInto: ' + e.name);
    ...
    +    } catch (e) {
    +        alert('ajaxComments-Replace: ' + e.name)
    ...
    +    } catch (e) {
    +        alert('ajaxComments-Before: ' + e.name)
    ...
    +    } catch (e) {
    +        alert('ajaxComments-After: ' + e.name)
    ...
    +    } catch (e) {
    +        alert('ajaxComments-Prepend: ' + e.name)
    

    any reason for? this could scare an end user.

  4. +++ b/ajax_comments.module
    @@ -11,19 +9,20 @@
    -  $items['ajax_comments/reply/%node/%'] = array(
    +  $items['ajax_comments/reply/%node'] = array(
    ...
    -  $items['ajax_comments/edit/cancel/%node/%comment'] = array(
    ...
    +  $items['ajax_comments/reply/%node/%'] = array(
    

    this change is wrong, you need to make sure that 4 argument is existing comment or 0 (zero)

  5. +++ b/ajax_comments.module
    @@ -112,12 +95,6 @@ function ajax_comments_views_data() {
    -  // Only show on full nodes.
    -  /*
    -  if ($variables['teaser'] || $variables['view_mode'] != 'full') {
    
    @@ -148,49 +129,85 @@ function ajax_comments_form_comment_form_alter(&$form, &$form_state, $form_id) {
    -  //@TODO: is this still needed? Breaks in views anyways
    -  $node = menu_get_object();
    -  // there should be a better way to determine the current view mode
    -  if (is_object($node)){
    

    this looks strange...
    node_is_page() could not work in panels... the the check was explicit!

    By default comments are rendered only on full node page! http://cgit.drupalcode.org/drupal/tree/modules/comment/comment.module?h=...

  6. +++ b/ajax_comments.module
    @@ -148,49 +129,85 @@ function ajax_comments_form_comment_form_alter(&$form, &$form_state, $form_id) {
    +  // @todo: test without this hack, and remove
       // HACK, stop ctools from modifying us in node_comment_form.inc
    -  $form_state['ctools comment alter'] = FALSE;
    +  //$form_state['ctools comment alter'] = FALSE;
    

    this needs manual testing...

  7. +++ b/ajax_comments.module
    @@ -202,7 +219,7 @@ function ajax_comments_form_comment_confirm_delete_alter(&$form, &$form_state, $
    -      'effect' => 'fade',
    +      //'effect' => 'fade',
    

    please do not comment-out code...

  8. +++ b/ajax_comments.module
    @@ -536,12 +485,12 @@ function ajax_comments_entity_prepare_view($entities, $entity_type, $langcode) {
    -function ajax_comments_reply($node, $pid = NULL, $flag = 'node') {
    +function ajax_comments_reply($node, $pid = 0, $flag = 'node') {
    ...
    -  if ($pid == "NULL") $pid = NULL;
    +  //if ($pid == "NULL") $pid = NULL;
    

    any reason?!

formatC'vt’s picture

1. The reason is make name more simplify. This option (Disable scroll to comment) only in dev version of this module and still doesn't exist in release/beta.

2. Done. Now it's in Drupal style.

3. this is dev =) and error in js break all js on the page, replace alert to log

4. This check in ajax_comments_reply()

    // Make sure the comment is valid and published.
    if (!($comments = comment_load_multiple(array($pid), array('status' => COMMENT_PUBLISHED)))) {
      return MENU_NOT_FOUND;
    }

5. And this is already removed

6. I test it by myself but it is be good if it test someone else

7. OK, i will remove it

8. My bad =)

Thanks!

formatC'vt’s picture

- Added NodeJS integration
- Small bugfixes (see interdiff)

seiplax’s picture

In the current patch the Cancel text on line 181 can not be translated

/contrib/ajax_comments/ajax_comments.module:

177: // If this a reply to comment offer a 'cancel' button
178 if (isset($form_state['comment']->pid)) {
179: $form['actions']['cancel'] = array (
180 '#type' => 'button',
181: '#value' => 'Cancel',
182 '#access' => true,
183 '#weight' => 21,
184 '#limit_validation_errors' => array(),
185 );

If you want to have this as a separate issue, please re-open https://www.drupal.org/node/2334861

  • muschpusch committed 7a13ce0 on 7.x-1.x
    Issue #2320845 by formatC'vt: Fixed Make 7.x-1.x-dev version work. Part...
muschpusch’s picture

Status: Needs review » Fixed

Ah damn it! I'm really sorry i did something wrong since and didn't put you as the committer :/ But finally this got committed. Thanks a lot for putting so much effort in this!

formatC'vt’s picture

Hello, muschpusch! I glad to see you again. Do you have enough time to maintain this module?
When i lost hope i open this issue #2335709: Offering to maintain AJAX Comments, but i can close it.

muschpusch’s picture

Hey formatC'vt! Sorry for disappearing! I was pretty busy and just found some time to review the patch at drupalcon. Are you in Amsterdam? I think it's a good idea to make you co-maintainer see updated #2335709: Offering to maintain AJAX Comments

formatC'vt’s picture

No, I'm about 2000 km from the Amsterdam =) Thanks.

  • muschpusch committed 7a13ce0 on 8.x-1.x
    Issue #2320845 by formatC'vt: Fixed Make 7.x-1.x-dev version work. Part...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.