header image loads twice

WockyHajar - August 4, 2009 - 10:02
Project:Nitobe
Version:6.x-4.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:header, image, Twice
Description

I follwed the instructions in #348568: phptemplate_preprocess_page is called twice for sub-themes, but the header image is loading twice.

I found out:

The 1st time the image is loading by nitobe_utils.inc's :

function _nitobe_fixed_header_css($filename) {
  global $base_url;

  $url    = $base_url . '/' . $filename;
  $output = '<style type="text/css">#masthead{background-image:url(%s);}</style>';

  return sprintf($output, $url);
}

The 2nd time by another function of nitobe_utils.inc's :

function _nitobe_random_header_js() {
  global $base_url;

  $files = _nitobe_get_header_list();
  $names = array();

  foreach ($files as $file => $data) {
    $names[] = $base_url . '/' . $file;
  }

  $name_js = drupal_to_js($names);

  $js = <<<EOJS
<script type="text/javascript">
  $(document).ready(function() {
    var names = {$name_js};
    $('#masthead').css('background-image', 'url(' + names[Math.floor(Math.random() * names.length)] + ')');
  });
</script><noscript></noscript>
EOJS;

  return $js;
}

Can I prevent this behavior?

#1

WockyHajar - August 4, 2009 - 15:29

My workaround is to disable the return of javascript in the 2nd code.

...
EOJS;

//  return $js;
}

 
 

Drupal is a registered trademark of Dries Buytaert.