You are here

function theme_emwave_wave in Embedded Media Field 6

Same name and namespace in other branches
  1. 6.3 contrib/emwave/emwave.theme.inc \theme_emwave_wave()
  2. 6.2 contrib/emwave/emwave.theme.inc \theme_emwave_wave()
2 theme calls to theme_emwave_wave()
theme_emwave_wave_full in contrib/emwave/emwave.theme.inc
theme_emwave_wave_preview in contrib/emwave/emwave.theme.inc

File

contrib/emwave/emwave.theme.inc, line 3

Code

function theme_emwave_wave($field, $item, $formatter, $node, $code, $width, $height, $bg_color, $color, $font, $font_size, $title = '', $link = NULL) {
  $url = module_invoke('emfield', 'include_invoke', 'emwave', $item['provider'], 'wave_url', $code, $width, $height, $formatter, $field, $item, $node);
  $attributes = array();
  if ($width) {
    $attributes['width'] = $width;
  }
  if ($height) {
    $attributes['height'] = $height;
  }
  if (!$width || !$height) {

    // Find out the size of the actual image file, and scale accordingly
    if ($item['data']['width'] && $item['data']['height']) {

      // The waves's width & height are known
      $scale_width = $item['data']['width'] / ($width ? $width : 1);
      $scale_height = $item['data']['height'] / ($height ? $height : 1);
      if ($scale_width > $scale_height) {
        $attributes['width'] = $width;
      }
      else {
        $attributes['height'] = $height;
      }
    }
    else {

      // We don't know the size of the image, so just make it fill the space available.
      // It will probably be stretched in one direction, making it look odd.
      $attributes['width'] = $width ? $width : NULL;
      $attributes['height'] = $height ? $height : NULL;
    }
  }

  // Setup an array of JavaScript settings.
  $js_settings = array(
    'wave_id' => $code,
    'bg_color' => $bg_color,
    'color' => $color,
    'font' => $font,
    'font_size' => $font_size . 'px',
  );
  static $added = FALSE;
  static $i = 0;
  if ($i >= 1) {
    $i++;
  }
  if ($added == FALSE) {
    drupal_set_html_head('    <script src="http://wave-api.appspot.com/public/embed.js" type="text/javascript"></script>');
    $added = TRUE;
    $i++;
  }

  // Add the JavaScript settings.
  drupal_add_js(array(
    'emwave-' . $code => $js_settings,
  ), "setting");
  $output .= <<<EOD
    <script type="text/javascript">
      Drupal.behaviors.emWave{<span class="php-variable">$i</span>} = function (context) {
        var wavePanel{<span class="php-variable">$i</span>} = new WavePanel('http://wave.google.com/a/wavesandbox.com/');
        wavePanel{<span class="php-variable">$i</span>}.loadWave('wavesandbox.com!w+{<span class="php-variable">$code</span>}');
        wavePanel{<span class="php-variable">$i</span>}.setUIConfig('{<span class="php-variable">$bg_color</span>}','{<span class="php-variable">$color</span>}','{<span class="php-variable">$font</span>}','{<span class="php-variable">$font_size</span>}');
        wavePanel{<span class="php-variable">$i</span>}.init(document.getElementById('waveframe{<span class="php-variable">$i</span>}'));
      }
    </script>
EOD;
  $output .= "\n" . '<div id="waveframe' . $i . '" style="width:';
  $output .= $attributes['width'] . 'px; height:' . $attributes['height'] . 'px;" ></div>';

  // Apparently this stuff is not implemented yet.

  //$output .= "\n" . '  <div id="add-reply-' . $i . '">';

  //$output .= "\n" . '    <button type="button" name="add-reply-';

  //$output .= $i . '" value="' . t('Reply to this wave') . '" onclick="wavePanel' . $i . '.addReply()" >';

  //$output .= 'Add Reply</button></div>';

  //$output .= "\n" . '  <div id="add-participant-' . $i . '">';

  //$output .= "\n" . '    <button type="button" name="add-participant-';

  //$output .= $i . '" value="' . t('Join this wave') . '" onclick="wavePanel' . $i . '.addParticipant()" >';

  //$output .= 'Add Participant</button></div>';

  // If being output as a link, theme a link version.
  if ($link) {
    $output = l($output, $link, array(
      'html' => true,
    ));
  }
  return $output;
}