aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jquery_gallery_view.module94
-rw-r--r--js/jquery_gallery_view.js66
2 files changed, 99 insertions, 61 deletions
diff --git a/jquery_gallery_view.module b/jquery_gallery_view.module
index 7c23d88..c367dcc 100644
--- a/jquery_gallery_view.module
+++ b/jquery_gallery_view.module
@@ -7,9 +7,61 @@
*/
/**
+ * Implementation of hook_menu().
+ */
+function jquery_gallery_view_menu() {
+ $items['jquery_gallery_view'] = array(
+ 'page callback' => 'jquery_gallery_view',
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
+
+ return $items;
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function jquery_gallery_view_theme() {
+ return array(
+ 'jquery_gallery_view' => array(
+ 'arguments' => array(
+ 'images' => array(),
+ ),
+ ),
+ );
+}
+
+/**
+ * Menu callback.
+ */
+function jquery_gallery_view() {
+ return jquery_gallery_view_setup_photos();
+
+ /*
+ $result = array(
+ 'content' => jquery_gallery_view_setup_photos(),
+ '__callbacks' => array('Drupal.jQueryGalleryView.formCallback'),
+ );
+
+ drupal_alter('ajax_data', $result, 'jquery_gallery_view', 'jquery_gallery_view_setup_photos');
+ drupal_json($result);
+ */
+}
+
+/**
+ * Load needed javascript files.
+ */
+function jquery_gallery_view_load() {
+ drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/jquery_gallery_view.js');
+ drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/galleryview/jquery.galleryview-2.1.1-pack.js');
+ drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/galleryview/jquery.timers-1.2.js');
+}
+
+/**
* Setup photos for a view.
*
- * @param $view
+ * @param $viewname
* View data.
*
* @param $field
@@ -18,31 +70,47 @@
* @param $title
* Title field name.
*/
-function jquery_gallery_view_setup_photos($view, $field, $title = NULL) {
- // Setup files folder.
+function jquery_gallery_view_setup_photos($viewname = 'foto', $field = 'field_foto_fid', $title = 'field_xmp_title_value') {
+ global $base_url;
$files = variable_get('file_directory_path', conf_path() .'/files');
+ $view = views_get_view($viewname);
+ $view->execute();
+
+ $field = $view->display_handler->get_handler('field', $field)->field_alias;
+ $title = $view->display_handler->get_handler('field', $title)->field_alias;
foreach ($view->result as $result) {
$fid = $result->{$field};
if ($fid != NULL) {
$file = field_file_load($fid);
$text = $result->{$title};
- $photos[] = array(
- 'filename' => $file['filename'],
- 'title' => $text,
+ $images[] = array(
+ 'url' => $base_url .'/'. $files .'/imagecache/65x40/images/'. $file['filename'],
+ 'title' => $text,
);
}
}
- // Add needed javascript.
- drupal_add_js(array('jqueryGalleryView' => array('photos' => $photos)), 'setting');
+ echo theme('jquery_gallery_view', $images);
+ exit;
}
/**
- * Load needed javascript files.
+ * Theme a jQuery Gallery list.
+ *
+ * @param $images
+ * Array with images's urls and titles.
+ *
+ * @return
+ * HTML list of images.
*/
-function jquery_gallery_view_load() {
- drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/jquery_gallery_view.js');
- drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/galleryview/jquery.galleryview-2.1.1-pack.js');
- drupal_add_js(drupal_get_path('module', 'jquery_gallery_view') .'/js/galleryview/jquery.timers-1.2.js');
+function theme_jquery_gallery_view($images = array()) {
+ $output = '<ul id="jquery-gallery-view">';
+
+ foreach ($images as $image) {
+ $output .= '<li><span class="panel-overlay">'. $image['title'] . ' overlay</span><img src="' . $image['url'] .'" /></li>';
+ }
+
+ $output .= '</ul>';
+ return $output;
}
diff --git a/js/jquery_gallery_view.js b/js/jquery_gallery_view.js
index 032c8e0..e0faa8e 100644
--- a/js/jquery_gallery_view.js
+++ b/js/jquery_gallery_view.js
@@ -1,52 +1,22 @@
// $Id$
Drupal.behaviors.jqueryGalleryViewBehavior = function (context) {
- // Add custom site title class
- $('.views-field-title').attr('class', 'views-field-site-title');
-
- // Add photos
- if (Drupal.settings.jqueryGalleryView != null && Drupal.settings.jqueryGalleryView.photos != null) {
- var photos = Drupal.settings.jqueryGalleryView.photos;
-
- // Image sizes
- var width = 300;
- var height = 200;
-
- // Image paths
- var base_url = window.location.protocol + '//' + window.location.hostname;
- var files = Drupal.settings.jqueryGalleryView.photos;
- var base_location = base_url + '/' + Drupal.settings.basePath + files + '/';
- var imagecache = 'imagecache/' + width + 'x' + height + '/';
- var image_folder = base_location + imagecache + '/';
-
- // Other variables
- var panel = new String();
- var file = new String();
- var title = new String();
-
- // Setup panels and fimstrip
- for(i=0; i<photos.length; i++)
- {
- // Build elements
- file = photos[i]['filename'];
- title = photos[i]['title'];
- panel = '<li><span class="panel-overlay">' + title +
- '</span><img src="' + image_folder + file +'" /></li>';
-
- // Add to the gallery
- $('#jquery-gallery-view').append(panel);
- }
-
- // Add gallery view
- $('#jquery-gallery-view').galleryView({
- panel_width: 300,
- panel_height: 250,
- frame_width: 100,
- frame_height: 50,
- filmstrip_position: 'bottom',
- overlay_position: 'top',
- transition_interval: 0,
- fade_panels: false,
- });
- }
+ var width = 300;
+ var height = 200;
+ var base_url = window.location.protocol + '//' + window.location.hostname;
+
+ $('.jquery-gallery-view:not(.jquery-gallery-view-processed)', context).each(function () {
+ $(this).addClass('jquery-gallery-view-processed');
+ $('#jquery-gallery-view').load(base_url + '/jquery_gallery_view', function() {
+ $('#jquery-gallery-view').galleryView({
+ panel_width: 300,
+ panel_height: 100,
+ frame_width: 65,
+ frame_height: 40,
+ filmstrip_position: 'bottom',
+ overlay_position: 'top',
+ transition_interval: 0,
+ });
+ });
+ });
}