I want to display the comment form in a popup. How could I do this?

I am using Drupal 7.

link|improve this question

21% accept rate
You mean real popup, a window from your browser or a modal box, like dialog from jQuery ? – yvan Aug 25 '11 at 5:40
I mean a dialog from JQuery. – Ahmad Aug 25 '11 at 5:48
feedback

3 Answers

Well, for it I can propose you a 'sexy' solution.

$(function(){
  var comments = elem = $('#comments'); // I get the element comments
  if(comments.size() > 0) { // I check if is exist
    // Here I remplace the form with a link
    var link = elem.replaceWith('<a href="#comments">'+ Drupal.t("Comment my node") +'</a>');
    // For the new link I give him a OnClick event.
    link.clik(function(){
      // Here I just hide the submit button, you can hide other buttons as well
      $('input[type=submit]', comments).css('display', 'none');
      // Here the dialog from jQuery UI you can change is as well
      comments.dialog({
        buttons: {
          "Comment": function() {
              $('form', comments).submit();
          },
          "Cancel": function() {
              $(this).dialog('close');
          }
        },
        modal: true,
        height: 245,
        width: 475,
        title: title,
        open: function() {
        },
        close: function() {
            $(this).dialog('destroy');
        },
        resizable: false,
      });
    });
  }
});

You've to include this code in the header or footer of your theme (better if you can check before if you're on one page with comments or not. And be sure that jQuery UI Dialog is also loaded with drupal_add_library.

P.S. I didn't try the code, so maybe you'll find some bugs, but the main idea is there.

link|improve this answer
How should I include the jQuery UI Dialog? Is it drupal_add_library('jQuery UI Dialog')? – Ahmad Aug 25 '11 at 6:43
Like this ´ drupal_add_library('system', 'ui.dialog');´ – yvan Aug 25 '11 at 6:53
I have copied your js code to popup.js file. Then In the module file and in the form_alter function I added ´ drupal_add_library('system', 'ui.dialog'); drupal_add_js('popup.js'); Is it fine? As it did not work for me. – Ahmad Aug 25 '11 at 7:11
Put your popup.js into your theme folder. After in your template.php add drupal_add_js(path_to_theme() . '/popup.js'); drupal_add_library('system', 'ui.dialog'); – yvan Aug 25 '11 at 7:15
My default theme is bartik. I put the popup.js file in the bartik folder and then I added those two lines at the end of the template.php file. I replace the path_to_path() with themes/bartik. But still it does not work. – Ahmad Aug 25 '11 at 7:24
show 4 more comments
feedback

If you want to do it in a fancy non-technical way use Beauty Tips module.

if you need help here is a good video on this topic.

http://gotdrupal.com/videos/drupal-views-enhanced-with-beauty-tips-module

link|improve this answer
feedback

Ctools has a nice modal functionality that is easy to use, and doesn't need you to manually add any depended JavaScript code.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.