0

I currently have a page which has a block with taxonomy terms displayed. Each link has been made to work with ajax to display information below if clicked, generated in a module callback.

What I am trying to acheive is also have this work if linked to. So for example my page URL is currently http://localhost/events/building01 If someone was to visit http://localhost/events/building01/printer then the information for printer would be displayed under the taxonomy term as it would if someone had clicked on the term.

My ajax links are currently setup like:

function building_block_menu() 
{
  $items['events/%/%/ajax'] = array(
  'title' => 'ajax call',
  'page arguments' => array(1, 2),
  'page callback' => '_event_ajax_callback',
  'access arguments' => array('access content'),
  'type' => MENU_CALLBACK,
  );
  $items['events/%/%/nojs'] = array(
  'title' => 'nojs call',
  'page arguments' => array(1, 2),
  'page callback' => '_event_nojs_callback',
  'access arguments' => array('access content'),
  'type' => MENU_CALLBACK,
  );
  return $items;
}
function _event_ajax_callback($building, $type)
{
  $markup = $building . ' - ' . $type;
  $ajax_commands = array();
  $ajax_commands[] = ajax_command_html('#ajax-target', $markup);
  ajax_deliver(array('#type' => 'ajax', '#commands' => $ajax_commands));
}
function _event_nojs_callback() 
{
  return "no js to be built";
}

And called from links built like:

$output .= l($term->name, 'events/$building/'.$term->tid.'/nojs', array(
            'attributes' => array('id' => 'building-term-'.$term->tid, 'class' => 'use-ajax')
            ));
0

The easiest option would be to add an ID to each link like link_printer and then use jQuery to parse the url, get the last fragment, and click any links that match.

var splitURL = window.location.href.split('/');
var link_id = '#link_' + splitURL[splitURL.length - 1];
if ($(link_id).length > 0) document.querySelector(link_id).click();
1
  • That works for me. Do you know if this would work for search engine crawlers as well? Or would I need to look at creating a more complicated solution using the HTML5 history API? – lumin1907 Aug 14 '18 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.