Skip to content

Commit 3fd0c04

Browse files
committed
jqueryui.com: Handle new demo directory structure for effects.
1 parent 20e8b6f commit 3fd0c04

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

mu-plugins/jqueryui.com/jquery-filters.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,36 @@
44
global $post;
55

66
$demoContent = '';
7-
$demoPos = strpos( $content, '<!--demos-->');
8-
if ( $demoPos === false ) {
7+
if ( !preg_match( '/<!--demos\(?(.*?)?\)?-->/', $content, $matches ) ) {
98
return $content;
109
}
1110

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+
}
1321
$demoList = json_decode( file_get_contents( GW_RESOURCE_DIR . '/demos/demo-list.json' ) );
1422
$demos = $demoList->$plugin;
15-
$defaultDemo = $demos[ 0 ];
1623

1724
$demoContent .=
18-
'<div class="demo-list">' .
25+
'<div class="demo-list"' . ( $isStandard ? '' : ' data-full-nav="true"' ) . '>' .
1926
'<h2>Examples</h2>' .
2027
'<ul>';
2128
foreach ( $demoList->$plugin as $demo ) {
2229
$filename = $demo->filename;
30+
if ( $filename === $active ) {
31+
$demoContent .= '<li class="active">';
32+
$demoDescription = $demo->description;
33+
} else {
34+
$demoContent .= '<li>';
35+
}
2336
$demoContent .=
24-
($filename === 'default' ? '<li class="active">' : '<li>') .
2537
'<a href="/resources/demos/' . $plugin . '/' . $filename . '.html">' .
2638
$demo->title .
2739
'</a>' .
@@ -31,18 +43,18 @@
3143
'</ul>' .
3244
'</div>';
3345

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>';
3648

3749
$demoContent .=
3850
'<div class="view-source">' .
3951
'<a tabindex="0"><i class="icon-eye-open"></i> view source</a>' .
4052
'<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' ) .
4254
'</div>' .
4355
'</div>';
4456

45-
return str_replace( '<!--demos-->', $demoContent, $content );
57+
return $content[ 0 ] . $demoContent . $content[ 1 ];
4658
} );
4759

4860
?>

themes/jquery/js/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ $(function() {
355355
plugin = parts[ 3 ],
356356
demo = parts[ 4 ].substring( 0, parts[ 4 ].length - 5 );
357357

358+
if ( demoList.is( "[data-full-nav]" ) ) {
359+
window.location = "/" + demo;
360+
return;
361+
}
362+
358363
$.getJSON( "/resources/demos/demo-list.json" ).then(function( demoList ) {
359364
demoDescription.html( $.grep( demoList[ plugin ], function( x ) {
360365
return x.filename === demo;

0 commit comments

Comments
 (0)