add capabilities.js and degrade gracefully on ajax caching

This commit is contained in:
Chris Van 2011-10-17 14:06:22 -07:00
Родитель 7bce8637c7
Коммит 7ba202edeb
7 изменённых файлов: 28 добавлений и 23 удалений

Просмотреть файл

@ -31,7 +31,7 @@ $.ajaxCache = function(o) {
ajaxFailure: $.noop, // Callback upon failure of Ajax request.
}, o);
if (parseFloat(jQuery.fn.jquery) < 1.5) {
if (!z.capabilities.JSON || parseFloat(jQuery.fn.jquery) < 1.5) {
// jqXHR objects allow Deferred methods as of jQuery 1.5. Some of our
// old pages are stuck on jQuery 1.4, so hopefully this'll disappear
// sooner than later.
@ -51,11 +51,11 @@ $.ajaxCache = function(o) {
var cache = z.AjaxCache(o.url + ':' + o.type),
args = JSON.stringify(o.data),
$self = this,
previous_args = JSON.stringify(cache.previous.args),
items,
request;
if (args != JSON.stringify(cache.previous.args)) {
if (args != previous_args) {
if (!!cache.items[args]) {
items = cache.items[args];
if (o.newItems) {

Просмотреть файл

@ -0,0 +1,16 @@
z.capabilities = {
'JSON': window.JSON && typeof JSON.parse == 'function',
'debug': (('' + document.location).indexOf('dbg') >= 0),
'debug_in_page': (('' + document.location).indexOf('dbginpage') >= 0),
'console': window.console && (typeof window.console.log == 'function'),
'replaceState': typeof history.replaceState === 'function',
'localStorage': false
};
try {
if ('localStorage' in window && window['localStorage'] !== null) {
z.capabilities.localStorage = true;
}
} catch (e) {
}

Просмотреть файл

@ -147,7 +147,7 @@ function initReviewActions() {
setTimeout(check_currently_viewing, d.interval_seconds * 1000);
});
}
if(!(('localStorage' in window) && window.localStorage['dont_poll'])) {
if (!(z.capabilities.localStorage && window.localStorage['dont_poll'])) {
check_currently_viewing();
}

Просмотреть файл

@ -1,9 +1,9 @@
function dbg() {
if (capabilities.debug) {
if(capabilities.console && !capabilities.debug_in_page) {
if (z.capabilities.debug) {
if (z.capabilities.console && !z.capabilities.debug_in_page) {
window.console.log(Array.prototype.slice.apply(arguments));
}
if (capabilities.debug_in_page) {
if (z.capabilities.debug_in_page) {
var args = Array.prototype.slice.apply(arguments);
$("#dbgout").append(args.join("\t"));
$("#dbgout").append("\n");
@ -111,7 +111,7 @@ function update_page_state() {
var seriesURL = AMO.getStatsBaseURL() + ([AMO.getReportName(),"day",Highcharts.dateFormat('%Y%m%d', start),Highcharts.dateFormat('%Y%m%d', end)]).join("-") + ".csv";
$('#export_data').attr('href', seriesURL);
if (capabilities.replaceState) {
if (z.capabilities.replaceState) {
history.replaceState(page_state, document.title, '?' + queryparams);
} else {
page_state.last_hash = '#' + queryparams;

Просмотреть файл

@ -13,13 +13,6 @@
};
var pending_fetches = 0;
var page_state = {};
var capabilities = {
'JSON' : window.JSON && typeof JSON.parse == 'function',
'debug' : (('' + document.location).indexOf("dbg") >= 0),
'debug_in_page' : (('' + document.location).indexOf("dbginpage") >= 0),
'console' : window.console && (typeof window.console.log == 'function'),
'replaceState' : typeof history.replaceState === "function"
};
var writeInterval = false;
@ -324,7 +317,7 @@
var ds = datastore[metric], data;
// process the Data. We want to directly use the native JSON
// without jQuery's costly regexes if we can.
if (capabilities.JSON) {
if (z.capabilities.JSON) {
dbg("native JSON");
data = JSON.parse(raw_data);
} else {

Просмотреть файл

@ -28,13 +28,7 @@ z.Storage = (function() {
return $.cookie(key, null);
}
};
var engine = cookieStorage;
try {
if ('localStorage' in window && window['localStorage'] !== null) {
engine = window.localStorage;
}
} catch (e) {
}
var engine = z.capabilities.localStorage ? localStorage : cookieStorage;
return function(namespace) {
namespace = namespace ? namespace + '-' : '';
return {

Просмотреть файл

@ -528,6 +528,7 @@ MINIFY_BUNDLES = {
'js/zamboni/browser.js',
'js/amo2009/addons.js',
'js/zamboni/init.js',
'js/impala/capabilities.js',
'js/zamboni/format.js',
'js/lib/jquery.cookie.js',
'js/zamboni/storage.js',
@ -597,6 +598,7 @@ MINIFY_BUNDLES = {
'js/zamboni/browser.js',
'js/amo2009/addons.js',
'js/zamboni/init.js',
'js/impala/capabilities.js',
'js/zamboni/format.js',
'js/lib/jquery.cookie.js',
'js/zamboni/storage.js',