Skip to content

Instantly share code, notes, and snippets.

@haroldSanchezb
Created August 18, 2014 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haroldSanchezb/dba11ac36e753abfe5c4 to your computer and use it in GitHub Desktop.
Save haroldSanchezb/dba11ac36e753abfe5c4 to your computer and use it in GitHub Desktop.
Drupal Ajax Tabs
<ul >
<li class="use-ajax tabs id active"><a href="nojs/id">tab1</a></li>
<li class="use-ajax tabs id2"><a href="nojs/id2">tab2</a></li>
<li class="use-ajax tabs id3"><a href="nojs/id3">tab3</a></li>
</ul>
<div class="content-to-replace">
</div>
<?php
function mymodule_tramites_menu() {
$items = array();
$items['path/url'] = array(
'page callback' => 'myfunction_callback',
'access arguments' => TRUE, // anonymous
'type' => MENU_CALLBACK,
);
return $items;
}
function myfunction_callback($type = 'ajax',$nid) {
global $user;
$content .= '<div class="content-to-replace">'.$nid.'</div>';
if ($type != 'ajax') {
return $content;
}
$commands = array();
$commands[] = ajax_command_replace(".content-to-replace", $content);
$commands[] = ajax_command_invoke('.tabs', 'removeClass',array('active'));
$commands[] = ajax_command_invoke('.'.$nid, 'addClass',array('active'));
ajax_deliver(array('#type' => 'ajax', '#commands' => $commands));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment