@@ -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