|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Integrate with the FancyBox lightbox and gallery scripts |
|
4
|
|
|
* @see https://fancyapps.com/fancybox/3/docs/#options |
|
5
|
|
|
* @since TODO |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Register the FancyBox lightbox |
|
10
|
|
|
* |
|
11
|
|
|
* @internal |
|
12
|
|
|
*/ |
|
13
|
|
|
class GravityView_Lightbox_Provider_FancyBox extends GravityView_Lightbox_Provider { |
|
14
|
|
|
|
|
15
|
|
|
public static $slug = 'fancybox'; |
|
16
|
|
|
|
|
17
|
|
|
public static $script_slug = 'gravityview-fancybox'; |
|
18
|
|
|
|
|
19
|
|
|
public static $style_slug = 'gravityview-fancybox'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Options to pass to Fancybox |
|
23
|
|
|
* |
|
24
|
|
|
* @see https://fancyapps.com/fancybox/3/docs/#options |
|
25
|
|
|
* |
|
26
|
|
|
* @return array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function default_settings() { |
|
29
|
|
|
|
|
30
|
|
|
$defaults = array( |
|
31
|
|
|
'animationEffect' => 'fade', |
|
32
|
|
|
'toolbar' => true, |
|
33
|
|
|
'closeExisting' => true, |
|
34
|
|
|
'arrows' => true, |
|
35
|
|
|
'buttons' => array( |
|
36
|
|
|
'thumbs', |
|
37
|
|
|
'close', |
|
38
|
|
|
), |
|
39
|
|
|
'i18n' => array( |
|
40
|
|
|
'en' => array( |
|
41
|
|
|
'CLOSE' => __( 'Close', 'gravityview' ), |
|
42
|
|
|
'NEXT' => __( 'Next', 'gravityview' ), |
|
43
|
|
|
'PREV' => __( 'Previous', 'gravityview' ), |
|
44
|
|
|
'ERROR' => __( 'The requested content cannot be loaded. Please try again later.', 'gravityview' ), |
|
45
|
|
|
'PLAY_START' => __( 'Start slideshow', 'gravityview' ), |
|
46
|
|
|
'PLAY_STOP' => __( 'Pause slideshow', 'gravityview' ), |
|
47
|
|
|
'FULL_SCREEN' => __( 'Full screen', 'gravityview' ), |
|
48
|
|
|
'THUMBS' => __( 'Thumbnails', 'gravityview' ), |
|
49
|
|
|
'DOWNLOAD' => __( 'Download', 'gravityview' ), |
|
50
|
|
|
'SHARE' => __( 'Share', 'gravityview' ), |
|
51
|
|
|
'ZOOM' => __( 'Zoom', 'gravityview' ), |
|
52
|
|
|
), |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
return $defaults; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @inheritDoc |
|
61
|
|
|
*/ |
|
62
|
|
|
public function output_footer() { |
|
63
|
|
|
|
|
64
|
|
|
$settings = self::get_settings(); |
|
65
|
|
|
|
|
66
|
|
|
$settings = json_encode( $settings ); |
|
67
|
|
|
|
|
68
|
|
|
?> |
|
69
|
|
|
<style> |
|
70
|
|
|
.fancybox-container { |
|
71
|
|
|
z-index: 100000; /** Divi is 99999 */ |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
.admin-bar .fancybox-container { |
|
75
|
|
|
margin-top: 32px; |
|
76
|
|
|
} |
|
77
|
|
|
</style> |
|
78
|
|
|
<script> |
|
79
|
|
|
jQuery( '.gravityview-fancybox' ).fancybox(<?php echo $settings; ?>); |
|
80
|
|
|
</script> |
|
81
|
|
|
<?php |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @inheritDoc |
|
86
|
|
|
*/ |
|
87
|
|
|
public function enqueue_scripts() { |
|
88
|
|
|
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
89
|
|
|
wp_enqueue_script( self::$script_slug, plugins_url( 'assets/lib/fancybox/dist/jquery.fancybox' . $min . '.js', GRAVITYVIEW_FILE ), array( 'jquery' ), GV_PLUGIN_VERSION ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @inheritDoc |
|
94
|
|
|
*/ |
|
95
|
|
|
public function enqueue_styles() { |
|
96
|
|
|
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
97
|
|
|
wp_enqueue_style( self::$style_slug, plugins_url( 'assets/lib/fancybox/dist/jquery.fancybox' . $min . '.css', GRAVITYVIEW_FILE ), array(), GV_PLUGIN_VERSION ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @inheritDoc |
|
102
|
|
|
*/ |
|
103
|
55 |
|
public function allowed_atts( $atts = array() ) { |
|
104
|
|
|
|
|
105
|
55 |
|
$atts['data-fancybox'] = null; |
|
106
|
55 |
|
$atts['data-fancybox-trigger'] = null; |
|
107
|
55 |
|
$atts['data-fancybox-index'] = null; |
|
108
|
55 |
|
$atts['data-src'] = null; |
|
109
|
55 |
|
$atts['data-type'] = null; |
|
110
|
55 |
|
$atts['data-width'] = null; |
|
111
|
55 |
|
$atts['data-height'] = null; |
|
112
|
55 |
|
$atts['data-srcset'] = null; |
|
113
|
55 |
|
$atts['data-caption'] = null; |
|
114
|
55 |
|
$atts['data-options'] = null; |
|
115
|
55 |
|
$atts['data-filter'] = null; |
|
116
|
|
|
|
|
117
|
55 |
|
return $atts; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @inheritDoc |
|
122
|
|
|
*/ |
|
123
|
3 |
|
public function fileupload_link_atts( $link_atts, $field_compat = array(), $context = null ) { |
|
124
|
|
|
|
|
125
|
3 |
|
if ( ! $context->view->settings->get( 'lightbox', false ) ) { |
|
126
|
1 |
|
return $link_atts; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
3 |
|
$link_atts['class'] = \GV\Utils::get( $link_atts, 'class' ) . ' gravityview-fancybox'; |
|
130
|
|
|
|
|
131
|
3 |
|
$link_atts['class'] = sanitize_html_class( $link_atts['class'] ); |
|
132
|
|
|
|
|
133
|
3 |
|
if ( $context && ! empty( $context->field->field ) ) { |
|
134
|
3 |
|
if ( $context->field->field->multipleFiles ) { |
|
135
|
3 |
|
$entry = $context->entry->as_entry(); |
|
136
|
3 |
|
$link_atts['data-fancybox'] = 'gallery-' . sprintf( "%s-%s-%s", $entry['form_id'], $context->field->ID, $context->entry->get_slug() ); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
3 |
|
return $link_atts; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
GravityView_Lightbox::register( 'GravityView_Lightbox_Provider_FancyBox' ); |
|
146
|
|
|
|