From 1ed980150cfbef085c96a1edc1a2b0fb74f04fc4 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Mon, 28 Nov 2011 01:27:41 -0500 Subject: [PATCH] Fix annoying chrome dual-load bug --- TODO.md | 1 - static/index.html | 26 +++++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/TODO.md b/TODO.md index d93c6bc..9d3e491 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ # TODO for OSS * tests -* fix that chrome bug where it loads the doc twice * Add file extensions ourselves to push state * add feedback for errors to UI - esp. too long * make sure file store still functions appropriately diff --git a/static/index.html b/static/index.html index d4fa224..38b62e2 100644 --- a/static/index.html +++ b/static/index.html @@ -19,22 +19,18 @@ // Handle pops var handlePop = function(evt) { var path = evt.target.location.pathname; - if (path === '/') { - app.newDocument(true); - } - else { - app.loadDocument(path.substring(1, path.length)); - } + if (path === '/') { app.newDocument(true); } + else { app.loadDocument(path.substring(1, path.length)); } }; - // If pop before loading jquery, delay load - window.onpopstate = function(evt) { - try { - handlePop(evt); - } catch(err) { - // not loaded yet - } - }; - // Construct app and load if not loaded + // Set up the pop state to handle loads, skipping the first load + // to make chrome behave like others: + // http://code.google.com/p/chromium/issues/detail?id=63040 + setTimeout(function() { + window.onpopstate = function(evt) { + try { handlePop(evt); } catch(err) { /* not loaded yet */ } + }; + }, 1000); + // Construct app and load initial path $(function() { app = new haste('hastebin', { twitter: true }); handlePop({ target: window });