Skip to content

Instantly share code, notes, and snippets.

@martinmev
Created August 23, 2012 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinmev/3436455 to your computer and use it in GitHub Desktop.
Save martinmev/3436455 to your computer and use it in GitHub Desktop.
Modified Drupal module Galleria
Modified Drupal module Galleria
The example of the modified galleria:
http://www.centernarovinu.org/content/weekend-coordinators-distance-adoption
----------
Modules:
Galleria 6.x-1.0
http://drupal.org/project/galleria
Lightbox2 6.x-1.11
http://drupal.org/project/lightbox2
----------
Galleria settings (the gallery is preloaded when the user clicks on it).
ImageCache gallery preset = Lightbox ImageCache preset (node-gallery-display)
(ImageCache thumbnail preset: gallery_assist-default-thumbnail-100)
Lightbox module: Lightbox2
----------
Modifications:
galleria.patch - Galleria appearance, link 'example#galleria_link_0'
triggers the first image in the galleria.
galleria.tpl.php.patch - add <!--GALLERIA_BEGIN--> and <!--GALLERIA_END-->
theme-node-page.tpl.php (sites/all/themes/theme/node-page.tpl.php) - shows the fist image
from galleria and prepares the trigger
theme-page.tpl.php.js (javascript in sites/all/themes/theme/page/tpl.php) -
Galleria appearance, adds link for the download of full resolution image.
theme-template.php (sites/all/themes/theme/template.php) - Article appearance:
1) If the article images are present in the galleria
the click triggers the big galleria images.
2) Article can load gallery from another node (galleria node reference).
theme.css - modified sites/all/themes/theme/css/theme.css
diff --git a/www/sites/all/modules/galleria/galleria.module b/www/sites/all/modules/galleria/galleria.module
index 8466a9d..e3e5382 100644
--- a/www/sites/all/modules/galleria/galleria.module
+++ b/www/sites/all/modules/galleria/galleria.module
@@ -358,7 +358,7 @@ function template_preprocess_galleria(&$vars) {
'wrap' => variable_get('galleria_jcarousel_wrap', 'null'),
'initCallback' => 'Drupal.galleria.jcarousel_initCallback',
);
- jcarousel_add('.gallery', $options);
+ jcarousel_add('gallery', $options);
}
}
diff --git a/www/sites/all/modules/galleria/inc/galleria.js b/www/sites/all/modules/galleria/inc/galleria.js
index 20a8c5b..2681786 100644
--- a/www/sites/all/modules/galleria/inc/galleria.js
+++ b/www/sites/all/modules/galleria/inc/galleria.js
@@ -11,6 +11,7 @@ Drupal.galleria = {};
Drupal.galleria.options = {
num_thumbs : 1,
insert : '#main-image',
+ firstOnImage : true,
onImage : function(image, caption, thumb) {
// Lightbox support
if (Drupal.settings.galleria_lightbox != 'none') {
@@ -18,7 +19,12 @@ Drupal.galleria.options = {
image.wrap('<a href="#" onclick="Lightbox.start(document.getElementById(\'' + thumb.next('a').attr('id') + '\')); return false;"></a>');
// keep Galleria from adding a click event to the image
$.galleria.clickNext = false;
- image.attr('title','View full-size');
+ image.attr('title','Galerie');
+ if (Drupal.galleria.options.firstOnImage) {
+ Drupal.galleria.options.firstOnImage = false;
+ } else {
+ Lightbox.start(document.getElementById(thumb.next('a').attr('id')));
+ }
}
// let's add some image effects for demonstration purposes
@@ -123,4 +129,16 @@ Drupal.behaviors.initGalleria = function(context) {
$('#lightbox ul.gallery').galleria(Drupal.galleria.options);
}
});
+
+ // check if trigger lightbox
+ $(window).load(function(){
+ // get url, check galleria_link
+ var url =$(location).attr('href');
+ if (url.search(/#galleria_link_/)>0) {
+ // trigger lightbox
+Lightbox.start(document.getElementById($(url.replace(/^.*#galleria_link_(.*)/,'#galleria-content ul.galleria li a:eq($1)')).attr('id')));
+}
+
+ });
+
};
diff --git a/www/sites/all/modules/galleria/inc/jquery.galleria.js b/www/sites/all/modules/galleria/inc/jquery.galleria.js
index aadb7ae..5401f29 100644
--- a/www/sites/all/modules/galleria/inc/jquery.galleria.js
+++ b/www/sites/all/modules/galleria/inc/jquery.galleria.js
@@ -219,6 +219,7 @@ $$ = $.fn.galleria = function($options) {
}).attr('src', _src);
});
});
+
};
/**
@@ -289,6 +290,9 @@ $$.onPageLoad = function(_src) {
// get the thumb
var _thumb = $('.galleria img[rel="'+_src+'"]');
+ // get url
+ var url =$(location).attr('href');
+
if (_src) {
// new hash location
@@ -321,6 +325,7 @@ $$.onPageLoad = function(_src) {
_img.attr('src',_src);
+
} else {
// clean up the container if none are active
@@ -333,6 +338,7 @@ $$.onPageLoad = function(_src) {
// place the source in the galleria.current variable
$.galleria.current = _src;
+
};
/**
diff --git a/www/sites/all/themes/centrumnarovinu/galleria.tpl.php b/www/sites/all/themes/centrumnarovinu/galleria.tpl.php
index 3a36e1e..95700d5 100644
--- a/www/sites/all/themes/centrumnarovinu/galleria.tpl.php
+++ b/www/sites/all/themes/centrumnarovinu/galleria.tpl.php
@@ -6,8 +6,8 @@
* Default output for a galleria node.
*/
?>
-<?php if ($image_count > 0): ?>
<!--GALLERIA_BEGIN--><div id="galleria-content">
+ <?php if ($image_count > 0): ?>
<div id="main-image"></div>
<?php print $thumbnails; ?>
<script type="text/javascript">
@@ -23,5 +23,5 @@
<a onclick="$.galleria.next(); return false;" href="#"><?php print $next; ?> &raquo;</a>
</div>
<?php endif; ?>
- </div><!--GALLERIA_END-->
<?php endif; ?>
+ </div><!--GALLERIA_END-->
...
<?php if($node->field_galleria[0]['filepath']) { ?>
<div class="Image">
<a href="#" onclick="Lightbox.start(document.getElementById($('#galleria-content ul.galleria li a:eq(0)').attr('id'))); return false;">
<?php
$preset = "medium";
print theme('imagecache',
$preset,
$node->field_galleria[0]['filepath'],
$node->field_galleria[0]['data']['title'],
$node->field_galleria[0]['data']['title']);
?>
</a>
</div>
<?php } ?>
...
<script type="text/javascript">
<!--
$(document).ready(function() {
$('.links').hide();
$('#field_galleria_values input.form-text').removeAttr('maxlength');
$('.view-news-archive .views-field-field-show-galleria-value,.view-action-archive .views-field-field-show-galleria-value,.view-archiv-akci .views-field-field-show-galleria-value,.view-archiv-aktualit .views-field-field-show-galleria-value')
.each( function() { if($(this).text().indexOf('0')>-1) {
//alert('remove');
$(this).next('.views-field-view-node').remove();
}});
$('.view-archiv-akci .views-row .views-field-field-galleria-fid,.view-archiv-akci .views-row .views-field-body,.view-archiv-akci .views-row .views-field-view-node').hide();
$('.view-archiv-aktualit .views-row .views-field-field-galleria-fid,.view-archiv-aktualit .views-row .views-field-body,.view-archiv-aktualit .views-row .views-field-view-node').hide();
$('.view-news-archive .views-row .views-field-field-galleria-fid,.view-news-archive .views-row .views-field-body,.view-news-archive .views-row .views-field-view-node').hide();
$('.view-action-archive .views-row .views-field-field-galleria-fid,.view-action-archive .views-row .views-field-body,.view-action-archive .views-row .views-field-view-node').hide();
$('.view-archiv-aktualit .views-field-field-show-galleria-value,.view-archiv-aktualit .views-field-field-show-galleria-value').remove();
$('.view-archiv-akci .views-field-field-show-galleria-value,.view-archiv-akci .views-field-field-show-galleria-value').remove();
$('.view-news-archive .views-field-field-show-galleria-value,.view-news-archive .views-field-field-show-galleria-value').remove();
$('.view-action-archive .views-field-field-show-galleria-value,.view-action-archive .views-field-field-show-galleria-value').remove();
$(window).load(function() {
$('#galleria-content ul.galleria li a').each(function(){
var patt=new RegExp("^.*/sites/default/files/imagecache/[^/]*/","");
<?php if ($language->language=='cs') { ?>
var imageText='Obrázek v plném rozlišení';
<? } else { ?>
var imageText='Full resolution image';
<? } ?>
var titleText = $(this).attr('title');
if (titleText.length>0) {
$(this).attr('title','');
titleText = titleText+'<br/>';
}
$(this).attr('rel',$(this).attr('rel')+"["+titleText+"<a href='"+
$(this).attr('href').replace(patt,'/sites/default/files/') +
"' target='_blank'>"+imageText+"</a>]");
});
});
-->
</script>
<?php
function centrumnarovinu_galleria_link_callback($matches) {
global $galleria_field;
$link_no = 0;
foreach ($galleria_field as &$value) {
/* match file path */
if (strpos(preg_replace('#/imagecache/[^/]*/#','/',$matches[0]),$value['filepath']) !== false) {
$galleria_link = "<a onclick=\"Lightbox.start(document.getElementById($('#galleria-content ul.galleria li a:eq($link_no)').attr('id'))); return false;\" href=\"#\">";
unset($value);
return ($galleria_link.$matches[0].'</a>');
}
$link_no++;
}
unset($value);
return ($matches[0]);
}
function centrumnarovinu_change_body_image_add_link(&$i) {
$i= preg_replace_callback('/<img[ ]*[^>]*>/i','centrumnarovinu_galleria_link_callback',$i);
}
function centrumnarovinu_change_content_link2galleria(&$i) {
$separator='<div class="field field-galleria"';
$o = explode($separator,$i);
if (count($o)>1) {
/** galleria field detected */
centrumnarovinu_change_body_image_add_link($o[0]);
$i=implode($separator,$o);
}
}
function centrumnarovinu_return_path_to_refered_galleria($path,$language) {
if ($path!='') {
if ($language=='cs') {
return '<br style="clear:right;"><a href="/'.$path.'#galleria_link_0" style="float: right;">fotogalerie</a>';
} else {
return '<br style="clear:right;"><a href="/'.$path.'#galleria_link_0" style="float: right;">photogallery</a>';
}
}
return '';
}
/*
* Node preprocessing
*/
function centrumnarovinu_preprocess_node(&$vars) {
//print_r($vars);
$view_archive = ($vars['view']->name == 'archiv_aktualit') || ($vars['view']->name == 'archiv_akci');
// show galleria thumbnails on web page?
$show_galleria = 100;
if (isset($vars['field_show_galleria'][0]['value'])) {
$show_galleria=$vars['field_show_galleria'][0]['value'];
}
if ($show_galleria==0) {
$vars['content']=preg_replace('/<div class="field field-galleria">/',
'<div class="field field-galleria" style="display:none;">',
$vars['content']);
}
$vars['centrumnarovinu_show_galleria']=$show_galleria;
// load galleria from node reference
$galleria_reference = false;
$galleria_reference_path='';
if ( (($show_galleria!=0) && isset($vars['field_refered_galleria'][0]['nid'])) || $view_archive) {
// replace original node galleria
$galleria_begin='<!--GALLERIA_BEGIN-->';
$galleria_end='<!--GALLERIA_END-->';
$galleria_loaded='';
if (isset($vars['field_refered_galleria'][0]['nid'])) {
$galleria_nid=$vars['field_refered_galleria'][0]['nid'];
$galleria_reference=true;
// load galleria node - full page
$node = node_build_content(node_load($galleria_nid),false,true);
//print_r($node);
// copy galleria field
$vars['field_galleria']=$node->field_galleria;
// copy path
$galleria_reference_path=$node->path;
// copy galleria html content
$loaded = drupal_render($node->content['field_galleria']);
}
// get original galleria
$x=explode($galleria_begin,$loaded);
if (count($x)==2) {
$y=explode($galleria_end,$x[1]);
if (count($y)==2) {
$galleria_loaded=$y[0];
}
}
// view_archive must not to have galleria
if ($view_archive) {
$galleria_loaded=' ';
}
// set galleria in node
if ($galleria_loaded!='') {
$x=explode($galleria_begin,$vars['content']);
if (count($x)==2) {
$y=explode($galleria_end,$x[1]);
if (count($y)==2) {
$vars['content']=$x[0].$galleria_begin.$galleria_loaded.$galleria_end.$y[1];
}
}
}
}
$vars['centrumnarovinu_galleria_referenced']=$galleria_reference;
/** links to galleria */
global $galleria_field;
$galleria_field=$vars['field_galleria'];
global $centrumnarovinu_content_p_count;
global $centrumnarovinu_content_p_counter;
global $centrumnarovinu_content_p_replace;
/** place 'read more' into content, and reset variable links */
$centrumnarovinu_content_p_count=substr_count(strtolower($vars['content']),'</p>');
$centrumnarovinu_content_p_counter=0;
$centrumnarovinu_content_p_replace='';
// teaser or view_archive
if (($view_archive) || ($vars['teaser'])) {
// link to photogallery and to whole article
$path='';
if ( ($show_galleria==1) ||
(isset($vars['field_galleria'][0]['nid']) && ($show_galleria>0) && $view_archive) )
$path=$vars['path'];
if ($galleria_reference)
$path=$galleria_reference_path;
if ($vars['language']=='cs') {
if (!$view_archive)
$centrumnarovinu_content_p_replace='<a href="/'.$vars['path'].'" style="float: right;">celý&nbsp;článek</a>';
if ($path!='')
$centrumnarovinu_content_p_replace.=centrumnarovinu_return_path_to_refered_galleria($path,$vars['language']);
}
else {
if (!$view_archive)
$centrumnarovinu_content_p_replace='<a href="/'.$vars['path'].'" style="float: right;">read&nbsp;more</a>';
if ($path!='')
$centrumnarovinu_content_p_replace.=centrumnarovinu_return_path_to_refered_galleria($path,$vars['language']);
}
if ($centrumnarovinu_content_p_count>0) {
$vars['content']=preg_replace_callback('/<\/p>/ui','centrumnarovinu_content_p_callback',$vars['content']);
}
else
$vars['content'].= $centrumnarovinu_content_p_replace;
$vars['links']='';
} else { // full node
/** galleria picture - link to lightbox */
centrumnarovinu_change_content_link2galleria($vars['content']);
// link to the photogallery
if ($galleria_reference) {
$centrumnarovinu_content_p_replace.=centrumnarovinu_return_path_to_refered_galleria($galleria_reference_path,$vars['language']);
if ($centrumnarovinu_content_p_count>0) {
$vars['content']=preg_replace_callback('/<\/p>/ui','centrumnarovinu_content_p_callback',$vars['content']);
}
else
$vars['content'].= $centrumnarovinu_content_p_replace;
}
}
}
?>
.view-news-archive .views-field-field-show-galleria-value,.view-action-archive .views-field-field-show-galleria-value,.view-archiv-akci .views-field-field-show-galleria-value,.view-archiv-aktualit .views-field-field-show-galleria-value {
display:none;
}
.node-teaser .Image, .view-news-archive .views-field-field-galleria-fid img,.view-action-archive .views-field-field-galleria-fid img,.view-archiv-akci .views-field-field-galleria-fid img,.view-archiv-aktualit .views-field-field-galleria-fid img {
float: left;
margin-right: 20px;
}
/* --- Galleria --- */
.field-galleria .field-label { visibility: hidden; }
.field-galleria img { float:none !important; }
.field-galleria { clear:both; }
.galleria_container { display: none; }
.field-show-galleria, .field-refered-galleria { display: none; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment