You are here

function ajax_loader_page_build in Ajax loader 7

Implements hook_page_build().

File

./ajax_loader.module, line 50
Contains general functionality and hooks.

Code

function ajax_loader_page_build(&$page) {
  $settings = variable_get('ajax_loader_settings', array());

  // Only add when settings are set and page is not an admin page.
  if ($settings && ThrobberManager::isApplicable($settings)) {
    $path = drupal_get_path('module', 'ajax_loader');
    $page['page_bottom']['ajax_loader'] = array(
      '#attached' => array(),
    );
    $attached =& $page['page_bottom']['ajax_loader']['#attached'];
    $class = $settings['throbber'];

    // Check if throbber is valid.

    /** @var ThrobberInterface $throbber */
    if ($throbber = ThrobberManager::isValidThrobber($class)) {

      // Add JS.
      $attached['js'] = array(
        array(
          'data' => array(
            'ajaxThrobber' => array(
              'markup' => $throbber
                ->getMarkup(),
              'hideAjaxMessage' => $settings['hide_ajax_message'],
            ),
          ),
          'type' => 'setting',
        ),
        array(
          'data' => $path . '/js/ajax-loader.js',
          'type' => 'file',
          'scope' => 'footer',
        ),
      );

      // Add CSS.
      $attached['css'] = array(
        array(
          'data' => $path . '/css/throbber-general.css',
          'type' => 'file',
        ),
        array(
          'data' => $throbber
            ->getCssFile(),
          'type' => 'file',
        ),
      );
    }
  }
}