You are here

function dynamicload_js in Javascript Tools 5

Menu callback to return a rendered page in JSON format.

1 string reference to 'dynamicload_js'
dynamicload_menu in dynamicload/dynamicload.module
Implementation of hook_menu().

File

dynamicload/dynamicload.module, line 392
Enable AJAX-based loading of selected page elements.

Code

function dynamicload_js() {

  // The path requested is the current q arg minus the 'dynamicload/js/'.
  if ($path = substr($_GET['q'], 15)) {
    $return = module_invoke('pagearray', 'page', $path);
    if ($return['status'] === FALSE) {
      switch ($return['value']) {
        case MENU_NOT_FOUND:
        case NULL:
          $result = array(
            'result' => FALSE,
            'message' => t('Item was not found.'),
          );
          break;
        case MENU_ACCESS_DENIED:
          $result = array(
            'result' => FALSE,
            'message' => t('Access denied.'),
          );
          break;
        case MENU_SITE_OFFLINE:
          $result = array(
            'result' => FALSE,
            'message' => t('Site offline.'),
          );
          break;
      }
    }
    else {

      // Generate 'extra' for outputting in main content area.
      $extra = '<h1>' . $return['page']['title'] . '</h1>';
      $extra = $return['page']['breadcrumb'] . $extra;
      if ($tabs = theme('menu_local_tasks')) {
        $extra .= $tabs;
      }
      $extra .= $return['page']['help'];
      $extra .= theme('status_messages');

      // Load scripts
      $result = array(
        'result' => TRUE,
        'extra' => $extra,
        'content' => $return['page']['content'],
        'title' => $return['page']['head_title'],
        'scripts' => $return['page']['raw_scripts'],
        'css' => $return['page']['css'],
      );
      $regions = array_filter(variable_get('dynamicload_regions', array()));
      if (!empty($regions)) {
        $result['regions'] = array();
        foreach ($regions as $region) {
          if (isset($return['page']['regions'][$region])) {
            $result['regions'][$region] = $return['page']['regions'][$region];
          }
        }
      }
    }
  }
  else {
    $result = array(
      'result' => FALSE,
      'message' => t('No request found.'),
    );
  }
  print drupal_to_js($result);
  exit;
}