PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.0
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.0
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / class-scripts-styles.php

class-scripts-styles.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.2.0, at includes/class-scripts-styles.php

367 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The scripts class
5 *
6 * @since 1.1.0
7 */
8 class WeForms_Scripts_Styles {
9
10 /**
11 * The constructor
12 */
13 function __construct() {
14
15 if ( is_admin() ) {
16 add_action( 'admin_enqueue_scripts', array( $this, 'register_backend' ) );
17 } else {
18 add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend' ) );
19 }
20 }
21
22 /**
23 * Register frontend scripts and styles
24 *
25 * @return void
26 */
27 public function register_frontend() {
28 $this->register_styles( $this->get_frontend_styles() );
29 $this->register_scripts( $this->get_frontend_scripts() );
30
31 $this->get_frontend_localized();
32 }
33
34 /**
35 * Register frontend scripts and styles
36 *
37 * @return void
38 */
39 public function register_backend() {
40 $this->register_styles( $this->get_admin_styles() );
41 $this->register_scripts( $this->get_admin_scripts() );
42
43 $this->get_frontend_localized();
44 }
45
46 /**
47 * Enqueue all the scripts and styles for frontend
48 *
49 * @return void
50 */
51 public function enqueue_frontend() {
52 $this->enqueue_scripts( $this->get_frontend_scripts() );
53 $this->enqueue_styles( $this->get_frontend_styles() );
54 }
55
56 /**
57 * Enqueue all the scripts and styles for backend
58 *
59 * @return void
60 */
61 public function enqueue_backend() {
62 $this->enqueue_scripts( $this->get_admin_scripts() );
63 $this->enqueue_styles( $this->get_admin_styles() );
64 }
65
66 /**
67 * Get file prefix
68 *
69 * @return string
70 */
71 public function get_prefix() {
72 $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
73
74 return $prefix;
75 }
76
77 /**
78 * Get all registered admin scripts
79 *
80 * @return array
81 */
82 public function get_admin_scripts() {
83 $prefix = $this->get_prefix();
84
85 $form_builder_js_deps = apply_filters( 'wpuf-form-builder-js-deps', array(
86 'jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'underscore',
87 'wpuf-vue', 'wpuf-vuex', 'wpuf-sweetalert2', 'wpuf-jquery-scrollTo',
88 'wpuf-selectize', 'wpuf-toastr', 'wpuf-clipboard', 'wpuf-tooltip'
89 ) );
90
91 $builder_scripts = apply_filters( 'weforms_builder_scripts', array(
92 'wpuf-vue' => array(
93 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/vue/vue' . $prefix . '.js',
94 'deps' => false,
95 'in_footer' => true
96 ),
97 'wpuf-vuex' => array(
98 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/vuex/vuex' . $prefix . '.js',
99 'deps' => array( 'wpuf-vue' ),
100 'in_footer' => true
101 ),
102 'wpuf-vue-router' => array(
103 'src' => WEFORMS_ASSET_URI . '/js/vendor/vue-router.js',
104 'deps' => array( 'jquery', 'wpuf-vue', 'wpuf-vuex' ),
105 'in_footer' => true
106 ),
107 'nprogress' => array(
108 'src' => WEFORMS_ASSET_URI . '/js/vendor/nprogress.js',
109 'deps' => array( 'jquery' ),
110 'in_footer' => true
111 ),
112 'wpuf-sweetalert2' => array(
113 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.js',
114 'deps' => false,
115 'in_footer' => true
116 ),
117 'wpuf-jquery-scrollTo' => array(
118 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js',
119 'deps' => array( 'jquery' ),
120 'in_footer' => true
121 ),
122 'wpuf-selectize' => array(
123 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/selectize/js/standalone/selectize' . $prefix . '.js',
124 'deps' => array( 'jquery' ),
125 'in_footer' => true
126 ),
127 'wpuf-toastr' => array(
128 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/toastr/toastr' . $prefix . '.js',
129 'deps' => false,
130 'in_footer' => true
131 ),
132 'wpuf-clipboard' => array(
133 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/clipboard/clipboard' . $prefix . '.js',
134 'deps' => false,
135 'in_footer' => true
136 ),
137 'wpuf-tooltip' => array(
138 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/tooltip/tooltip' . $prefix . '.js',
139 'deps' => false,
140 'in_footer' => true
141 ),
142 'jquery-ui-timepicker' => array(
143 'src' => WEFORMS_ASSET_URI . '/wpuf/js/jquery-ui-timepicker-addon.js',
144 'deps' => array('jquery-ui-datepicker'),
145 'in_footer' => true
146 ),
147 'wpuf-form-builder-mixins' => array(
148 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-mixins.js',
149 'deps' => $form_builder_js_deps,
150 'in_footer' => true
151 ),
152 'wpuf-form-builder-mixins-form' => array(
153 'src' => WEFORMS_ASSET_URI . '/js/wpuf-form-builder-contact-forms.js',
154 'deps' => $form_builder_js_deps,
155 'in_footer' => true
156 ),
157 'wpuf-form-builder-components' => array(
158 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-components.js',
159 'deps' => array( 'wpuf-form-builder-mixins', 'wpuf-form-builder-mixins-form' ),
160 'in_footer' => true
161 ),
162
163 ) );
164
165 $spa_scripts = array(
166 'weforms-mixins' => array(
167 'src' => WEFORMS_ASSET_URI . '/js/spa-mixins.js',
168 'deps' => array( 'wpuf-vue-router', 'wp-util' ),
169 'in_footer' => true
170 ),
171 'weforms-components' => array(
172 'src' => WEFORMS_ASSET_URI . '/js/form-builder-components.js',
173 'deps' => array( 'wpuf-vue', 'wp-util' ),
174 'in_footer' => true
175 ),
176 'weforms-app' => array(
177 'src' => WEFORMS_ASSET_URI . '/js/spa-app.js',
178 'deps' => array( 'wpuf-vue-router', 'wp-util', 'wpuf-form-builder-components' ),
179 'in_footer' => true
180 ),
181 );
182
183 $scripts = array_merge( $builder_scripts, $spa_scripts );
184
185 return apply_filters( 'weforms_admin_scripts', $scripts );
186 }
187
188 /**
189 * Get admin styles
190 *
191 * @return array
192 */
193 public function get_admin_styles() {
194 $frontend_styles = $this->get_frontend_styles();
195
196 $backend_styles = array(
197 'wpuf-font-awesome' => array(
198 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/font-awesome/css/font-awesome.min.css',
199 ),
200 'wpuf-sweetalert2' => array(
201 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.css',
202 ),
203 'wpuf-selectize' => array(
204 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/selectize/css/selectize.default.css',
205 ),
206 'wpuf-toastr' => array(
207 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/toastr/toastr.min.css',
208 ),
209 'wpuf-tooltip' => array(
210 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/tooltip/tooltip.css',
211 ),
212 'wpuf-form-builder' => array(
213 'src' => WEFORMS_ASSET_URI . '/wpuf/css/wpuf-form-builder.css',
214 'deps' => array(
215 'wpuf-css', 'wpuf-font-awesome', 'wpuf-sweetalert2', 'wpuf-selectize', 'wpuf-toastr', 'wpuf-tooltip'
216 )
217 ),
218 'weforms-style' => array(
219 'src' => WEFORMS_ASSET_URI . '/css/admin.css',
220 )
221 );
222
223 $styles = array_merge( $frontend_styles, $backend_styles );
224
225 return apply_filters( 'weforms_admin_styles', $styles );
226 }
227
228 /**
229 * Get all registered frontend scripts
230 *
231 * @return array
232 */
233 public function get_frontend_scripts() {
234 $scripts = array(
235 'wpuf-form' => array(
236 'src' => WEFORMS_ASSET_URI . '/wpuf/js/frontend-form.js',
237 'deps' => array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider' ),
238 'in_footer' => false
239 ),
240 'jquery-ui-timepicker' => array(
241 'src' => WEFORMS_ASSET_URI . '/wpuf/js/jquery-ui-timepicker-addon.js',
242 'deps' => array('jquery-ui-datepicker'),
243 'in_footer' => false
244 ),
245 'wpuf-upload' => array(
246 'src' => WEFORMS_ASSET_URI . '/wpuf/js/upload.js',
247 'deps' => array( 'jquery', 'plupload-handlers' ),
248 'in_footer' => false
249 )
250 );
251
252 return apply_filters( 'weforms_frontend_scripts', $scripts );
253 }
254
255 /**
256 * Get all registered frontend styles
257 *
258 * @return array
259 */
260 public function get_frontend_styles() {
261 $styles = array(
262 'wpuf-css' => array(
263 'src' => WEFORMS_ASSET_URI . '/wpuf/css/frontend-forms.css',
264 ),
265 'jquery-ui' => array(
266 'src' => WEFORMS_ASSET_URI . '/wpuf/css/jquery-ui-1.9.1.custom.css',
267 )
268 );
269
270 return apply_filters( 'weforms_frontend_styles', $styles );
271 }
272
273 /**
274 * Frontend localized scripts
275 *
276 * @return void
277 */
278 public function get_frontend_localized() {
279 wp_localize_script( 'wpuf-form', 'wpuf_frontend', array(
280 'ajaxurl' => admin_url( 'admin-ajax.php' ),
281 'error_message' => __( 'Please fix the errors to proceed', 'wpuf' ),
282 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
283 'word_limit' => __( 'Word limit reached', 'wpuf' )
284 ) );
285
286 wp_localize_script( 'wpuf-form', 'error_str_obj', array(
287 'required' => __( 'is required', 'wpuf' ),
288 'mismatch' => __( 'does not match', 'wpuf' ),
289 'validation' => __( 'is not valid', 'wpuf' ),
290 'duplicate' => __( 'requires a unique entry and this value has already been used', 'wpuf' ),
291 ) );
292
293 wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', array(
294 'confirmMsg' => __( 'Are you sure?', 'wpuf' ),
295 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
296 'ajaxurl' => admin_url( 'admin-ajax.php' ),
297 'plupload' => array(
298 'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
299 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
300 'filters' => array(array('title' => __( 'Allowed Files', 'wpuf' ), 'extensions' => '*')),
301 'multipart' => true,
302 'urlstream_upload' => true,
303 'warning' => __( 'Maximum number of files reached!', 'wpuf' ),
304 'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'wpuf' ),
305 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'wpuf' )
306 )
307 ));
308 }
309
310 /**
311 * Register scripts
312 *
313 * @param array $scripts
314 *
315 * @return void
316 */
317 public function register_scripts( $scripts ) {
318 foreach ($scripts as $handle => $script) {
319 $deps = isset( $script['deps'] ) ? $script['deps'] : false;
320 $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
321
322 wp_register_script( $handle, $script['src'], $deps, WEFORMS_VERSION, $in_footer );
323 }
324 }
325
326 /**
327 * Register styles
328 *
329 * @param array $styles
330 *
331 * @return void
332 */
333 public function register_styles( $styles ) {
334 foreach ($styles as $handle => $style) {
335 $deps = isset( $style['deps'] ) ? $style['deps'] : false;
336
337 wp_register_style( $handle, $style['src'], $deps, WEFORMS_VERSION );
338 }
339 }
340
341 /**
342 * Enqueue the scripts
343 *
344 * @param array $scripts
345 *
346 * @return void
347 */
348 public function enqueue_scripts( $scripts ) {
349 foreach ($scripts as $handle => $script) {
350 wp_enqueue_script( $handle );
351 }
352 }
353
354 /**
355 * Enqueue styles
356 *
357 * @param array $styles
358 *
359 * @return void
360 */
361 public function enqueue_styles( $styles ) {
362 foreach ($styles as $handle => $script) {
363 wp_enqueue_style( $handle );
364 }
365 }
366 }
367