Skip to content

Commit af114ab

Browse files
Remix dropdown: add styles even if running inside a remix preview (#5843)
* Add styles even if running inside a remix preview, so the Open Sandbox button for CodeSandbox is correctly repositioned * Use preview param for Krabbel to specify which file to open in editor and preview
1 parent 5fb2d2a commit af114ab

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

examples/js/remix-dropdown.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,26 @@
6363
}
6464

6565
function init () {
66+
addStyles();
67+
6668
// Don't show the button when the example is already running inside a remix
6769
// service preview (CodeSandbox *.csb.app, Krabbel *.krabbel.fun).
6870
if (/\.(csb\.app|krabbel\.fun)$/.test(window.location.hostname)) { return; }
6971

7072
var loc = getExampleLocation();
7173
if (!loc) { return; }
7274

73-
// Point at the directory, adding a file parameter for non-index.html pages
74-
// so the specific example file is opened. The leading slash is URL-encoded
75-
// (CodeSandbox expects %2F).
76-
var fileParam = (loc.file && loc.file !== 'index.html') ? '?file=' + encodeURIComponent('/' + loc.file) : '';
77-
var treePath = 'tree/gh-pages/examples/' + loc.dir + fileParam;
78-
var codesandboxUrl = 'https://codesandbox.io/p/sandbox/github/aframevr/aframe/' + treePath;
79-
var krabbelUrl = 'https://krabbel.dev/github/aframevr/aframe/' + treePath;
80-
81-
addStyles();
75+
// Point at the directory, adding a parameter for non-index.html pages so the
76+
// specific example file is opened. CodeSandbox uses a file parameter (with a
77+
// leading slash, URL-encoded as %2F); Krabbel supports file and preview parameters
78+
// (leading slash optional, if preview parameter specified and file parameter not
79+
// specified, it will open the same file in both editor and preview).
80+
var treePath = 'tree/gh-pages/examples/' + loc.dir;
81+
var isFile = loc.file && loc.file !== 'index.html';
82+
var fileParam = isFile ? '?file=' + encodeURIComponent('/' + loc.file) : '';
83+
var previewParam = isFile ? '?preview=' + encodeURIComponent(loc.file) : '';
84+
var codesandboxUrl = 'https://codesandbox.io/p/sandbox/github/aframevr/aframe/' + treePath + fileParam;
85+
var krabbelUrl = 'https://krabbel.dev/github/aframevr/aframe/' + treePath + previewParam;
8286

8387
var menu = document.createElement('div');
8488
menu.classList.add('a-remix-menu');

0 commit comments

Comments
 (0)