Completed
Branch EDTR/master (6bd139)
by
unknown
35:03 queued 26:41
created

EspressoLegacyAdminAssetManager::addAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\services\assets;
4
5
use EEH_Qtip_Loader;
6
use EventEspresso\core\services\assets\AssetManager;
7
8
/**
9
 * Class EspressoLegacyAdminAssetManager
10
 *
11
 * @package EventEspresso\core\domain\services\assets
12
 * @author  Brent Christensen
13
 * @since   $VID:$
14
 */
15
class EspressoLegacyAdminAssetManager extends AssetManager
16
{
17
18
    const JS_HANDLE_INJECT_WP = 'ee-inject-wp';
19
20
    const JS_HANDLE_JQUERY_COOKIE = 'jquery-cookie';
21
22
    const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr';
23
24
    const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride';
25
26
    const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css';
27
28
    const CSS_HANDLE_JOYRIDE = 'joyride-css';
29
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function addAssets()
35
    {
36
        $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN);
37
        $this->registerJavascript($joyride);
38
        $this->registerStyleSheets($joyride);
39
    }
40
41
42
    /**
43
     * Register javascript assets
44
     *
45
     * @param bool $joyride
46
     */
47
    private function registerJavascript($joyride = false)
48
    {
49
        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
50
        // Note: the intention of this script is to only do TARGETED injections.
51
        //ie: only injecting on certain script calls.
52
        $this->addJavascript(
53
            EspressoLegacyAdminAssetManager::JS_HANDLE_INJECT_WP,
54
            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
55
            ['jquery'],
56
            true,
57
            EVENT_ESPRESSO_VERSION
58
        );
59
        // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook,
60
        // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' );
61
        if (! $joyride) {
62
            return;
63
        }
64
        // register cookie script for future dependencies
65
        $this->addJavascript(
66
            EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_COOKIE,
67
            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
68
            ['jquery'],
69
            true,
70
            '2.1'
71
        );
72
        $this->addJavascript(
73
            EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR,
74
            EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
75
            [],
76
            true,
77
            '2.1'
78
        );
79
        // wanna go for a joyride?
80
        $this->addJavascript(
81
            EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE,
82
            EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
83
            [
84
                EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_COOKIE,
85
                EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR
86
            ],
87
            '2.1',
88
            true
89
        )->enqueueAsset();
90
        $this->loadQtipJs();
91
    }
92
93
94
    /**
95
     * Register CSS assets.
96
     *
97
     * @param bool $joyride
98
     */
99
    private function registerStyleSheets($joyride = false)
100
    {
101
        if (! $joyride) {
102
            return;
103
        }       // joyride style
104
        $this->addStylesheet(
105
            EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE,
106
            EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css',
107
            [],
108
            'all',
109
            '2.1'
110
        );
111
        $this->addStylesheet(
112
            EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE,
113
            EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
114
            ['joyride-css'],
115
            'all',
116
            EVENT_ESPRESSO_VERSION
117
        )->enqueueAsset();
118
    }
119
120
121
    /**
122
     * registers assets for cleaning your ears
123
     */
124
    public function loadQtipJs()
125
    {
126
        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
127
        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
128
        if (apply_filters('FHEE_load_qtip', false)) {
129
            $qtip_loader = EEH_Qtip_Loader::instance();
130
            if ($qtip_loader instanceof EEH_Qtip_Loader) {
131
                $qtip_loader->register_and_enqueue();
132
            }
133
        }
134
    }
135
}
136