PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / trunk
Floating Button – Easily Create Sticky, Fixed & Floating Buttons vtrunk
trunk 2.0.2 3.0 4.0 4.1.2 4.3 5.0 5.0.1 5.1 5.1.1 5.2 5.3 5.3.1 6.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 All 31 releases
floating-button / classes / Publish / EnqueueScript.php

EnqueueScript.php in Floating Button – Easily Create Sticky, Fixed & Floating Buttons trunk, at classes/Publish/EnqueueScript.php

95 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FloatingButton\Publish;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use FloatingButton\WOWP_Plugin;
8
9 class EnqueueScript {
10
11 /**
12 * @var mixed
13 */
14 private $id;
15 private $param;
16
17 public function __construct( $id, $param ) {
18 $this->id = $id;
19 $this->param = maybe_unserialize( $param );
20 }
21
22 /**
23 * @throws \JsonException
24 */
25 public function init(): void {
26
27 $slug = WOWP_Plugin::SLUG;
28 $version = WOWP_Plugin::info( 'version' );
29 $assets = WOWP_Plugin::url() . 'public/assets/';
30 $assets = apply_filters( WOWP_Plugin::PREFIX . '_frontend_assets', $assets );
31
32 $pre_suffix = ! WOWP_Plugin::DEVMODE ? '.min' : '';
33
34 $url_script = $assets . 'js/script' . $pre_suffix . '.js';
35 wp_enqueue_script( $slug, $url_script, array( 'jquery' ), $version, true );
36
37 $inline_script = $this->inline();
38 wp_add_inline_script( $slug, $inline_script, 'before' );
39
40 do_action( WOWP_Plugin::PREFIX . '_enqueue_script' );
41
42 }
43
44 /**
45 * @throws \JsonException
46 */
47 public function inline(): string {
48 $param = $this->param;
49
50 $arg = [
51 'element' => 'floatBtn-' . absint( $this->id ),
52 ];
53
54 if ( ! empty( $param['showAfterPosition'] ) ) {
55 $arg['showAfterPosition'] = (int) $param['showAfterPosition'];
56 }
57
58 if ( ! empty( $param['hideAfterPosition'] ) ) {
59 $arg['hideAfterPosition'] = (int) $param['hideAfterPosition'];
60 }
61
62 if ( ! empty( $param['showAfterTimer'] ) ) {
63 $arg['showAfterTimer'] = (int) $param['showAfterTimer'];
64 }
65
66 if ( ! empty( $param['hideAfterTimer'] ) ) {
67 $arg['hideAfterTimer'] = (int) $param['hideAfterTimer'];
68 }
69
70 if ( ! empty( $param['uncheckedBtn'] ) ) {
71 $arg['uncheckedBtn'] = true;
72 }
73
74 if ( ! empty( $param['uncheckedSubBtn'] ) ) {
75 $arg['uncheckedSubBtn'] = true;
76 }
77
78 if ( ! empty( $param['hideBtns'] ) ) {
79 $arg['hideBtns'] = true;
80 }
81
82 if ( ! empty( $param['touch'] ) ) {
83 $arg['touch'] = true;
84 }
85
86 if ( is_singular() ) {
87 $arg['pageId'] = get_the_ID();
88 }
89
90 return 'var FloatingButton_' . absint( $this->id ) . ' = ' . json_encode( $arg, JSON_THROW_ON_ERROR );
91
92 }
93
94
95 }