forked from TangibleInc/template-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
59 lines (49 loc) · 1.46 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
<?php
/**
* Mermaid - Diagram library
*
* @see http://mermaid-js.github.io/mermaid/
* @see https://github.com/mermaid-js/mermaid
*/
namespace tangible\template_system\mermaid;
use tangible\template_system;
function register() {
$url = template_system::$state->url . '/modules/mermaid';
$version = template_system::$state->version;
wp_register_script(
'tangible-mermaid',
"{$url}/build/mermaid.min.js",
[ 'jquery' ],
$version,
true
);
}
function enqueue() {
wp_enqueue_script('tangible-mermaid');
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\register', 0 );
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\register', 0 );
$html->add_raw_tag('Mermaid', function($atts, $content) use ($html) {
wp_enqueue_script('tangible-mermaid');
return $html->render_raw_tag(
'div',
[
'class' => 'tangible-mermaid tangible-dynamic-module',
'data-tangible-dynamic-module' => 'mermaid',
'style' => 'display: none'
]+$atts,
$html->render_raw_tag('code', [], trim($content))
);
});
function register_mermaid_script() {
$url = untrailingslashit(plugins_url('/', __FILE__)) . '/build';
$version = template_system::$state->version;
wp_register_script(
'tangible-mermaid',
"{$url}/mermaid.min.js",
[],
$version
);
};
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\register_mermaid_script', 0 );
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\register_mermaid_script', 0 );