-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgallery-owl-carousel.php
217 lines (174 loc) · 6.51 KB
/
gallery-owl-carousel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* FooGallery Owl Carousel template
* This is the template that is run when a FooGallery shortcode is rendered to the frontend
*/
//the current FooGallery that is currently being rendered to the frontend
global $current_foogallery;
//the current shortcode args
global $current_foogallery_arguments;
//get our thumbnail sizing args
$args = foogallery_gallery_template_setting( 'thumbnail_size', 'thumbnail' );
//add the link setting to the args
$args['link'] = foogallery_gallery_template_setting( 'thumbnail_link', 'image' );
//get which lightbox we want to use
$lightbox = foogallery_gallery_template_setting( 'lightbox', 'unknown' );
//other owl carousel settings
$items = foogallery_gallery_template_setting( 'items', '3' );
$nav = foogallery_gallery_template_setting( 'nav', 'true' );
$dots = foogallery_gallery_template_setting( 'dots', 'true' );
$autoplay = foogallery_gallery_template_setting( 'autoplay', 'true' );
$hash = foogallery_gallery_template_setting( 'hash', 'true' );
$pause = foogallery_gallery_template_setting( 'pause', 'true' );
$seconds = foogallery_gallery_template_setting( 'seconds', '4000' );
$loop = foogallery_gallery_template_setting( 'loop', 'true' );
$margin = foogallery_gallery_template_setting( 'margin', '10' );
$hover_effect = foogallery_gallery_template_setting( 'hover-effect', 'hover-effect-zoom' );
$border_style = foogallery_gallery_template_setting( 'border-style', 'border-style-square-white' );
$animation = foogallery_gallery_template_setting( 'animation', false );
$showdesc = foogallery_gallery_template_setting( 'showdesc', false );
$advanced = foogallery_gallery_template_setting( 'enable_advanced', 'no' );
$responsive = foogallery_gallery_template_setting( 'enable-responsive', 'no' );
$itemsat0 = foogallery_gallery_template_setting( 'items-at-0', false );
$itemsat480 = foogallery_gallery_template_setting( 'items-at-480', false );
$itemsat960 = foogallery_gallery_template_setting( 'items-at-960', false );
$autowidth = foogallery_gallery_template_setting( 'autowidth', false );
if(( $border_style == '' ) || ( $border_style == 'border-style-rounded' ) ) {
$hasborder = '';
$height = $args['height'];
} else {
$hasborder = 'hasborder';
$height = ($args['height'] + 20);
}
//general FooGallery settings that are useful for owl
$width = $args['width']; //image width
$gallid = $current_foogallery->ID; // current FooGallery ID
?>
<style>
/*Used to keep captions inside the visible area*/
#foogallery-gallery-<?php echo $gallid; ?> .foo-item {
max-height: <?php echo $height ; ?>px;
}
#foogallery-gallery-<?php echo $gallid; ?>.border-style-inset a::after {
box-shadow: inset 0 0 20px #000;
-moz-box-shadow: inset 0 0 20px #000;
-webkit-box-shadow: inset 0 0 <?php echo 'calc(' . $height . ')px/4'; ?> rgba(0,0,0,0.8);
}
</style>
<div id="foogallery-gallery-<?php echo $gallid; ?>" class="<?php echo foogallery_build_class_attribute( $current_foogallery, 'foogallery-lightbox-' . $lightbox, 'owl-carousel ' . $hover_effect, $border_style, $hasborder ); ?>">
<?php
foreach ( $current_foogallery->attachments() as $attachment ) {
$title = $attachment->title;
$strippedtitle = str_replace(' ', '_', $title);
$datahash = ( empty($title) ? 'no-title' : $strippedtitle );
$dohash = ( $hash =='true' ? 'data-hash="' . $datahash . '"' : '');
?>
<div class="foo-item" <?php echo $dohash ; ?>>
<?php
$cap = $attachment->caption;
$desc = $attachment->description;
//the image instance
echo $attachment->html( $args );
// show caption if it exists
// basically, if both caption and description are empty, show nothing here
// otherwise, check if either exists then show it
if( $showdesc == true ) {
if( (empty($cap) ) && ( empty($desc)) ) { } else { ?>
<div class="owl-caption">
<?php if( !empty($cap) ) { ?>
<h4><?php echo $cap ; ?></h4>
<?php } if( !empty($desc) ) { ?>
<p><?php echo $desc ; ?></p>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
</div>
<?php }
// end foreach ?>
</div>
<script>
/* The Owl Initialization Script
/* The first lines conditionally show the slide animation */
jQuery(window).on("load", function(){
var $galleryContainer = jQuery( '#foogallery-gallery-<?php echo $gallid; ?>' );
var $containerID = '#foogallery-gallery-<?php echo $gallid; ?>';
jQuery(document).on('keydown', function( event ) { //attach event listener
if (event.keyCode == 37) {
$galleryContainer.trigger('prev.owl')
}
if (event.keyCode == 39) {
$galleryContainer.trigger('next.owl')
}
});
<?php
switch ($animation) {
case 'lightspeed' :
$aniOut = 'lightSpeedOut';
$aniIn = 'lightSpeedIn';
break;
case 'zoomleftright' :
$aniOut = 'zoomOutLeft';
$aniIn = 'zoomOutRight';
break;
case 'zoom' :
$aniOut = 'zoomOut';
$aniIn = 'zoomIn';
break;
case 'roll' :
$aniOut = 'rollOut';
$aniIn = 'rollIn';
break;
case 'sliderock' :
$aniOut = 'slideOutDown';
$aniIn = 'flipInX';
break;
case 'fade' :
$aniOut = 'fadeOut';
$aniIn = 'fadeIn';
break;
default :
$aniOut = false;
$aniIn = false;
}
?>
$galleryContainer.owlCarousel({
<?php if ( $animation != "left" ) { ?>
animateOut: '<?php echo $aniOut; ?>',
animateIn: '<?php echo $aniIn; ?>',
<?php } ?>
items: <?php echo $items; ?>,
nav: <?php echo $nav; ?>,
margin: <?php echo $margin; ?>,
loop:<?php echo $loop; ?>,
autoplay: <?php echo $autoplay; ?>,
autoplaySpeed: <?php echo $seconds; ?>,
smartSpeed:250,
navSpeed: 1250,
navText: ['<?php printf(__(apply_filters('owl_prev_text',esc_html__('prev'),'foogallery-owl-carousel'))); ?>', '<?php printf(__(apply_filters('owl_next_text',esc_html__('next'),'foogallery-owl-carousel'))); ?>'],
autoplayHoverPause: <?php echo $pause; ?>,
lazyLoad: <?php printf(__(apply_filters('foogallery_owl_lazyload', $lazyLoad = true, $gallid), 'foogallery-owl-carousel' )); ?>,
autoWidth: <?php echo $autowidth; ?>,
<?php if( $advanced == 'yes') { ?>
URLhashListener: <?php echo $hash; ?>,
startPosition: <?php printf(__(apply_filters('foogallery_owl_startposition', $startpos='\'URLHash\'', $gallid), 'foogallery-owl-carousel' )); ?>,
dots: <?php echo $dots; ?>,
<?php if($responsive = 'yes') { ?>
responsiveClass: true,
responsive:{
0:{
items: <?php echo $itemsat0 ?>,
},
480:{
items: <?php echo $itemsat480 ?>,
},
960:{
items: <?php echo $itemsat960 ?>,
}
},
<?php }
} ?>
<?php printf(__(apply_filters('foogallery_owl_custom_init',$custom_init='', $gallid))); ?>
});
});
</script>