Skip to content

Instantly share code, notes, and snippets.

Created May 20, 2011 10:57
Show Gist options
  • Select an option

  • Save anonymous/982721 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/982721 to your computer and use it in GitHub Desktop.
Ajax Node Content Reload Module
name = Ajax reload
description = "Ajax Node Content Reload Module"
core = 7.x
files[] = ajax_reload.js
(function ($) {
Drupal.behaviors.ajax_reload = {
attach: function (context, settings) {
$('.region-submenu a').bind('click', function () {
var url = $(this).attr('href');
// $('.article-content').slideUp('slow');
$('.article-content').empty();
$('.article-content').load(url);
return false;
});
}
}
}(jQuery));
<?php
/**
* @file
* Ajax Node Content Reload Module
*/
/**
* Implements hook_init()
*/
function ajax_reload_init() {
drupal_add_js(drupal_get_path('module', 'ajax_reload') . '/ajax_reload.js');
}
/**
* Implements hook_preprocess_html()
*/
function ajax_reload_preprocess_html(&$vars, $hook) {
// page called via AJAX?
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) {
// add AJAX template
$vars['theme_hook_suggestions'][] = 'html__xhttp';
}
}
/**
* Implements hook_preprocess_page()
*/
function ajax_reload_preprocess_page(&$vars, $hook) {
// page called via AJAX?
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) {
// add AJAX template
$vars['theme_hook_suggestions'][] = 'page__xhttp';
}
}
/**
* Implements hook_preprocess_node()
*/
function ajax_reload_preprocess_node(&$vars, $hook) {
// page called via AJAX?
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) {
// add AJAX template
$vars['theme_hook_suggestions'][] = 'node__xhttp';
}
}
<?php
// html--xhttp.tpl.php
print '<!-- Rendering html--xhttp.tpl.php -->';
print $page;
<?php
// node--xhttp.tpl.php
print '<!-- Rendering page--xhttp.tpl.php -->';
hide($content['comments']);
hide($content['links']);
print render($content);
<?php
// page--xhttp.tpl.php
print '<!-- Rendering page--xhttp.tpl.php -->';
print render($page['content']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment