|
4 | 4 | global $post;
|
5 | 5 |
|
6 | 6 | $demoContent = '';
|
7 |
| - $demoPos = strpos( $content, '<!--demos-->'); |
8 |
| - if ( $demoPos === false ) { |
| 7 | + if ( !preg_match( '/<!--demos\(?(.*?)?\)?-->/', $content, $matches ) ) { |
9 | 8 | return $content;
|
10 | 9 | }
|
11 | 10 |
|
12 |
| - $plugin = $post->post_name; |
| 11 | + $content = explode( $matches[ 0 ], $content, 2 ); |
| 12 | + $isStandard = empty( $matches[ 1 ] ); |
| 13 | + |
| 14 | + if ( $isStandard ) { |
| 15 | + $plugin = $post->post_name; |
| 16 | + $active = 'default'; |
| 17 | + } else { |
| 18 | + $plugin = $matches[ 1 ]; |
| 19 | + $active = $post->post_name; |
| 20 | + } |
13 | 21 | $demoList = json_decode( file_get_contents( GW_RESOURCE_DIR . '/demos/demo-list.json' ) );
|
14 | 22 | $demos = $demoList->$plugin;
|
15 |
| - $defaultDemo = $demos[ 0 ]; |
16 | 23 |
|
17 | 24 | $demoContent .=
|
18 |
| - '<div class="demo-list">' . |
| 25 | + '<div class="demo-list"' . ( $isStandard ? '' : ' data-full-nav="true"' ) . '>' . |
19 | 26 | '<h2>Examples</h2>' .
|
20 | 27 | '<ul>';
|
21 | 28 | foreach ( $demoList->$plugin as $demo ) {
|
22 | 29 | $filename = $demo->filename;
|
| 30 | + if ( $filename === $active ) { |
| 31 | + $demoContent .= '<li class="active">'; |
| 32 | + $demoDescription = $demo->description; |
| 33 | + } else { |
| 34 | + $demoContent .= '<li>'; |
| 35 | + } |
23 | 36 | $demoContent .=
|
24 |
| - ($filename === 'default' ? '<li class="active">' : '<li>') . |
25 | 37 | '<a href="/resources/demos/' . $plugin . '/' . $filename . '.html">' .
|
26 | 38 | $demo->title .
|
27 | 39 | '</a>' .
|
|
31 | 43 | '</ul>' .
|
32 | 44 | '</div>';
|
33 | 45 |
|
34 |
| - $demoContent .= '<iframe src="/resources/demos/' . $plugin . '/default.html" class="demo-frame"></iframe>'; |
35 |
| - $demoContent .= '<div class="demo-description">' . $defaultDemo->description . '</div>'; |
| 46 | + $demoContent .= '<iframe src="/resources/demos/' . $plugin . '/' . $active . '.html" class="demo-frame"></iframe>'; |
| 47 | + $demoContent .= '<div class="demo-description">' . $demoDescription . '</div>'; |
36 | 48 |
|
37 | 49 | $demoContent .=
|
38 | 50 | '<div class="view-source">' .
|
39 | 51 | '<a tabindex="0"><i class="icon-eye-open"></i> view source</a>' .
|
40 | 52 | '<div>' .
|
41 |
| - file_get_contents( GW_RESOURCE_DIR . '/demos-highlight/' . $plugin . '/default.html' ) . |
| 53 | + file_get_contents( GW_RESOURCE_DIR . '/demos-highlight/' . $plugin . '/' . $active . '.html' ) . |
42 | 54 | '</div>' .
|
43 | 55 | '</div>';
|
44 | 56 |
|
45 |
| - return str_replace( '<!--demos-->', $demoContent, $content ); |
| 57 | + return $content[ 0 ] . $demoContent . $content[ 1 ]; |
46 | 58 | } );
|
47 | 59 |
|
48 | 60 | ?>
|
0 commit comments