exploratoria / exploratoria.github.io

An online hommage to the Exploratorium
http://exploratoria.github.io
MIT License
5 stars 0 forks source link

Support relative URLs in readme-reader.js and code-edit-view.html #5

Closed paulmasson closed 9 years ago

paulmasson commented 9 years ago

Currently all URLs in exhibits need to be hard coded as absolute references. It would be expedient for future flexibility to support relative URLs in both readme-reader.js and code-edit-view.html.

theo-armour commented 9 years ago

@paulmasson

Currently all URLs in exhibits need to be hard coded as absolute references.

It might be more accurate to state: Currently all URLs in exhibits need to be hard coded as absolute references - if they are to operate correctly in iframes with readme-reader or code-edit-view as parents.

It would be expedient for future flexibility to support relative URLs in both readme-reader.js and code-edit-view.html.

Agree this would be nice, but it may be difficult to accomplish.

An interim measure might be to make scripts that are intended to be embedded as children in iframes to compensate for being embedded.

I have updated Star Spotter with an example of code that seems to work:

var pathSprites = ( window.self === window.top ) ?  './sprites/' : '../../exhibits/astronomy/star-spotter/sprites/';

https://github.com/exploratoria/exploratoria.github.io/blob/master/exhibits/astronomy/star-spotter/star-spotter.html#L19-21

The should work with both readme-reader abd code-edit-view as thay are both in the same relative URL hierarchy

paulmasson commented 9 years ago

That's an interesting approach, but it requires the coder to be aware of too much structure of the website. I was hoping to make the embedding process as transparent as possible.

One way to do this would be by creating an anchor and using its DOM properties to turn a relative reference into an absolute reference. This absolute reference could then be used to add a tag to the document header before passing the document to the showdown library. Presumably showdown can handle relative references as long as the tag is included.

It does occur to me though that if we have set up the site to allow download of code, then relative URLs could be a bad idea. While it makes some things simpler for us, the downloaded file would reference things that don't exist on the end user's computer. The end user still needs an absolute reference to classes and data for the downloaded page to function.

We should probably just keep absolute references after all. Thoughts?

theo-armour commented 9 years ago

While it makes some things simpler for us, the downloaded file would reference things that don't exist on the end user's computer. The end user still needs an absolute reference to classes and data for the downloaded page to function.

Bingo.

There may well be issues with CORS and some files. But at the least, the user can click on the link and save the data to their disk.

We should probably just keep absolute references after all. Thoughts?

How about a rule that says "absolute references are recommended for items that would otherwise have issues with loading into Code-Edit-View"?

On Sun, Sep 20, 2015 at 3:08 PM, paulmasson notifications@github.com wrote:

That's an interesting approach, but it requires the coder to be aware of too much structure of the website. I was hoping to make the embedding process as transparent as possible.

One way to do this would be by creating an anchor and using its DOM properties to turn a relative reference into an absolute reference. This absolute reference could then be used to add a tag to the document header before passing the document to the showdown library. Presumably showdown can handle relative references as long as the tag is included.

It does occur to me though that if we have set up the site to allow download of code, then relative URLs could be a bad idea. While it makes some things simpler for us, the downloaded file would reference things that don't exist on the end user's computer. The end user still needs an absolute reference to classes and data for the downloaded page to function.

We should probably just keep absolute references after all. Thoughts?

— Reply to this email directly or view it on GitHub https://github.com/exploratoria/exploratoria.github.io/issues/5#issuecomment-141840619 .

paulmasson commented 9 years ago

Sounds like a good idea. Added to notes.md file.

Would you like to revert the changes to Star Spotter or shall I?

theo-armour commented 9 years ago

I'm working on parametric equations for the next few hours. So go ahead

On Sun, Sep 20, 2015 at 4:16 PM, paulmasson notifications@github.com wrote:

Sounds like a good idea. Added to notes.md file.

Would you like to revert the changes to Star Spotter or shall I?

— Reply to this email directly or view it on GitHub https://github.com/exploratoria/exploratoria.github.io/issues/5#issuecomment-141844480 .

paulmasson commented 9 years ago

Will do. Thanks!