Handle all static links through hashchange

Fixes #17
This commit is contained in:
Ray Schamp 2015-05-13 14:02:05 -04:00
parent 9034aa66d0
commit cfc57f3cf5
2 changed files with 16 additions and 14 deletions

View file

@ -10,7 +10,7 @@
<main>
<header>
<div>
<a href="#home" data-action="show"><h1 class="scratchx-logo"><span>ScratchX</span></h1></a>
<a href="#home"><h1 class="scratchx-logo"><span>ScratchX</span></h1></a>
<nav class="main-nav">
Related Sites:
<ul>
@ -24,7 +24,7 @@
<article id="home">
<header>
<div>
<aside class="warning message"><strong>Warning:</strong> These extensions are experimental. <a href="#faq" data-action="show">Please read the FAQ before trying them.</a></aside>
<aside class="warning message"><strong>Warning:</strong> These extensions are experimental. <a href="#faq">Please read the FAQ before trying them.</a></aside>
<h1>About ScratchX</h1>
<p>
@ -36,7 +36,7 @@
<section>
<h2>Open an Extension File</h2>
<p>Choose a .sbx file from your local drive</p>
<p><a href="#faq-sbx-file" data-action="show">What is a .sbx file?</a></p>
<p><a href="#faq-sbx-file">What is a .sbx file?</a></p>
</section>
<section>
<button data-action="load-file">Browse for local file</button>
@ -47,7 +47,7 @@
<section>
<h2>Open an Extension URL</h2>
<p>Paste the web address below</p>
<p><a href="#faq-scratchx-url" data-action="show">What is a ScratchX URL?</a></p>
<p><a href="#faq-scratchx-url">What is a ScratchX URL?</a></p>
</section>
<section>
<form class="input-plus-button url-load-form">
@ -91,14 +91,14 @@
<div>
<h2>Developer Documentation</h2>
<p>Developers can create new Experimental Extensions using Javascript. To learn more, read the <a href="http://llk.github.io/scratch-extension-docs/">Developer Documentation</a>.</p>
<p><a href="#scratch" data-action="show"><button>Open editor</button></a></p>
<p><a href="#scratch"><button>Open editor</button></a></p>
</div>
</section>
</article>
<article id="privacy-policy">
<section>
<div>
<aside class="warning message"><strong>Warning:</strong> These extensions are experimental. <a href="#faq" data-action="show">Please read the FAQ before trying them.</a></aside>
<aside class="warning message"><strong>Warning:</strong> These extensions are experimental. <a href="#faq">Please read the FAQ before trying them.</a></aside>
<div>
<section class="main">
<h1>Privacy Policy</h1>
@ -137,7 +137,7 @@
<article id="faq">
<section>
<div>
<aside class="warning message"><strong>Warning:</strong> These extensions are experimental. <a href="#faq" data-action="show">Please read the FAQ before trying them.</a></aside>
<aside class="warning message"><strong>Warning:</strong> These extensions are experimental. <a href="#faq">Please read the FAQ before trying them.</a></aside>
<div>
<section class="main">
<h1><abbr title="Frequently Asked Questions">FAQ</abbr></h1>
@ -164,7 +164,7 @@
<p>Click the 'Save' button at the top of the page to download your project as an .sbx file on to your local computer. You can then send this file to other people, and they can upload your file onto ScratchX to play with your project.</p>
<h2 id="faq-examples">Where can I find example Experimental Extensions to play around with?</h2>
<p>We have linked to a few example extensions on the <a href="#home" data-action="show">ScratchX</a> homepage. We plan to highlight additional extensions in the coming months.</p>
<p>We have linked to a few example extensions on the <a href="#home">ScratchX</a> homepage. We plan to highlight additional extensions in the coming months.</p>
<h2 id="faq-scratchx-url">What is a ScratchX URL?</h2>
<p>Developers who make extensions for ScratchX can choose to create a custom web address or URL that points to their extension and/or demo project. Clicking on a ScratchX extension URL will take you directly to a project with an extension loaded.</p>
@ -211,9 +211,9 @@
<h2>ScratchX</h2>
<ul>
<li><a href="https://scratch.mit.edu/terms_of_use/">Terms of Service</a></li>
<li><a href="#privacy-policy" data-action="show">Privacy Policy</a></li>
<li><a href="#privacy-policy">Privacy Policy</a></li>
<li><a href="mailto:scratch-extensions@media.mit.edu">Contact Us</a></li>
<li><a href="#faq" data-action="show">FAQ</a></li>
<li><a href="#faq">FAQ</a></li>
<li><a href="https://scratch.mit.edu/discuss/41/">Forums</a></li>
</ul>
</nav>

View file

@ -307,10 +307,6 @@ var showClickListener = function(e) {
showPage(path);
};
$(window).bind('hashchange', function(e) {
if (document.location.hash == '') showPage('home');
});
function showPage(path, force) {
/*
* Show a part of the page. The site is set up like
@ -355,6 +351,7 @@ function showPage(path, force) {
if (showEditor) $toShow.css({top: 0});
if (document.location.hash.substr(1) != path) document.location.hash = path;
$toShow[0].scrollIntoView(true);
}
@ -425,6 +422,11 @@ function attachListeners(){
$(".url-load-form").on('submit', loadURLformListener);
$("[data-action='show']").on('click', showClickListener);
}
$(window).on('hashchange', function(e) {
var path = document.location.hash.split('#')[1] || document.location.hash || 'home';
showPage(path);
});
function initPage() {
/*