Skip to content

Commit f6df41e

Browse files
author
Gabriel Schulhof
committed
Demos: View source: Correct misconception that different types of sources are added iteratively
1 parent 320697b commit f6df41e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

docs/demos/_assets/js/view-source.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ $.fn.viewSourceCode = function() {
4141
"</div>" ),
4242
self = $( this ),
4343
page = self.closest( "[data-role='page']" ),
44-
data, source,
44+
fixData = function( data ) {
45+
return data.replace( /\s+$/gm, "" );
46+
},
47+
data,
4548
sources = [];
4649

4750
// Collect source code before it becomes enhanced
@@ -52,7 +55,7 @@ $.fn.viewSourceCode = function() {
5255
} else {
5356
data = $( "<div></div>" ).append( $( self.attr( "data-demo-html" ) ).clone() ).html();
5457
}
55-
source = { title: "HTML", theme: "b", brush: "xml" };
58+
sources.push( { title: "HTML", theme: "b", brush: "xml", data: fixData( data ) } );
5659
}
5760

5861
if ( self.is( "[data-demo-php]" ) ) {
@@ -64,22 +67,17 @@ $.fn.viewSourceCode = function() {
6467
data = "// Failed to retrieve PHP source code";
6568
});
6669

67-
source = { title: "PHP", theme: "g", brush: "php" };
70+
sources.push( { title: "PHP", theme: "g", brush: "php", data: fixData( data ) } );
6871
}
6972

7073
if ( self.is( "[data-demo-js]" ) ) {
7174
data = getHeadSnippet( "script", self.attr( "data-demo-js" ) );
72-
source = { title: "JS", theme: "f", brush: "js" };
75+
sources.push( { title: "JS", theme: "f", brush: "js", data: fixData( data ) } );
7376
}
7477

7578
if ( self.is( "[data-demo-css]" ) ) {
7679
data = getHeadSnippet( "style", self.attr( "data-demo-css" ) );
77-
source = { title: "CSS", theme: "e", brush: "css" };
78-
}
79-
80-
if ( data && source ) {
81-
source.data = data.replace( /\s+$/gm, "" );
82-
sources.push( source );
80+
sources.push( { title: "CSS", theme: "e", brush: "css", data: fixData( data ) } );
8381
}
8482

8583
attachPopupHandler( popup, sources );

0 commit comments

Comments
 (0)