Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit ce82bad

Browse files
committed
adding support to open code view & auto-select code based on query string vars
1 parent cd45827 commit ce82bad

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

public/styleguide/js/code-viewer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var codeViewer = {
1616
css: "",
1717
ids: { "e": "#sg-code-title-html", "m": "#sg-code-title-mustache", "c": "#sg-code-title-css" },
1818
targetOrigin: (window.location.protocol === "file:") ? "*" : window.location.protocol+"//"+window.location.host,
19+
copyOnInit: false,
1920

2021
/**
2122
* add the onclick handler to the code link in the main nav
@@ -45,6 +46,13 @@ var codeViewer = {
4546
// initialize the code viewer
4647
codeViewer.codeContainerInit();
4748

49+
// load the query strings in case code view has to show by default
50+
var queryStringVars = urlHandler.getRequestVars();
51+
if ((queryStringVars.view !== undefined) && (queryStringVars.view === "code")) {
52+
codeViewer.copyOnInit = ((queryStringVars.copy !== undefined) && (queryStringVars.copy === "true")) ? true : false;
53+
codeViewer.openCode();
54+
}
55+
4856
},
4957

5058
/**
@@ -221,6 +229,10 @@ var codeViewer = {
221229
$("#sg-code-fill").removeClass().addClass("language-"+className);
222230
$("#sg-code-fill").html(code).text();
223231
Prism.highlightElement(document.getElementById("sg-code-fill"));
232+
if (codeViewer.copyOnInit) {
233+
codeViewer.selectCode();
234+
codeViewer.copyOnInit = false;
235+
}
224236
},
225237

226238
/**

0 commit comments

Comments
 (0)