Skip to content

Commit 9ea7e8e

Browse files
yaustarSteven Yauwilleastcott
authored
Added view source button to the examples page (playcanvas#2035)
* Added view source button to the examples page * Fixed docs build command in readme * Move examples styling to SCSS * Added generated CSS and map to examples page * Update README.md Co-authored-by: Steven Yau <syau@snaphcat.com> Co-authored-by: Will Eastcott <will@playcanvas.com>
1 parent 06d0cd4 commit 9ea7e8e

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Now you can run various build options:
122122
| `npm run build:prf` | Build unminified profiler engine | `build\output\playcanvas.prf.js` |
123123
| `npm run build:dbg` | Build unminified debug engine | `build\output\playcanvas.dbg.js` |
124124
| `npm run tsd` | Build engine Typescript bindings | `build\output\playcanvas.d.ts` |
125-
| `npm run doc` | Build engine [API reference docs](https://developer.playcanvas.com/en/api/) | `docs` |
125+
| `npm run docs` | Build engine [API reference docs](https://developer.playcanvas.com/en/api/) | `docs` |
126126

127127
Pre-built versions of the engine are also available.
128128

examples/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414
<div class="sidenav closed"></div>
1515
<iframe id="example"></iframe>
1616

17+
<div class="sourcenav">
18+
<div class="btn">View Source</div>
19+
</div>
20+
1721
<script src="examples.js"></script>
1822
<script>
23+
let currentExampleRelativeUrl;
24+
1925
function titleCase(string) {
2026
let sentence = string.toLowerCase().split('-');
2127
for(let i = 0; i < sentence.length; i++){
@@ -32,6 +38,8 @@
3238
location.pathname +
3339
'#' +
3440
example;
41+
42+
currentExampleRelativeUrl = example;
3543
}
3644

3745
// Load the initial example (loading the first one if none is specified)
@@ -75,6 +83,11 @@
7583
navigationToggle.addEventListener("click", function (event){
7684
sidenav.classList.toggle("closed");
7785
})
86+
87+
let sourceButton = document.querySelector(".sourcenav > .btn");
88+
sourceButton.addEventListener("click", function (event){
89+
window.open("https://github.com/playcanvas/playcanvas.github.io/blob/master/" + currentExampleRelativeUrl);
90+
})
7891
</script>
7992
</body>
8093
</html>

examples/style.css

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/style.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/style.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ p {
102102
color: $text-primary;
103103
}
104104

105+
/* Go to GitHub source button area */
106+
.sourcenav {
107+
position: fixed;
108+
right: 24px;
109+
bottom: 24px;
110+
}
111+
112+
.sourcenav .btn {
113+
padding: 15px;
114+
background-color: $text-active;
115+
color: $text-primary;
116+
cursor: pointer;
117+
}
118+
105119
#example,
106120
iframe {
107121
position: fixed;

0 commit comments

Comments
 (0)