Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. function awesomesite_comments_form_comment_confirm_delete_alter(&$form, &$form_state, $form_id) {
  2.  
  3. // Add the Ajax Submit Function
  4. $form['actions']['submit']['#ajax'] = array(
  5. 'callback' => 'awesomesite_comments_ajax_delete',
  6. 'progress' => false,
  7. );
  8.  
  9. }
  10.  
  11. function awesomesite_comments_ajax_delete($form, $form_state) {
  12.  
  13. // Get rid of all of the messages that have been set
  14. drupal_get_messages();
  15.  
  16. // Get the comment & node objects
  17. $comment = $form_state['comment'];
  18.  
  19. // Put all of the Ajax Commands into an array
  20. $commands = array();
  21.  
  22. // Place the comment above the form
  23. $commands[] = ajax_command_remove('#comment-'.$comment->cid.', comment-'.$comment->cid.' + .comment');
  24.  
  25. // Return the Ajax Commands Array
  26. return array('#type' => 'ajax', '#commands' => $commands);
  27.  
  28. }
  29.  
  30. function awesomesite_comments_menu_alter(&$items) {
  31. $items['comment/%/delete/ajax'] = $items['comment/%/delete'];
  32. $items['comment/%/delete/ajax']['delivery callback'] = 'ajax_deliver';
  33. $items['comment/%/delete/ajax']['page callback'] = 'awesomesite_comments_ajax_confirm_delete_page';
  34. }
  35.  
  36. function awesomesite_comments_ajax_confirm_delete_page($cid) {
  37.  
  38. // Get the HTML of the detele page.
  39. $data = drupal_render(comment_confirm_delete_page($cid));
  40.  
  41. // Put all of the Ajax Commands into an array
  42. $commands = array();
  43.  
  44. // Replace the HTML
  45. $commands[] = ajax_command_html('#comment-'.$cid.' + .comment', $data, array('effect' => 'fade'));
  46.  
  47. return array('#type' => 'ajax', '#commands' => $commands);
  48.  
  49. }
  50.  
  51. jQuery('a.ajax-link:not(.ajax-processed)').addClass('ajax-processed').each(function() {
  52.  
  53. // Cret the element settings object
  54. var element_settings = {};
  55.  
  56. // Get rid of the progress
  57. element_settings.progress = { 'type' : 'none' };
  58.  
  59. // setup the click elements and add the href
  60. if (jQuery(this).attr('href')) {
  61. element_settings.url = jQuery(this).attr('href');
  62. element_settings.event = 'click';
  63. }
  64.  
  65. element_settings.effect = 'fade';
  66.  
  67. // Get the base
  68. var base = jQuery(this).attr('id');
  69.  
  70. // Register the Ajax Request with Drupal
  71. Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
  72.  
  73. });
  74.  
  75. jQuery('.ajax-processed').once().ajaxSuccess(function() {
  76. Drupal.attachBehaviors();
  77. });
  78.  
  79. (function($) {
  80.  
  81. $(document).ready(function(){
  82.  
  83. ..the JS code here..
  84.  
  85. });
  86.  
  87. jQuery('.ajax-processed').once().ajaxSuccess(function() {
  88. Drupal.attachBehaviors();
  89. });
  90.  
  91. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement