Created
August 18, 2014 20:50
-
-
Save haroldSanchezb/dba11ac36e753abfe5c4 to your computer and use it in GitHub Desktop.
Drupal Ajax Tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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