Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function awesomesite_comments_form_comment_confirm_delete_alter(&$form, &$form_state, $form_id) {
- // Add the Ajax Submit Function
- $form['actions']['submit']['#ajax'] = array(
- 'callback' => 'awesomesite_comments_ajax_delete',
- 'progress' => false,
- );
- }
- function awesomesite_comments_ajax_delete($form, $form_state) {
- // Get rid of all of the messages that have been set
- drupal_get_messages();
- // Get the comment & node objects
- $comment = $form_state['comment'];
- // Put all of the Ajax Commands into an array
- $commands = array();
- // Place the comment above the form
- $commands[] = ajax_command_remove('#comment-'.$comment->cid.', comment-'.$comment->cid.' + .comment');
- // Return the Ajax Commands Array
- return array('#type' => 'ajax', '#commands' => $commands);
- }
- function awesomesite_comments_menu_alter(&$items) {
- $items['comment/%/delete/ajax'] = $items['comment/%/delete'];
- $items['comment/%/delete/ajax']['delivery callback'] = 'ajax_deliver';
- $items['comment/%/delete/ajax']['page callback'] = 'awesomesite_comments_ajax_confirm_delete_page';
- }
- function awesomesite_comments_ajax_confirm_delete_page($cid) {
- // Get the HTML of the detele page.
- $data = drupal_render(comment_confirm_delete_page($cid));
- // Put all of the Ajax Commands into an array
- $commands = array();
- // Replace the HTML
- $commands[] = ajax_command_html('#comment-'.$cid.' + .comment', $data, array('effect' => 'fade'));
- return array('#type' => 'ajax', '#commands' => $commands);
- }
- jQuery('a.ajax-link:not(.ajax-processed)').addClass('ajax-processed').each(function() {
- // Cret the element settings object
- var element_settings = {};
- // Get rid of the progress
- element_settings.progress = { 'type' : 'none' };
- // setup the click elements and add the href
- if (jQuery(this).attr('href')) {
- element_settings.url = jQuery(this).attr('href');
- element_settings.event = 'click';
- }
- element_settings.effect = 'fade';
- // Get the base
- var base = jQuery(this).attr('id');
- // Register the Ajax Request with Drupal
- Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
- });
- jQuery('.ajax-processed').once().ajaxSuccess(function() {
- Drupal.attachBehaviors();
- });
- (function($) {
- $(document).ready(function(){
- ..the JS code here..
- });
- jQuery('.ajax-processed').once().ajaxSuccess(function() {
- Drupal.attachBehaviors();
- });
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement