You are here

function mediafront_views_pre_render in MediaFront 6

Same name and namespace in other branches
  1. 6.2 mediafront.module \mediafront_views_pre_render()
  2. 7.2 views/mediafront.views.inc \mediafront_views_pre_render()
  3. 7 mediafront.module \mediafront_views_pre_render()

Views pre-render

File

./mediafront.module, line 663

Code

function mediafront_views_pre_render(&$view) {

  // Check to make sure this is the block playlist.
  if (mediafront_block_show($view)) {

    // Get the preset for this view.
    $preset = variable_get('mediafront_block_preset', '');

    // Initialize our javascript.
    $js = 'jQuery.media = jQuery.media ? jQuery.media : {};';
    $js .= 'jQuery.media.nodes = jQuery.media.nodes ? jQuery.media.nodes : {};';

    // Iterate through our results, and add the node objects to the page.
    foreach ($view->result as &$result) {
      $js .= 'jQuery.media.nodes["' . $result->nid . '"] = ' . mediafront_json_encode(mediafront_invoke_node(node_load($result->nid), NULL)) . ';';
    }

    // Get the class of the first field.
    $view_id = '.view-' . views_css_safe($view->name);
    $js .= 'jQuery.media.fieldSelector = "' . $view_id . ' .views-field-mediafront-nid";';
    $js .= 'jQuery.media.playerId = "mediafront_' . $preset . '";';

    // Add this javascript to the main page.
    drupal_add_js($js, 'inline');

    // Add the playlist javascript.
    drupal_add_js(drupal_get_path('module', 'mediafront') . '/js/mediafront.js');
  }
}