Browse Source

Added "view source" button to examples viewer.

Mr.doob 12 years ago
parent
commit
851dddee6f
1 changed files with 35 additions and 4 deletions
  1. 35 4
      examples/index.html

+ 35 - 4
examples/index.html

@@ -85,6 +85,21 @@
 
 
 			}
 			}
 
 
+			#button {
+				position: fixed;
+				top: 20px;
+				right: 20px;
+				padding: 8px;
+				color: #fff;
+				background-color: #555;
+				opacity: 0.7;
+			}
+
+				#button:hover {
+					cursor: pointer;
+					opacity: 1;
+				}
+
 		</style>
 		</style>
 	</head>
 	</head>
 	<body>
 	<body>
@@ -326,8 +341,22 @@
 		var container = document.createElement( 'div' );
 		var container = document.createElement( 'div' );
 		list.appendChild( container );
 		list.appendChild( container );
 
 
+		var button = document.createElement( 'div' );
+		button.id = 'button';
+		button.textContent = 'View source';
+		button.addEventListener( 'click', function ( event ) {
+
+			var array = location.href.split( '/' );
+			array.pop();
+
+			window.open( 'view-source:' + array.join( '/' ) + '/' + selected + '.html' );
+
+		}, false );
+		button.style.display = 'none';
+		document.body.appendChild( button );
+
 		var divs = {};
 		var divs = {};
-		var SELECTED = null;
+		var selected = null;
 
 
 		for ( var key in files ) {
 		for ( var key in files ) {
 
 
@@ -365,15 +394,17 @@
 
 
 		var load = function ( file ) {
 		var load = function ( file ) {
 
 
-			if ( SELECTED !== null ) SELECTED.className = 'link';
+			if ( selected !== null ) divs[ selected ].className = 'link';
 
 
-			SELECTED = divs[ file ];
-			SELECTED.className = 'link selected';
+			selected = file;
+			divs[ selected ].className = 'link selected';
 
 
 			window.location.hash = file;
 			window.location.hash = file;
 			viewer.src = file + '.html';
 			viewer.src = file + '.html';
 			viewer.focus();
 			viewer.focus();
 
 
+			button.style.display = '';
+
 		};
 		};
 
 
 		if ( window.location.hash !== '' ) {
 		if ( window.location.hash !== '' ) {