-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
103 lines (75 loc) · 2.31 KB
/
index.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
<?php
/**
* Embed - oEmbed
*/
namespace tangible\template_system\embed;
use tangible\template_system;
function register() {
$url = template_system::$state->url . '/modules/embed';
$version = template_system::$state->version;
wp_register_script(
'tangible-embed-dynamic',
"{$url}/build/embed.min.js",
[ 'jquery' ],
$version,
true
);
wp_register_style(
'tangible-embed',
"{$url}/build/embed.min.css",
[],
$version,
);
}
function enqueue() {
// wp_enqueue_script('tangible-embed-dynamic');
wp_enqueue_style('tangible-embed');
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\register', 0 );
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\register', 0 );
$html->add_open_tag('Embed', function( $atts, $nodes ) use ( $html ) {
$content = $html->format_embed(
$html->render( $nodes )
);
if ( isset( $atts['ratio'] ) ) {
$atts['responsive'] = $atts['ratio'];
unset( $atts['ratio'] );
} elseif ( ! isset( $atts['responsive'] ) || array_search( 'responsive', $atts['keys'] ) !== false ) {
$atts['responsive'] = strpos( $content, '<iframe ' ) !== false
? 'dynamic'
: 'false';
}
if ($atts['responsive'] === 'false') return $content;
unset( $atts['keys'] );
$is_dynamic = false;
wp_enqueue_style('tangible-embed');
$ratio = $atts['responsive'];
unset( $atts['responsive'] );
if ( $ratio === 'dynamic' ) {
// JS required for dynamic ratio
wp_enqueue_script('tangible-embed-dynamic');
$is_dynamic = true;
} elseif ( $ratio !== 'default' ) {
// Ratio given as width:height, such as 16:9
$parts = explode( ':', $ratio );
if ( count( $parts ) === 2 ) {
$width = $parts[0];
$height = $parts[1];
$ratio = "$width / $height";
} else {
$ratio = "100 / $ratio";
}
$atts['style'] =
( isset( $atts['style'] ) ? ( $atts['style'] . ';' ) : '' )
. 'aspect-ratio:' . $ratio;
}
return $html->render_tag('div', array_merge($atts, [
'class' => ( $is_dynamic
? 'tangible-embed-dynamic tangible-dynamic-module' // Dynamic aspect ratio requires JS
: 'tangible-embed' // CSS-only solution
)
. ( isset( $atts['class'] ) ? ' ' . $atts['class'] : '' )
,
'data-tangible-dynamic-module' => 'embed-dynamic',
]), $content);
});