Comparing version 0.0.5 to 0.0.6
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "d6.js", | ||
@@ -31,3 +31,3 @@ "homepage": "http://lighter.io/d6", | ||
"dependencies": { | ||
"jymin": "0.2.0" | ||
"jymin": "0.2.2" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
@@ -22,3 +22,3 @@ /** | ||
var cache = {}; | ||
var cache = d6._CACHE = {}; | ||
@@ -38,8 +38,6 @@ var isReady = false; | ||
on(body, 'a', 'click', function (a, event) { | ||
var url = a.href; | ||
var which = event.which; | ||
if (isSameDomain(url) && (!which || which == 1)) { | ||
//+env:debug | ||
log('Loading URL: "' + url + '"'); | ||
//-env:debug | ||
var url = removeHash(a.href); | ||
var buttonNumber = event.which; | ||
var isLeftClick = (!buttonNumber || (buttonNumber == 1)); | ||
if (isSameDomain(url) && isLeftClick) { | ||
preventDefault(event); | ||
@@ -55,4 +53,5 @@ pushHistory(url); | ||
if (!hasClass(a, '_NOPREFETCH')) { | ||
var url = a.href; | ||
if (isSameDomain(url)) { | ||
var url = removeHash(a.href); | ||
var isDifferentPage = (url != removeHash(location)); | ||
if (isDifferentPage && isSameDomain(url)) { | ||
prefetchUrl(url); | ||
@@ -77,2 +76,6 @@ } | ||
var removeHash = function (url) { | ||
return ensureString(url).replace(/#.*$/, ''); | ||
}; | ||
var prefetchUrl = function (url) { | ||
@@ -102,2 +105,5 @@ // Only proceed if it's not already prefetched. | ||
var loadUrl = d6._LOAD = function (url, callback) { | ||
//+env:debug | ||
log('Loading URL: "' + url + '"'); | ||
//-env:debug | ||
@@ -123,3 +129,2 @@ // Set all spinners in the page to their loading state. | ||
else { | ||
resource.request.url = url; | ||
renderResponse(resource); | ||
@@ -137,9 +142,9 @@ } | ||
// When data is received, execute all callbacks that have been waiting. | ||
// When data is received, cache the response and execute callbacks. | ||
var onComplete = function (response) { | ||
forEach(cache[url], function (callback) { | ||
var queue = cache[url]; | ||
cache[url] = response; | ||
forEach(queue, function (callback) { | ||
callback(response); | ||
}); | ||
// Once everything's been executed, remove the queue. | ||
delete cache[url]; | ||
}; | ||
@@ -154,5 +159,10 @@ | ||
var err = context._ERROR; | ||
var view = views[context.view]; | ||
var view = views[context._STATUS ? context.view : 'error0']; | ||
var url = context.request.url.replace(/[&\?]d6=on/, ''); | ||
var html; | ||
//+env:debug | ||
log('Rendering "' + url + '" response:', context); | ||
//-env:debug | ||
// Reset any spinners. | ||
@@ -163,8 +173,8 @@ all('._SPINNER', function (spinner) { | ||
// If there's an error, render the error text. | ||
if (err) { | ||
// If we got bad JSON, try rendering it as HTML. | ||
if (err == '_BAD_JSON') { | ||
html = context._TEXT; | ||
//+env:dev | ||
error(err + ': "' + html + '"'); | ||
//-env:dev | ||
//+env:debug | ||
error(err + ': "' + html + '"'); | ||
//-env:debug | ||
writeHtml(html); | ||
@@ -181,7 +191,12 @@ } | ||
else { | ||
//+env:dev | ||
error('View not found: "' + context.view + '"'); | ||
//-env:dev | ||
window.location = context.request.url; | ||
//+env:debug | ||
error('View not found: "' + context.view + '"'); | ||
//-env:debug | ||
// TODO: Restore the hash from the request URL. | ||
window.location = url; | ||
} | ||
// If we render this page again, we'll want a fresh context. | ||
delete cache[url]; | ||
}; | ||
@@ -210,3 +225,3 @@ | ||
onReady(); | ||
} | ||
}; | ||
@@ -213,0 +228,0 @@ var cacheBust; |
11696
270
6
+ Addedjymin@0.2.2(transitive)
- Removedjymin@0.2.0(transitive)
Updatedjymin@0.2.2