### Eclipse Workspace Patch 1.0 #P ajax_comments Index: ajax_comments.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ajax_comments/Attic/ajax_comments.module,v retrieving revision 1.1.2.39 diff -u -r1.1.2.39 ajax_comments.module --- ajax_comments.module 25 Oct 2010 05:16:48 -0000 1.1.2.39 +++ ajax_comments.module 31 Jan 2011 15:04:00 -0000 @@ -110,7 +110,17 @@ /** * Implementation of hook_form_FORM_ID_alter(). */ -function ajax_comments_form_comment_form_alter(&$form, $form_state) { +function ajax_comments_form_comment_form_alter(&$form, $form_state) { + // Add class for multiply comments form selection + $form['#attributes']['class'] = 'comment-form'; + // Change form id for single/multiply comment form processing + if ($form['#id'] == 'comment-form') { + $form['#id'] = 'comment-form-1'; + $form_num = 1; + } else { + $form_num = substr($form['#id'], strrpos($form['#id'], '-') + 1); + } + if ($form['nid']['#value']) { $node = node_load($form['nid']['#value']); } @@ -132,7 +142,7 @@ if ($all_allowed || isset($allowed_node_types[$node->type]) && $allowed_node_types[$node->type]) { if ((arg(1) != 'edit') && (arg(1) != 'reply') && (arg(2) != 'edit') && (arg(2) != 'reply')) { - $form['#prefix'] = '
'; + $form['#prefix'] = '
'; // Overriding PID param so it will appear on the form. $form['pid']['#type'] = 'hidden'; @@ -147,7 +157,7 @@ // We should set specific ID to let ahah wrapper know what to wrap on ajax // loaded comment-form even if we have many submit buttons on the page. - $form['preview']['#id'] = "ajax-comments-preview"; + $form['preview']['#id'] = "ajax-comments-preview-" . $form_num; $form['preview']['#ahah'] = array( 'path' => 'ajax_comments/js', 'wrapper' => 'comment-preview', @@ -157,7 +167,7 @@ 'progress' => array('type' => '1bar', 'message' => t('Please wait...')), ); - $form['submit']['#id'] = "ajax-comments-submit"; + $form['submit']['#id'] = "ajax-comments-submit-" . $form_num; $form['submit']['#submit'] = array('ajax_comments_submit'); $form['submit']['#ahah'] = array( 'path' => 'ajax_comments/js', Index: ajax_comments.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ajax_comments/Attic/ajax_comments.js,v retrieving revision 1.1.2.47 diff -u -r1.1.2.47 ajax_comments.js --- ajax_comments.js 25 Oct 2010 05:31:03 -0000 1.1.2.47 +++ ajax_comments.js 31 Jan 2011 15:04:00 -0000 @@ -1,10 +1,3 @@ -// $Id: ajax_comments.js,v 1.1.2.47 2010/10/25 05:31:03 rjbrown99 Exp $ - -/** - * @file - * The primary AHAH behaviors and handlers for AJAX commenting. - */ - var commentbox = ".comment"; var ctrl = false; var last_submit; @@ -13,13 +6,7 @@ var firsttime_init = true; /** - * Attach AHAH behavior to each AHAH form element. - * - * Define a function as a property of Drupal.behaviors. This will call the code - * block when the DOM has finished loading. In this case, we attach the AHAH - * behavior to each AHAH form element. - * - * @see http://drupal.org/node/205296 + * Attaches the ahah behavior to each ahah form element. */ Drupal.behaviors.ajax_comments = function(context) { Drupal.ajax_comments_init_form(context); @@ -28,9 +15,8 @@ Drupal.ajax_comments_fold(context); } - // The CTRL key listener is for the comment deletion feature. - // It allows for bypassing the deletion confirmation dialog. - $(window).keydown(function(e) { + // Add Ctrl key listener for deletion feature. + $(window).keydown(function(e) { if(e.keyCode == 17) { ctrl = true; } @@ -38,9 +24,10 @@ $(window).keyup(function(e) { ctrl = false; // Add sending on Ctrl+Enter. - if ((e.ctrlKey) && ((e.keyCode == 0xA) || (e.keyCode == 0xD)) && !submitted) { + if ((e.ctrlKey) && ((e.keyCode == 0xA) || (e.keyCode == 0xD)) && ((typeof submitted == "undefined") || !submitted)) { submitted = true; - $('#ajax-comments-submit').click() + var form_num = ajax_comments_get_form_num_from_element(e.target); + $('#ajax-comments-submit-' + form_num).click(); } }); @@ -55,8 +42,17 @@ * as an on-page placement guide for a number of other actions (previews, new comments, etc.) */ Drupal.ajax_comments_init_form = function(context) { - $('#comment-form:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').each(function() { - form = $(this); + $('.comment-form:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').each(function() { + form = $(this); + + // Extract form number from id + var form_num = form.attr("id").substr(form.attr("id").search(/-(\d)$/) + 1); + var nid = ajax_comments_get_nid_from_href(form.attr('action')); + + // CSS selectors for submit and preview buttons + var comments_submit_sel = '#ajax-comments-submit-' + form_num; + var preview_submit_sel = '#ajax-comments-preview-' + form_num; + var comments_n_preview_sel = comments_submit_sel + ',' + preview_submit_sel; // Prepare the form when the DOM is ready. if ((Drupal.settings.ajax_comments_rows_default == undefined) || (!Drupal.settings.ajax_comments_rows_default)) { @@ -73,31 +69,34 @@ Drupal.settings.ajax_comments_blink_new = true; } - $('#edit-upload', form).bind('change', function(){ - $('#ajax-comments-submit,#ajax-comments-preview', form).attr('disabled', 1); + $('#edit-upload-' + form_num, form).bind('change', function(){ + $(comments_n_preview_sel, form).attr('disabled', 1); }); - // It's not possible to use 'click' or 'submit' events for AHAH sumits, so + // It's not possible to use 'click' or 'submit' events for ahah sumits, so // we should emulate it by up-down events. We need to check which elements // are actually clicked pressed, to make everything work correct. - $('#ajax-comments-submit,#ajax-comments-preview', form).bind('mousedown keydown', function() { last_submit = $(this).attr('id'); }); - $('#ajax-comments-submit,#ajax-comments-preview', form).bind('mouseup', function() { + + $(comments_n_preview_sel, form).bind('mousedown keydown', function() { + last_submit = $(this).attr('id'); + }); + $(comments_n_preview_sel, form).bind('mouseup', function() { if (last_submit == $(this).attr('id')) { - ajax_comments_show_progress(context); + ajax_comments_show_progress(form_num, context); ajax_comments_update_editors(); } }); - $('#ajax-comments-submit,#ajax-comments-preview', form).bind('keyup', function(event) { + $(comments_n_preview_sel, form).bind('keyup', function(event) { if (last_submit == $(this).attr('id') && event.keyCode == 13) { - ajax_comments_show_progress(context); + ajax_comments_show_progress(form_num, context); ajax_comments_update_editors(); } }); // Enable comments buttons back when attachement is uploaded. - $('#edit-attach', form).bind('mousedown keydown', function() { + $('#edit-attach-' + form_num, form).bind('mousedown keydown', function() { if (last_submit == $(this).attr('id')) { - $('#ajax-comments-submit,#ajax-comments-preview', form).removeAttr('disabled'); + $(comments_n_preview_sel, form).removeAttr('disabled'); } }); @@ -106,9 +105,9 @@ // Creating title link. form.parent('div').prev('h2:not(.ajax-comments-title-processed),h3:not(.ajax-comments-title-processed),h4:not(.ajax-comments-title-processed)').addClass('ajax-comments-title-processed').each(function(){ - var title = $(this).html(); - $(this).html('' + title + ''); - form.parent('div').attr('id','comment-form-content').removeClass("content"); + title = $(this).html(); + $(this).html(''+title+''); + form.parent('div').attr('id','comment-form-content-' + form_num).removeClass("content"); }); // Expanding form if needed. @@ -117,38 +116,42 @@ if (page_url.match('#')) { fragment = page_url.split('#')[1]; } + + var title_sel = '#comment-form-title-' + form_num; + var content_sel = '#comment-form-content-' + form_num; - if ((fragment == 'comment-form' || Drupal.settings.ajax_comments_always_expand_form) && firsttime_init) { - $('#comment-form-title', context).addClass('pressed'); - $('#comment-form-content').attr('cid', 0); + if ((fragment == 'comment-form' + form_num || Drupal.settings.ajax_comments_always_expand_form) && firsttime_init) { + $(title_sel, context).addClass('pressed'); + $(content_sel).attr('cid', 0); } else { // Fast hide form. - $('#comment-form-content', context).hide(); + $(content_sel, context).hide(); } // Attaching event to title link. - $('#comment-form-title:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').click(Drupal.ajax_comments_reply_click); + $(title_sel + ':not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').click(Drupal.ajax_comments_reply_click); // Moving preview in a proper place. if (ajax_comments_is_reply_to_node(action)) { - $('.ajax-comments-title-processed').before($('#comment-preview')); + $('#comments-' + nid + ' .ajax-comments-title-processed').before($('#comment-preview-' + form_num)); } else { - $('#comment-form-content').before($('#comment-preview')); + $(content_sel).before($('#comment-preview-' + form_num)); } - if (!$('#comment-form-content').attr('cid')) { - $('#comment-form-content').attr('cid', -1); + if (!$(content_sel).attr('cid')) { + $(content_sel).attr('cid', -1); } if(typeof(fix_control_size)!='undefined'){ fix_control_size(); } + }); } /** * Attach behaviors to comment links. - * + * * This function adds event handlers for when a user clicks on certain page elements, including * reply links, quote links, and edit links. */ @@ -160,12 +163,14 @@ $('.quote a:not(.ajax-comments-processed)', context).addClass('ajax-comments-processed').each(function(){ href = $(this).attr('href'); if (ajax_comments_is_reply_to_node(href)) { + var form_num = ajax_comments_get_form_num_from_href(href); + $(this).click(function(){ - $('#comment-form').attr('action', $(this).attr('href')); - ajax_comments_reload_form(0, 'pid'); + $('#comment-form-' + form_num).attr('action', $(this).attr('href')); + ajax_comments_reload_form(form_num, 0, 'pid'); - $('#comment-form-title', context).click(); - ajax_comments_scroll_to_comment_form(); + $('#comment-form-title-' + form_num, context).click(); + ajax_comments_scroll_to_comment_form(form_num); return false; }); } @@ -188,12 +193,11 @@ /** * Fold indednted comments threads. - * - * Comment folding is configured via the AJAX comments administrative page. It enables - * replies to comments to be 'folded' under the parent. + * + * TODO: check div selector */ Drupal.ajax_comments_fold = function(context) { - $('#comments > .indented:not(.ajax-comments-processed)', context).addClass('folded').addClass('ajax-comments-processed').each(function (){ + $('div[id^=comments-] > .indented:not(.ajax-comments-processed)', context).addClass('folded').addClass('ajax-comments-processed').each(function (){ $thread = $(this); // Hide threads. $thread.css('display', 'none'); @@ -232,87 +236,95 @@ /** * Reply links handler. - * + * * This function is called as the handler to the .click() event. The events were bound * during the init functions above. This is the function executed when the user clicks * on a 'reply' button on the page or the 'Post new comment' link. */ Drupal.ajax_comments_reply_click = function() { - // We should only handle non pressed links. + + // We should only handle non presed links. if (!$(this).is('.pressed')){ action = $(this).attr('href'); - form_action = $('#comment-form').attr('action'); + var comment_nid = ajax_comments_get_nid_from_href(action); + var form_num = ajax_comments_get_form_num_from_href(action); + + form_action = $('#comment-form-' + form_num).attr('action'); link_cid = ajax_comments_get_cid_from_href(action); rows = Drupal.settings.ajax_comments_rows_default; - if ($('#comment-form-content').attr('cid') != link_cid) { + + // CSS selectors + var comment_content_sel = '#comment-form-content-' + form_num; + + if ($('#comment-form-content-' + form_num).attr('cid') != link_cid) { // We should remove any WYSIWYG before moving controls. ajax_comments_remove_editors(); // Move form from old position. if (ajax_comments_is_reply_to_node(action)) { - $('#comment-form-content').removeClass('indented'); - if ($('#comment-form-content:visible').length) { - $('#comment-form-content').after('
'); + $(comment_content_sel).removeClass('indented'); + if ($(comment_content_sel + ':visible').length) { + $(comment_content_sel).after('
'); $('.sizer').slideUp(speed, function(){ $(this).remove(); }); } - $(this).parents('h2,h3,h4').after($('#comment-form-content')); + $(this).parents('h2,h3,h4').after($(comment_content_sel)); rows = Drupal.settings.ajax_comments_rows_default; - $('.ajax-comments-title-processed').before($('#comment-preview')); + $('.ajax-comments-title-processed').before($('#comment-preview-' + form_num)); } else { - $('#comment-form-content').addClass('indented'); - if ($('#comment-form-content:visible').length) { - $('#comment-form-content').after('
'); + $(comment_content_sel).addClass('indented'); + if ($(comment_content_sel + ':visible').length) { + $(comment_content_sel).after('
'); $('.sizer').slideUp(speed, function(){ $(this).remove(); }); } folded_thread = $(this).parents(commentbox).next('.indented.folded'); if (folded_thread.length && Drupal.settings.comment_bonus_api_fold_comments) { $(this).parents(commentbox).find('.hide-thread').click(); - folded_thread.after($('#comment-form-content')); + folded_thread.after($(comment_content_sel)); } else { - $(this).parents(commentbox).after($('#comment-form-content')); + $(this).parents(commentbox).after($(comment_content_sel)); } rows = Drupal.settings.ajax_comments_rows_in_reply; - $('#comment-form-content').prepend($('#comment-preview')); + $(comment_content_sel).prepend($('#comment-preview-' + form_num)); } - $('#comment-form-content').hide(); + $(comment_content_sel).hide(); } // We don't need to load everything twice. if (!$(this).is('.last-clicked')) { // Reload form if preview is required. - if ((Drupal.settings.comment_preview_required && $('#ajax-comments-submit').length) || + if ((Drupal.settings.comment_preview_required && $('#ajax-comments-submit-' + form_num).length) || // Or if quoted comment or custom reload trigger. action.match('quote=1') || form_action.match('reload=1') ) { - $('#comment-form').attr('action', action) - ajax_comments_reload_form(link_cid, 'pid'); + $('#comment-form-' + form_num).attr('action', action) + ajax_comments_reload_form(form_num, link_cid, 'pid'); $('.editing').fadeTo('fast', 1); } else { - ajax_comments_rewind(link_cid, rows); - ajax_comments_scroll_to_comment_form(); + ajax_comments_rewind(form_num, link_cid, rows); + ajax_comments_scroll_to_comment_form(form_num); } } // ...and show the form after everything is done. - ajax_comments_expand_form(); + ajax_comments_expand_form(form_num); $('.pressed').removeClass('pressed'); $(this).addClass('pressed'); $('.last-clicked').removeClass('last-clicked'); $(this).addClass('last-clicked'); - $('#comment-form-content').attr('cid', link_cid); + $(comment_content_sel).attr('cid', link_cid); } else { // Handling double click. - if ((!$(this).is('#comment-form-title')) && (Drupal.settings.ajax_comments_always_expand_form)) { - $('#comment-form-title').click(); + if ((!$(this).is('#comment-form-title-' + form_num)) && (Drupal.settings.ajax_comments_always_expand_form)) { + $('#comment-form-title-' + form_num).click(); } else if (!Drupal.settings.ajax_comments_always_expand_form) { - ajax_comments_close_form(); + ajax_comments_close_form(form_num); } } @@ -329,48 +341,56 @@ */ Drupal.ajax_comments_edit_click = function() { $edit_link = $(this); + var form_num = ajax_comments_get_form_num_from_element(this); + + // CSS selectors + var comment_content_sel = '#comment-form-content-' + form_num; $edit_link.parents(commentbox).fadeTo('fast', 0.5).addClass('editing'); - ajax_comments_show_progress(); - $('#comment-form-content').addClass('indented'); - if ($('#comment-form-content:visible').length) { - $('#comment-form-content').after('
'); + ajax_comments_show_progress(form_num); + $(comment_content_sel).addClass('indented'); + if ($(comment_content_sel + ':visible').length) { + $(comment_content_sel).after('
'); $('.sizer').slideUp(speed, function(){ $(this).remove(); }); } - $edit_link.parents(commentbox).after($('#comment-form-content')); + $edit_link.parents(commentbox).after($(comment_content_sel)); rows = Drupal.settings.ajax_comments_rows_in_reply; - $('#comment-form-content').prepend($('#comment-preview')); - $('#comment-form-content').hide(); - ajax_comments_expand_form(); - + $(comment_content_sel).prepend($('#comment-preview-' + form_num)); + $(comment_content_sel).hide(); + ajax_comments_expand_form(form_num); - form_action = $('#comment-form').attr('action'); + form_action = $('#comment-form-' + form_num).attr('action'); // Reload form with edit data. $args = ajax_comments_get_args(form_action); nid = $args[2]; action = $edit_link.attr('href'); action = action.replace('comment/edit', 'ajax_comments/js_reload/' + nid) + '/cid'; - ajax_comments_reload_form(action, 'action', function() { - // Set reload trigger. - $('#comment-form').attr('action', form_action + '?reload=1'); - $('#comment-form-content').attr('cid', 'edit'); + ajax_comments_reload_form(form_num, action, 'action', function() { + // Set reload trigger. + $('#comment-form-' + form_num).attr('action', form_action + '?reload=1'); + $(comment_content_sel).attr('cid', 'edit'); }); - - + + $('.pressed').removeClass('pressed'); + $(this).addClass('pressed'); + $('.last-clicked').removeClass('last-clicked'); + $(this).addClass('last-clicked'); + return false; } /** * Delete links handler. - * + * * This function is called as the handler to the .click() event. The event was bound * during the init function above. This is the function executed when the user clicks * on a 'delete' button on the page. */ Drupal.ajax_comments_delete_click = function() { if ((ctrl) || (confirm(Drupal.t('Are you sure you want to delete the comment? Any replies to this comment will be lost. This action cannot be undone.')))) { + var form_num = ajax_comments_get_form_num_from_element(this); // Taking link's href as AJAX url. comment = $(this).parents(commentbox); action = $(this).attr('href'); @@ -382,10 +402,10 @@ url: action, success: function(response) { if (response.status) { - ajax_comments_close_form(); + ajax_comments_close_form(form_num); // If comment form is expanded on this module, we should collapse it first. - if (comment.next().is('#comment-form-content')) { + if (comment.next().is('#comment-form-content-' + form_num)) { thread = comment.next().next('.indented, div > .indented'); } else { @@ -396,7 +416,7 @@ thread.remove(); comment.remove(); if (!$(commentbox).length) { - $('#comment-controls').animate({height:'hide', opacity:'hide'}, speed, function(){ $(this).remove(); }); + $('#comment-controls-' + form_num).animate({height:'hide', opacity:'hide'}, speed, function(){ $(this).remove(); }); } }); } @@ -412,16 +432,10 @@ } /** - * Attach AHAH behavior to each AHAH form element. - * - * Define a function as a property of Drupal.behaviors. This will call the code - * block when the DOM has finished loading. In this case, we attach the AHAH - * behavior to the pager element if it appears on the page. The pager will show - * up when the number of comments on the page exceeds the "Default comments per page" - * setting for your node type. + * Attaches the ahah behavior to each ahah form element. */ Drupal.behaviors.ajax_comments_pager = function(context) { - $('#comments .pager:not(.pager-processed)', context).addClass('pager-processed').each(function() { + $('div[id^=comments-] .pager:not(.pager-processed)', context).addClass('pager-processed').each(function() { $target = $(this); $target .find('li > a') @@ -454,7 +468,7 @@ */ Drupal.turn_over_page = function(target, url, scroll, success_callback, error_callback) { if (target.length && url) { - ajaxPath = url.replace(/(.*?)\?(.*?)/g, Drupal.settings.basePath + 'ajax_comments/js_load_thread/' + Drupal.settings.ajax_comments_nid + '?$2'); + ajaxPath = url.replace(/(.*?)\?(.*?)/g, Drupal.settings.basePath + '/ajax_comments/js_load_thread/' + Drupal.settings.ajax_comments_nid + '?$2'); $.ajax({ url: ajaxPath, type: 'GET', @@ -499,10 +513,10 @@ /** * Hide comment form, reload if needed. */ -function ajax_comments_expand_form(focus) { - $('#comment-form-content').animate({height:'show'}, speed, function() { +function ajax_comments_expand_form(form_num, focus) { + $('#comment-form-content-' + form_num).animate({height:'show'}, speed, function() { if (focus) { - $('#comment-form textarea').focus(); + $('#comment-form-' + form_num + ' textarea').focus(); } if ($.browser.msie) this.style.removeAttribute('filter'); }); @@ -510,28 +524,18 @@ /** * Helper function for reply handler. - * - * In addition to clearing the textareas and forms, this is where the PID value - * is set for the comment. The PID controls whether this is a new standalone - * 'anchor' comment or a reply to an existing comment thread. A PID value - * of 0 is a new anchor comment while any other number is a reply. - * - * @param $pid - * Some comments are replies to other comments. In those cases, $pid is the parent comment's cid. - * @param $rows - * */ -function ajax_comments_rewind(pid, rows){ +function ajax_comments_rewind(form_num, pid, rows){ // Resizing and clearing textarea. - $('#comment-form textarea').attr('rows', rows); - $('#comment-form:not(.fresh) textarea').attr('value',''); + $('#comment-form-' + form_num + ' textarea').attr('rows', rows); + $('#comment-form-' + form_num + ':not(.fresh) textarea').attr('value',''); // Clearing form. - $('#comment-preview').empty(); + $('#comment-preview-' + form_num).empty(); $('#comment-form .error').removeClass('error'); // Set proper PID. - $('#comment-form input[name=pid]').val(pid) + $('#comment-form-' + form_num + ' input[name=pid]').val(pid) // Now we can attach previously removed editors. ajax_comments_attach_editors(); @@ -541,31 +545,31 @@ /** * Hide comment form, reload if needed. */ -function ajax_comments_close_form(reload) { - pid = $('#comment-form-content').attr('cid'); - $('#comment-form-content').animate({height:'hide'}, speed, function(){ +function ajax_comments_close_form(form_num, reload) { + pid = $('#comment-form-content-' + form_num).attr('cid'); + $('#comment-form-content-' + form_num).animate({height:'hide'}, speed, function(){ if (reload) { - ajax_comments_reload_form(pid, 'pid'); + ajax_comments_reload_form(form_num, pid, 'pid'); } }); $('.pressed').removeClass('pressed'); - $('#comment-form-content').attr('cid', -1); - ajax_comments_hide_progress(); + $('#comment-form-content-' + form_num).attr('cid', -1); + ajax_comments_hide_progress(form_num); } /** * Reload comments form from server. */ -function ajax_comments_reload_form(id, type, callback) { +function ajax_comments_reload_form(form_num, id, type, callback) { rows = Drupal.settings.ajax_comments_rows_default; if (type == 'pid') { - action = $('#comment-form').attr('action'); + action = $('#comment-form-' + form_num).attr('action'); action = action.replace(/comment\/reply\/([0-9]+?)(\/*[0-9]*)$/, 'ajax_comments/js_reload/$1$2'); action = action.replace(/ajax_comments\/js_reload\/([0-9]+?)\/([0-9]+?)\/cid/, 'ajax_comments/js_reload/$1'); if (id > 0) { action = action.replace(/([?])$/, '/' + id + '?'); - action = action.replace(/#comment-form/, ''); + action = action.replace('/#comment-form-' + form_num + '/', ''); rows = Drupal.settings.ajax_comments_rows_in_reply; } @@ -574,31 +578,40 @@ action = id; } - $('#comment-preview').hide(); - ajax_comments_show_progress(); + $('#comment-preview-' + form_num).hide(); + ajax_comments_show_progress(form_num); $.ajax({ type: "GET", url: action, success: function(response) { if (response.status && response.content) { - saved_class = $('#comment-form').attr('class'); + saved_class = $('#comment-form-' + form_num).attr('class'); saved_class = saved_class.replace('ajax-comments-processed', ''); + content = response.content; + // form_clean_id() will not work with JSON request so we need to extend + // form id and other form elements with previous unique number + if (form_num > 1) { + content = content.replace(/comment-preview-1/gm, 'comment-preview-' + form_num); + content = content.replace(/comment-form-1/gm, 'comment-form-' + form_num); + content = content.replace(/ajax-comments-submit-1/gm, 'ajax-comments-submit-' + form_num); + content = content.replace(/ajax-comments-preview-1/gm, 'ajax-comments-preview-' + form_num); + } - $('#comment-form-content').html(response.content); - $('#comment-form').attr('class', saved_class); + $('#comment-form-content-' + form_num).html(content); + $('#comment-form-' + form_num).attr('class', saved_class); - $('#comment-form').addClass('fresh'); - Drupal.attachBehaviors($('#comment-form-content')); - ajax_comments_rewind(id, rows); - ajax_comments_hide_progress(); + $('#comment-form-' + form_num).addClass('fresh'); + Drupal.attachBehaviors($('#comment-form-content-' + form_num)); + ajax_comments_rewind(form_num, id, rows); + ajax_comments_hide_progress(form_num); - $('#comment-form').removeClass('fresh'); + $('#comment-form-' + form_num).removeClass('fresh'); if (undefined != callback) { callback(); } - } + } }, dataType: 'json' }); @@ -607,7 +620,7 @@ /** * Scrolling to a new comment. */ -function ajax_comments_scroll_to_comment_form() { +function ajax_comments_scroll_to_comment_form(form_num) { if ($.browser.msie) { height = document.documentElement.offsetHeight ; } @@ -615,7 +628,7 @@ height = window.innerHeight; } height = height / 2; - offset = $('#comment-form-content').offset(); + offset = $('#comment-form-content-' + form_num).offset(); if ((offset.top > $('html').scrollTop() + height) || (offset.top < $('html').scrollTop() - 20)) { $('html').animate({scrollTop: offset.top}, 'slow'); } @@ -624,26 +637,28 @@ /** * Find a place for a new comment. */ -function ajax_comments_insert_new_comment($comment) { - if ($('#comment-form-content').attr('cid') == 'edit') { - $('#comment-form-content').before($comment); +function ajax_comments_insert_new_comment(form_num, nid, $comment) { + var form_content_sel = '#comment-form-content-' + form_num; + + if ($(form_content_sel).attr('cid') == 'edit') { + $(form_content_sel).before($comment); $('.editing').remove(); - $('#comment-form-content').attr('cid', 0); + $(form_content_sel).attr('cid', 0); } - else if ($('#comment-form-content').attr('cid') <= 0) { - if ($('#comments .pager').length) { - $('#comment-preview').prev('.item-list').before($comment); + else if ($(form_content_sel).attr('cid') <= 0) { + if ($('#comments-' + nid + ' .pager').length) { + $('#comment-preview-' + form_num).prev('.item-list').before($comment); } else { - $('#comment-preview').before($comment); + $('#comment-preview-' + form_num).before($comment); } } else { - if ($('#comment-form-content').next().is('.indented')) { - $('#comment-form-content').next().append($comment); + if ($(form_content_sel).next().is('.indented')) { + $(form_content_sel).next().append($comment); } else { - $('#comment-form-content').before($comment); + $(form_content_sel).before($comment); $comment.wrap('
'); } } @@ -651,7 +666,6 @@ /** * AHAH effect for comment previews. - * * This effect was bound via ajax_comments.module in ajax_comments_form_comment_form_alter() * as the AHAH effect. * @@ -660,53 +674,54 @@ jQuery.fn.ajaxCommentsPreviewToggle = function() { var obj = $(this[0]); + //var form_num = ajax_comments_get_form_num_from_element(this[0]); + var comments_form = obj.parents('div[id^=comments-]'); + alert(obj.parent().html()); + // Hide previous preview. - $('#comment-preview > div:visible').animate({height:'hide', opacity:'hide'}, speed, function() { $(this).remove(); } ); + $('#comment-preview-' + form_num + ' > div:visible').animate({height:'hide', opacity:'hide'}, speed, function() { $(this).remove(); } ); // Show fresh preview. - $('#comment-preview').show(); + $('#comment-preview-' + form_num).show(); obj.animate({height:'show', opacity:'show'}, speed); - ajax_comments_hide_progress(); + ajax_comments_hide_progress(form_num); // Add submit button if it doesn't added yet. - if (!$('#ajax-comments-submit').length && $('.preview-item').length) { - $('#ajax-comments-preview').after(''); + if (!$('#ajax-comments-submit-' + form_num).length && $('.preview-item').length) { + $('#ajax-comments-preview-' + form_num).after(''); // Re-attaching to new comment. - Drupal.attachBehaviors($('#ajax-comments-submit')); + Drupal.attachBehaviors($('#ajax-comments-submit-' + form_num)); } }; /** * AHAH effect for comment submits. - * - * This effect was bound via ajax_comments.module in ajax_comments_form_comment_form_alter() - * as the AHAH effect. - * - * @see http://drupal.org/node/331941 */ -jQuery.fn.ajaxCommentsSubmitToggle = function() { - var obj = $(this[0]); - - html = obj.html(); +jQuery.fn.ajaxCommentsSubmitToggle = function() { + var obj = $(this[0]); + var html = obj.html(); + var link = obj.find('a[href*=/comment/reply]'); + var form_num = ajax_comments_get_form_num_from_href(link.attr('href')); + var nid = ajax_comments_get_nid_from_href(link.attr('href')); + if (html.indexOf('comment-new-success') > -1) { // Empty any preview before output comment. - $('#comment-preview').slideUp(speed, function(){ $(this).empty(); }); + $('#comment-preview-' + form_num).slideUp(speed, function(){ $(this).empty(); }); // If there are more than one page in comments tthread, we should firstly turn over to a last page. - $last_page = $('#comments .pager:first li.pager-last a'); + $last_page = $('#comments-' + nid + ' .pager:first li.pager-last a'); if (!$last_page.length) { - $last_page = $('#comments .pager:first li.pager-next').prev().children('a'); + $last_page = $('#comments-' + nid + ' .pager:first li.pager-next').prev().children('a'); } - if ($('#comment-form-content').attr('cid') <= 0 && $last_page.length) { - Drupal.turn_over_page($('#comments .pager:first'), $last_page.attr('href'), false, function(){}, function(){ $(this).removeClass('throbber'); }); + if ($('#comment-form-content-' + form_num).attr('cid') <= 0 && $last_page.length) { + Drupal.turn_over_page($('#comments-' + nid + ' .pager:first'), $last_page.attr('href'), false, function(){}, function(){ $(this).removeClass('throbber'); }); } else { // Place new comment in proper place. - ajax_comments_insert_new_comment(obj); + ajax_comments_insert_new_comment(form_num, nid, obj); offset = obj.offset(); $('html').animate({scrollTop: offset.top}); - - // At last - showing it up. + // At last - showing it up. obj.animate({height:'show', opacity:'show'}, speed, function () { if ($.browser.msie) { height = document.documentElement.offsetHeight ; @@ -735,15 +750,15 @@ Drupal.attachBehaviors(html); // Hiding comment form. - ajax_comments_close_form(true); + ajax_comments_close_form(form_num, true); if (Drupal.settings.ajax_comments_always_expand_form) { - $('#comment-form-title').click(); + $('#comment-form-title-' + form_num).click(); } } } else { - $('#comment-preview').append(obj); + $('#comment-preview-' + form_num).append(obj); obj.ajaxCommentsPreviewToggle(speed); } }; @@ -786,20 +801,14 @@ } /** - * Update editors text to their textareas. Needs to be done before submits. + * Update editors text to their textareas. Need to be done befor submits. */ function ajax_comments_update_editors() { // Update tinyMCE. if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } - - // Update CKeditor. - if (typeof(CKEDITOR) != 'undefined') { - Drupal.ckeditorOff('edit-comment'); - Drupal.ckeditorOn("edit-comment"); - } - + // Update FCKeditor. if (typeof(doFCKeditorSave) != 'undefined') { doFCKeditorSave(); @@ -828,6 +837,37 @@ return cid; } +function ajax_comments_get_nid_from_href(action) { + args = ajax_comments_get_args(action); + + // Getting token params (/comment/reply/nid/!cid!). + if (args[1] == 'reply') { + if (typeof(args[2]) == 'undefined') { + nid = 0; + } else { + nid = args[2]; + } + } else { + nid = 0; + } + return nid; +} + +/** + * Retrieve related comment form number from reply link + */ +function ajax_comments_get_form_num_from_href(href) { + var nid = ajax_comments_get_nid_from_href(href); + var form_id = $('#comments-' + nid).find('form').attr('id'); + return form_id.substr(form_id.search(/-(\d)$/) + 1); +} + +function ajax_comments_get_form_num_from_element(el) { + var comments_form = $(el).parents('div[id^=comments-]'); + var form_id = comments_form.find('form').attr('id'); + return form_id.substr(form_id.search(/-(\d)$/) + 1); +} + function ajax_comments_is_reply_to_node(href) { args = ajax_comments_get_args(href); result = args[1] == 'reply' && args[2] && (typeof(args[3]) == 'undefined'); @@ -835,8 +875,8 @@ } function ajax_comments_get_args(url) { - if (Drupal.settings.clean_url == '1') { - var regexS = "(http(s)*:\/\/)*([^/]*)" + Drupal.settings.basePath + "([^?#]*)"; + if (Drupal.settings.clean_url[0] == '1') { + var regexS = "(http(s)*:\/\/)*([^/]*)"+ Drupal.settings.basePath +"([^?#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( url ); args = results[4]; @@ -859,25 +899,18 @@ return args; } -/** - * Display and hide the progress bar. - * - * Show or hide the progress bar during the actual comment - * submit/post. Be careful here with IE7 here as it needs - * to see the #ajax-comments-submit button or else it won't - * post. - */ -function ajax_comments_show_progress(context) { +function ajax_comments_show_progress(form_num, context) { if (!context) { - context = '#comment-form-content'; + context = '#comment-form-content-' + form_num; } - if (!$('#comment-form .ajax-comments-loader', context).length) { - $('#comment-form', context).append('
'); + if (!$('#comment-form-' + form_num + ' .ajax-comments-loader', context).length) { + $('#comment-form-' + form_num, context).append('
'); } } -function ajax_comments_hide_progress(context) { + +function ajax_comments_hide_progress(form_num, context) { if (!context) { - context = '#comment-form-content'; + context = '#comment-form-content-' + form_num; } - $('#comment-form .ajax-comments-loader', context).fadeOut(speed, function(){ $(this).remove(); }); -} + $('#comment-form-' + form_num + ' .ajax-comments-loader', context).fadeOut(speed, function(){ $(this).remove(); }); +} \ No newline at end of file Index: ajax_comments.views.inc =================================================================== RCS file: ajax_comments.views.inc diff -N ajax_comments.views.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ajax_comments.views.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,30 @@ + $mode, + 'language_list' => $languages, + 'clean_url' => variable_get('clean_url', 0), + // 'comment_preview_required' => variable_get('comment_preview_'. $node->type, COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_REQUIRED, + 'ajax_comments_rows_in_reply' => variable_get('ajax_comments_reply_row_count', 3), + 'ajax_comments_rows_default' => variable_get('ajax_comments_default_row_count', 5), + 'ajax_comments_always_expand_form' => variable_get('ajax_comments_always_expand_form', TRUE), + 'ajax_comments_blink_new' => variable_get('ajax_comments_blink_new', TRUE), + 'comment_bonus_api_fold_comments' => variable_get('comment_bonus_api_fold_comments', FALSE), + // 'ajax_comments_nid' => $node->nid, + ), 'setting'); +}