Project URL: Glitch :・゚✧
Alright so imagine you’ve made a neat webpage template with a bunch of different places people can edit the HTML to put their own information.
The first step for the person remixing it is to cross reference where in the code is the markup that goes with which parts of the page. And that can be pretty tricky with the wild layouts that you can make in CSS these days.
Here’s an idea for how to speed that up (doesn’t work though). Take a look at this sample code:
<h2>
Using this project
<script>editLink();</script>
</h2>
The editLink
function here does the following:
- If our page isn’t embedded in the Glitch editor, exit right away.
- Pretend there was a JS error.
- Look at the error’s stack to see where
editLink()
was called. That’ll be something like this:Error at editLink (https://lavish-lace-axolotl.glitch.me/edit.js:52:13) at https://lavish-lace-axolotl.glitch.me/:71:21
- Extract the Glitch project name, path, and line+column location. For example:
lavish-lace-axolotl
,index.html
, line 71, column 21. - Come up with a Glitch editor URL that goes there:
https://glitch.com/edit/#!/lavish-lace-axolotl?path=index.html%3A71%3A13
(actually a few characters before it so that we’re actually in the part to edit and not the script tag). - Put a link to that URL right there where the script is. The link has
target="_parent"
so that it navigates the editor instead of opening another copy of the editor inside the preview panel.
You can put these <script>editLink();</script>
all over your template. When people view the webpage by itself, it’ll look normal, as if nothing were there. When you open it in the editor preview, you get a bunch of links, and clicking on one will move your editor cursor right to where you can edit that part of the page:
Except no, it doesn’t. The Glitch editor doesn’t actually respond to hash changes. This was all pointless.