You are here

function template_preprocess_views_view_fluidgrid in Views Fluid Grid - jQuery Masonry 6

Same name and namespace in other branches
  1. 7 views_fluidgrid.module \template_preprocess_views_view_fluidgrid()

Template function for views_fluidgrid

Parameters

array $vars: Array of template variables.

File

./views_fluidgrid.module, line 21
Provide a fluid grid display style for Views.

Code

function template_preprocess_views_view_fluidgrid(&$vars) {
  $view = $vars['view'];
  $options = $view->style_plugin->options;
  drupal_add_js(drupal_get_path('module', 'views_fluidgrid') . '/js/jquery.masonry.min.js');
  drupal_add_css(drupal_get_path('module', 'views_fluidgrid') . '/views_fluidgrid.css');
  $vars['views_fluidgrid_id'] = 'views_fluidgrid_' . $view->name . '_' . $view->current_display;
  $vars['views_fluidgrid_item_class'] = 'views-fluidgrid-item';
  $view_settings['single_mode'] = check_plain($options['single_mode']);
  $view_settings['column_width'] = check_plain($options['column_width']);
  $view_settings['resizeable'] = check_plain($options['resizeable']);
  $view_settings['callback'] = $options['callback'];
  $settings = $view_settings;

  /* This looks like shit! but I had to this to make this compatable with Views Display Tabs
   * Adding the script inline with each view helps in loading each view's settings seperatly when called via AJAX
   * If you have another way to do this, please let me know.
   */
  $vars['script'] .= "\n<script type=\"text/javascript\">\n    <!--//--><![CDATA[//><!--\n    Drupal.behaviors.viewsFluidGrid = function(context) {\n      viewsFluidGrid = {}; viewsFluidGrid." . $vars['views_fluidgrid_id'] . " = {};\n      if (!\$('#" . $vars['views_fluidgrid_id'] . "').hasClass('views-fluidgrid-processed')) {\n        viewsFluidGrid." . $vars['views_fluidgrid_id'] . ".settings = " . drupal_to_js($settings) . ";\n        \$('#" . $vars['views_fluidgrid_id'] . "').masonry({\n          singleMode: viewsFluidGrid." . $vars['views_fluidgrid_id'] . ".settings.single_mode,\n          columnWidth: viewsFluidGrid." . $vars['views_fluidgrid_id'] . ".settings.column_width,\n          itemSelector: '.views-fluidgrid-item:visible',\n          resizeable: viewsFluidGrid." . $vars['views_fluidgrid_id'] . ".settings.resizeable,\n          appendedContent: \$('#" . $vars['views_fluidgrid_id'] . "'),\n          saveOptions: false\n          },  function() { eval(viewsFluidGrid." . $vars['views_fluidgrid_id'] . ".settings.callback); }\n        ); \$('#" . $vars['views_fluidgrid_id'] . "').addClass('views-fluidgrid-processed');\n      }\n\t  }; //--><!]]>\n    </script>";
}