index.php
1.9 KB
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
<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'stackable_load_accordion_frontend_script' ) ) {
function stackable_load_accordion_frontend_script() {
if ( ! is_admin() ) {
wp_enqueue_script(
'stk-frontend-accordion',
plugins_url( 'dist/frontend_block_accordion.js', STACKABLE_FILE ),
array(),
STACKABLE_VERSION,
true
);
}
}
add_action( 'stackable/accordion/enqueue_scripts', 'stackable_load_accordion_frontend_script' );
}
if ( ! function_exists( 'stackable_load_accordion_frontend_polyfill_script' ) ) {
/**
* Adds polyfill for summary/details element that are * used in accordion blocks.
*
* TODO: confirm that this works on older browsers
*/
function stackable_load_accordion_frontend_polyfill_script() {
$user_agent = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
if ( ! $user_agent ) {
return;
}
$load_polyfill = false;
if (
// Safari 13.1.3
( stripos( $user_agent, 'Version/13.' ) !== false && stripos( $user_agent, 'Safari/' ) !== false ) ||
// Adnroid 7.0 Samsung Galaxy J5
( stripos( $user_agent, 'Android 7.' ) !== false && stripos( $user_agent, 'Chrome/' ) !== false ) ||
// IE 11
stripos( $user_agent, 'Trident/7.0; rv:11.0' ) !== false
) {
$load_polyfill = true;
} else if ( stripos( $user_agent, ' Edge/' ) !== false || stripos( $user_agent, ' Edg/' ) !== false ) {
$matches = array();
if ( preg_match( '/(Edge?)\/(\d+)/', $user_agent, $matches ) ) {
$version = intval( $matches[2] );
if ( $version < 79 ) {
$load_polyfill = true;
}
}
}
if ( $load_polyfill ) {
wp_enqueue_script(
'stk-frontend-accordion-polyfill',
plugins_url( 'dist/frontend_block_accordion_polyfill.js', STACKABLE_FILE ),
array(),
STACKABLE_VERSION
);
}
}
add_action( 'wp_footer', 'stackable_load_accordion_frontend_polyfill_script' );
}