-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathparallax.php
230 lines (203 loc) · 8.11 KB
/
parallax.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
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/**
* Title: Parallax Element
*
* Description: Adds parallax effect to different elements.
*
* Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
* should be made in a child theme.
*
* @category Cyber Chimps Framework
* @package Framework
* @since 1.0
* @author CyberChimps
* @license http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
* @link http://www.cyberchimps.com/
*/
// Don't load directly
if ( !defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( !class_exists( 'CyberChimpsParallax' ) ) {
class CyberChimpsParallax {
protected static $instance;
public $options;
public $slider_parallax_toggle;
public $slider_parallax_image;
public $portfolio_parallax_toggle;
public $portfolio_parallax_image;
public $boxes_parallax_toggle;
public $boxes_parallax_image;
public $body_parallax_toggle;
/* Static Singleton Factory Method */
public static function instance() {
if ( !isset( self::$instance ) ) {
$className = __CLASS__;
self::$instance = new $className;
}
return self::$instance;
}
/**
* Initializes plugin variables and sets up WordPress hooks/actions.
*
* @return void
*/
protected function __construct() {
$this->options = get_option( 'cyberchimps_options' );
add_action( 'wp_enqueue_scripts', array( $this, 'cyberchimps_parallax_scripts' ) );
add_action( 'wp_footer', array( $this, 'cyberchimps_parallax_render' ) );
add_filter( 'cyberchimps_field_filter', array( $this, 'cyberchimps_parallax_fields' ) );
// Set slider options
$this->slider_parallax_toggle = ( isset( $this->options['cyberchimps_blog_slider_parallax'] ) ) ? $this->options['cyberchimps_blog_slider_parallax'] : 1;
$this->slider_parallax_image = ( isset( $this->options['cyberchimps_blog_slider_parallax_image'] ) ) ? $this->options['cyberchimps_blog_slider_parallax_image'] : '';
// Set portfolio parallax options.
$this->portfolio_parallax_toggle = ( isset( $this->options['cyberchimps_blog_portfolio_parallax'] ) ) ? $this->options['cyberchimps_blog_portfolio_parallax'] : 1;
$this->portfolio_parallax_image = ( isset( $this->options['cyberchimps_blog_portfolio_parallax_image'] ) ) ? $this->options['cyberchimps_blog_portfolio_parallax_image'] : '';
// Get boxes parallax options.
$this->boxes_parallax_toggle = ( isset( $this->options['cyberchimps_blog_boxes_parallax'] ) ) ? $this->options['cyberchimps_blog_boxes_parallax'] : 1;
$this->boxes_parallax_image = ( isset( $this->options['cyberchimps_blog_boxes_parallax_image'] ) ) ? $this->options['cyberchimps_blog_boxes_parallax_image'] : '';
// Get boxes parallax options.
$this->body_parallax_toggle = ( isset( $this->options['cyberchimps_body_parallax'] ) ) ? $this->options['cyberchimps_body_parallax'] : 1;
}
/**
* Sets up scripts for parallax
*/
public function cyberchimps_parallax_scripts() {
// Add parallax js library.
wp_enqueue_script( 'parallax-js', get_template_directory_uri() . '/elements/lib/js/jquery.parallax.min.js', array( 'jquery' ) );
}
/**
* Adds option fields to blog options
*
* @param $original
*
* @return mixed
*/
public function cyberchimps_parallax_fields( $original ) {
// Slider parallax toggle.
$new_field[][2] = array(
'name' => __( 'Parallax', 'cyberchimps_core' ),
'id' => 'cyberchimps_blog_slider_parallax',
'type' => 'toggle',
'std' => 1,
'section' => 'cyberchimps_blog_slider_lite_section',
'heading' => 'cyberchimps_blog_heading'
);
// Slider parallax image.
$new_field[][3] = array(
'name' => __( 'Background image for parallax', 'cyberchimps_core' ),
'desc' => __( 'Enter URL or upload file', 'cyberchimps_core' ),
'id' => 'cyberchimps_blog_slider_parallax_image',
'class' => 'cyberchimps_blog_slider_parallax_toggle',
'type' => 'upload',
'section' => 'cyberchimps_blog_slider_lite_section',
'heading' => 'cyberchimps_blog_heading'
);
// Portfolio parallax toggle.
$new_field[][2] = array(
'name' => __( 'Parallax', 'cyberchimps_core' ),
'id' => 'cyberchimps_blog_portfolio_parallax',
'type' => 'toggle',
'std' => 1,
'section' => 'cyberchimps_blog_portfolio_lite_section',
'heading' => 'cyberchimps_blog_heading'
);
// Portfolio parallax image.
$new_field[][3] = array(
'name' => __( 'Background image for parallax', 'cyberchimps_core' ),
'desc' => __( 'Enter URL or upload file', 'cyberchimps_core' ),
'id' => 'cyberchimps_blog_portfolio_parallax_image',
'class' => 'cyberchimps_blog_portfolio_parallax_toggle',
'type' => 'upload',
'section' => 'cyberchimps_blog_portfolio_lite_section',
'heading' => 'cyberchimps_blog_heading'
);
// Boxes parallax toggle.
$new_field[][2] = array(
'name' => __( 'Parallax', 'cyberchimps_core' ),
'id' => 'cyberchimps_blog_boxes_parallax',
'type' => 'toggle',
'std' => 1,
'section' => 'cyberchimps_blog_boxes_lite_section',
'heading' => 'cyberchimps_blog_heading'
);
// Boxes parallax image.
$new_field[][3] = array(
'name' => __( 'Background image for parallax', 'cyberchimps_core' ),
'desc' => __( 'Enter URL or upload file', 'cyberchimps_core' ),
'id' => 'cyberchimps_blog_boxes_parallax_image',
'class' => 'cyberchimps_blog_boxes_parallax_toggle',
'type' => 'upload',
'section' => 'cyberchimps_blog_boxes_lite_section',
'heading' => 'cyberchimps_blog_heading'
);
// Body parallax toggle.
$new_field[][1] = array(
'name' => __( 'Parallax', 'cyberchimps_core' ),
'id' => 'cyberchimps_body_parallax',
'desc' => __( 'Set the background image at Appearance > Background to get parallax effect on whole body.', 'cyberchimps_core' ),
'type' => 'toggle',
'std' => 1,
'section' => 'cyberchimps_custom_layout_section',
'heading' => 'cyberchimps_design_heading'
);
$new_fields = cyberchimps_array_field_organizer( $original, $new_field );
return $new_fields;
}
// Set parallax to individual elements by checking toggle.
public function cyberchimps_parallax_render() {
?>
<script>
jQuery(document).ready(function () {
<?php
// Add parallax to slider.
if( $this->slider_parallax_toggle && $this->slider_parallax_image ) { ?>
jQuery('#slider_lite_section').css({
'background-image': 'url("<?php echo $this->slider_parallax_image;?>")',
'background-size': '100%',
'padding': '100px 0',
'border-top': '5px solid rgba(0, 0, 0, 0.3)',
'border-bottom': '5px solid rgba(0, 0, 0, 0.3)'
});
jQuery('#slider_lite_section').parallax('50%', 0.5);
<?php }
// Add parallax to portfolio.
if( $this->portfolio_parallax_toggle && $this->portfolio_parallax_image ) { ?>
jQuery('#portfolio_lite_section').css({
'background-image': 'url("<?php echo $this->portfolio_parallax_image;?>")',
'background-size': '100%',
'padding': '100px 0 80px 0',
'border-top': '5px solid rgba(0, 0, 0, 0.3)',
'border-bottom': '5px solid rgba(0, 0, 0, 0.3)'
});
jQuery('#portfolio_lite_section').parallax('50%', 0.5);
<?php }
// Add parallax to boxes.
if( $this->boxes_parallax_toggle && $this->boxes_parallax_image ) { ?>
jQuery('#boxes_lite_section').css({
'background-image': 'url("<?php echo $this->boxes_parallax_image;?>")',
'background-size': '100%',
'padding-top': '100px 0 90px 0',
'border-top': '5px solid rgba(0, 0, 0, 0.3)',
'border-bottom': '5px solid rgba(0, 0, 0, 0.3)'
});
jQuery('#boxes_lite_section').parallax('50%', 0.5);
<?php }
// Add parallax to body.
if( $this->body_parallax_toggle ) { ?>
jQuery('body').parallax('50%', -0.5);
<?php } ?>
jQuery('#testimonial_section').css({
'background-size': '100%'
});
jQuery('#testimonial_section').parallax('50%', 0.5);
jQuery('#map_contact_section').css({
'background-size': '100%'
});
jQuery('#map_contact_section').parallax('50%', 0.5);
});
</script>
<?php
}
}
}