Browse Source

Cleaned up and moved grid/list display logic into islandora, since its now used in several modules.

pull/297/head
Nigel Banks 12 years ago
parent
commit
2c829f0241
  1. 39
      css/islandora.objects.css
  2. 23
      islandora.module
  3. 17
      theme/islandora-objects-grid.tpl.php
  4. 29
      theme/islandora-objects-list.tpl.php
  5. 15
      theme/islandora-objects.tpl.php
  6. 61
      theme/theme.inc

39
css/islandora.objects.css

@ -0,0 +1,39 @@
/**
* @file
* Styles for rendering grids/lists of objects.
*/
.islandora-objects-display-switch {
float: right;
}
.islandora-objects-grid-item {
display: inline-block;
width: 20%;
min-width: 100px;
min-height: 180px;
display: -moz-inline-stack;
display: inline-block;
vertical-align: top;
margin: 1.5em 1.84%;
zoom: 1;
*display: inline;
_height: 180px;
}
.islandora-objects-list-item {
padding-bottom: 1.5em;
border-bottom: 1px solid #ddd;
}
.islandora-objects-list-item .islandora-object-thumb {
clear: left;
float: left;
padding: 3px 0 0;
text-align: center;
width: 100px;
}
.islandora-objects-list-item .islandora-object-caption, .islandora-objects-list-item .islandora-object-description {
margin: 0 0 0 130px;
padding-top: 2px;
padding-bottom: 2px;
}
.islandora-object-thumb img {
width: 100%;
}

23
islandora.module

@ -286,6 +286,29 @@ function islandora_theme() {
'file' => 'theme/theme.inc', 'file' => 'theme/theme.inc',
'variables' => array('object' => NULL, 'content' => array()), 'variables' => array('object' => NULL, 'content' => array()),
), ),
// Render a bunch of objects as either a grid or a list.
'islandora_objects' => array(
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-objects',
'variables' => array(
'objects' => NULL,
'display' => NULL,
'page_size' => 20,
'limit' => 10,
),
),
// Render a bunch of objects as a grid.
'islandora_objects_grid' => array(
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-objects-grid',
'variables' => array('objects' => NULL),
),
// Render a bunch of objects as a list.
'islandora_objects_list' => array(
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-objects-list',
'variables' => array('objects' => NULL),
),
); );
} }

17
theme/islandora-objects-grid.tpl.php

@ -0,0 +1,17 @@
<?php
/**
* @file
* Render a bunch of objects in a list or grid view.
*/
?>
<div class="islandora-objects-grid clearfix">
<?php foreach($objects as $object): ?>
<div class="islandora-objects-grid-item clearfix">
<dl class="islandora-object <?php print $object['class']; ?>">
<dt class="islandora-object-thumb"><?php print $object['thumb']; ?></dt>
<dd class="islandora-object-caption"><?php print $object['link']; ?></dd>
</dl>
</div>
<?php endforeach; ?>
</div>

29
theme/islandora-objects-list.tpl.php

@ -0,0 +1,29 @@
<?php
/**
* @file
* Render a bunch of objects in a list or grid view.
*/
?>
<div class="islandora-objects-list">
<?php $row_field = 0; ?>
<?php foreach($objects as $object): ?>
<?php $first = ($row_field == 0) ? 'first' : ''; ?>
<div class="islandora-objects-list-item clearfix">
<dl class="islandora-object <?php print $object['class']; ?>">
<dt class="islandora-object-thumb">
<?php print $object['thumb']; ?>
</dt>
<dd class="islandora-object-caption <?php print $object['class']?> <?php print $first; ?>">
<strong>
<?php print $object['link']; ?>
</strong>
</dd>
<dd class="islandora-object-description">
<?php print $object['description']; ?>
</dd>
</dl>
</div>
<?php $row_field++; ?>
<?php endforeach; ?>
</div>

15
theme/islandora-objects.tpl.php

@ -0,0 +1,15 @@
<?php
/**
* @file
* Render a bunch of objects in a list or grid view.
*/
?>
<div class="islandora-objects clearfix">
<span class="islandora-objects-display-switch">
<?php print theme('links', array('links' => $display_links, 'attributes' => array('class' => array('links', 'inline')))); ?>
</span>
<?php print $pager; ?>
<?php print $content; ?>
<?php print $pager; ?>
</div>

61
theme/theme.inc

@ -157,3 +157,64 @@ function islandora_preprocess_islandora_object_print(array &$variables) {
function theme_islandora_object_print(array &$variables) { function theme_islandora_object_print(array &$variables) {
return drupal_render($variables['content']); return drupal_render($variables['content']);
} }
/**
* Implements hook_preprocess_theme().
*/
function islandora_preprocess_islandora_objects(array &$variables) {
module_load_include('inc', 'islandora_paged_content', 'includes/utilities');
$display = (empty($_GET['display'])) ? 'grid' : $_GET['display'];
$grid_display = $display == 'grid';
$list_display = !$grid_display;
$query_params = drupal_get_query_parameters($_GET);
$variables['display_links'] = array(
array(
'title' => t('Grid view'),
'href' => url($_GET['q'], array('absolute' => TRUE)),
'attributes' => array(
'class' => $grid_display ? 'active' : '',
),
'query' => array('display' => 'grid') + $query_params,
),
array(
'title' => t('List view'),
'href' => url($_GET['q'], array('absolute' => TRUE)),
'attributes' => array(
'class' => $list_display ? 'active' : '',
),
'query' => array('display' => 'list') + $query_params,
),
);
// Pager.
$objects = $variables['objects'];
$limit = $variables['limit'];
$page_size = $variables['page_size'];
$page = pager_default_initialize(count($objects), $limit);
$objects = array_slice($objects, $page * $limit, $limit);
$variables['pager'] = theme('pager', array('quantity' => 10));
// Content.
$map_objects = function($o) {
$o = islandora_object_load($o);
$url = "islandora/object/{$o->id}";
$link_options = array('html' => TRUE, 'attributes' => array('title' => $o->label));
$img = theme_image(array('path' => url("$url/datastream/TN/view"), 'attributes' => array()));
$description = NULL;
$dc = DublinCore::importFromXMLString($o['DC']->content);
if ($dc) {
$dc = $dc->asArray();
$description = $dc['dc:description']['value'];
}
return array(
'label' => $o->label,
'class' => drupal_strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $o->id)),
'link' => l($o->label, $url, $link_options),
'thumb' => l($img, $url, $link_options),
'description' => $description,
);
};
$objects = array_map($map_objects, $objects);
$theme = $grid_display ? 'islandora_objects_grid' : 'islandora_objects_list';
$variables['content'] = theme($theme, array('objects' => $objects));
$module_path = drupal_get_path('module', 'islandora');
drupal_add_css("$module_path/css/islandora.objects.css");
}

Loading…
Cancel
Save