/[drupal]/contributions/modules/magnifier/magnifier.module
ViewVC logotype

Contents of /contributions/modules/magnifier/magnifier.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Mon Jan 28 14:53:11 2008 UTC (21 months, 4 weeks ago) by aaron
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +36 -12 lines
File MIME type: text/x-php
added optional support for jq module
1 <?php
2 // $Id: magnifier.module,v 1.6 2008/01/25 15:52:31 aaron Exp $
3
4 define('MAGNIFIER_MAGNIFY_DEFAULT', 4);
5 define('MAGNIFIER_GLASS_SIZE_DEFAULT', 125);
6
7 /**
8 * Displays an image with a magnifier glass box.
9 *
10 * @param $image_path
11 * This is the filepath to the image to display.
12 * @param $args
13 * An array with optional arguments:
14 * 'magnify' => 4, // the zoom magnification scale
15 * 'glass_size' => 125, // the size of the glass box, which will be a square to zoom
16 * 'imagecache' => '', // the imagecache setting to use for the smaller image. if this is set, then $image_path
17 * // will be used for the image in the glass box only, and the imagecache'd version will be
18 * // used in the main page display.
19 * 'image' => '', // the image path of the larger image displayed in the glass when zooming.
20 * // if not specified, this defaults to $image_path. You don't need this when using imagecache.
21 * 'width' => NULL, // the display width of the smaller image -- if specified, forces a browser image scale
22 * // you generally don't need this when using imagecache.
23 * 'height' => NULL, // the display height of the smaller image -- if specified, forces a browser image scale
24 * // you generally don't need this when using imagecache.
25 * 'title' => '', // the title attribute
26 * 'alt' => '', // the alt attribute
27 * 'attributes' => array(), // additional attributes to send, as 'rel' => 'rel_path'
28 * 'id' => FALSE, // if TRUE, then force magnifier to resolve as an ID (slightly faster, but may result in more
29 * // javascript if multiple images on screen). additionally, if this is a string, then the ID
30 * // of the image will be set to that string. Note that ID will always be set to true if an
31 * // imagecache is used, or 'image' is set, so you won't have to set this attribute in that case.
32 * @return
33 * returns the magnified image as output
34 */
35 function theme_magnifier($image_path, $args = array()) {
36 $magnify = $args['magnify'] ? $args['magnify'] : MAGNIFIER_MAGNIFY_DEFAULT;
37 $glass_size = $args['glass_size'] ? $args['glass_size'] : MAGNIFIER_GLASS_SIZE_DEFAULT;
38 $imagecache = $args['imagecache'] ? $args['imagecache'] : NULL;
39 $image = $args['image'] ? $args['image'] : '';
40 $id = ($imagecache || ($image && $image_path != $image) || $args['id']) ? TRUE : FALSE;
41 $id = is_string($args['id']) ? $args['id'] : $id;
42 $attributes = isset($args['attributes']) ? (array) $args['attributes'] : array();
43
44 $width = isset($args['width']) ? $args['width'] : NULL;
45 $height = isset($args['height']) ? $args['height'] : NULL;
46 if (isset($width)) {
47 $attributes['width'] = $width;
48 }
49 if (isset($height)) {
50 $attributes['height'] = $height;
51 }
52
53 $title = $args['title'] ? $args['title'] : '';
54 $alt = $args['alt'] ? $args['alt']: '';
55 $mag = magnifier_class($magnify, $glass_size, $image, $id);
56 if ($id) {
57 $attributes['id'] = $mag;
58 }
59 else if (isset($attributes['class'])) {
60 $attributes['class'] .= " $mag";
61 }
62 else {
63 $attributes['class'] = $mag;
64 }
65 $attributes['class'] .= ' magnifier';
66 if ($imagecache && module_exists('imagecache')) {
67 $output = theme('imagecache', $imagecache, $image_path, $title, $alt, $attributes);
68 }
69 else {
70 if ($title) {
71 $attributes['title'] = $title;
72 }
73 if ($alt) {
74 $attributes['alt'] = $alt;
75 }
76 $attr_str = '';
77 foreach ($attributes as $attr => $value) {
78 $attr_str .= ' ' . check_plain($attr) . '="' . check_plain($value) . '"';
79 }
80 $output = '<img src="' . url($image_path) . '" ' . $attr_str . " />\n";
81 }
82 return $output;
83 }
84
85 function magnifier_class($magnify = NULL, $glass_size = NULL, $image = '', $id = FALSE) {
86 static $count = 0, $classes;
87
88 if (!isset($magnify)) {
89 $magnify = MAGNIFIER_MAGNIFY_DEFAULT;
90 }
91 if (!isset($glass_size)) {
92 $glass_size = MAGNIFIER_GLASS_SIZE_DEFAULT;
93 }
94 $id_or_class = $id ? '#' : '.';
95
96 if (!isset($classes)) {
97 $classes = array();
98 if (module_exists('jq')) {
99 if (!jq_add('magnifier')) {
100 return FALSE;
101 }
102 }
103 else {
104 $base = drupal_get_path('module', 'magnifier');
105 drupal_add_js($base . '/js/magnifier.js', 'module');
106 drupal_add_css($base . '/css/magnifier.css', 'module');
107 }
108 }
109 if (!isset($classes[$magnify][$glass_size][$id_or_class][$image])) {
110 $class_name = is_string($id) ? $id : ('magnifier-' . $count);
111 $classes[$magnify][$glass_size][$id_or_class][$image] = $class_name;
112 if ($image) {
113 $image_str = ', image:"' . $image . '"';
114 }
115 $js = '
116 $(document).ready(function() {
117 $("img' . $id_or_class . $class_name . '").magnify({ scale:' . $magnify . ', glassSize:' . $glass_size . $image_str . ' });
118 });
119 ';
120 drupal_add_js($js, 'inline');
121 $count++;
122 }
123 return $classes[$magnify][$glass_size][$id_or_class][$image];
124 }
125
126 function magnifier_id($magnify = NULL, $glass_size = NULL, $image = '', $id = TRUE) {
127 return magnifier_class($magnify, $glass_size, $image, $id);
128 }
129
130 function magnifier_jq($op, $plugin = NULL) {
131 switch ($op) {
132 case 'info':
133 return array(
134 'magnifier' => array(
135 'name' => t('Magnifier'),
136 'description' => t('This Magnifier jQuery plugin is based on the Dojo version. jQuery image magnification plugin - ported from dojox.image.Magnifier class.'),
137 'version' => 'modified by Aaron Winborn',
138 'url' => 'http://drupal.org/project/magnifier',
139 'files' => array(
140 'js' => array(
141 drupal_get_path('module', 'magnifier') . '/js/magnifier.js',
142 ),
143 'css' => array(
144 drupal_get_path('module', 'magnifier') . '/css/magnifier.css',
145 ),
146 ),
147 ),
148 );
149 break;
150 }
151 }

  ViewVC Help
Powered by ViewVC 1.1.2