Skip to content

Instantly share code, notes, and snippets.

@rainhead
Created February 25, 2011 20:03
Show Gist options
  • Save rainhead/844403 to your computer and use it in GitHub Desktop.
Save rainhead/844403 to your computer and use it in GitHub Desktop.
<%- if SiteConfig['patch_mootools_framework'] -%>
if (window.JSON && !(JSON.parse && JSON.stringify) && QUORUS.JSON) {
JSON.parse = QUORUS.JSON.parse;
JSON.stringify = QUORUS.JSON.stringify;
}
delete Number.prototype.toJSON;
delete String.prototype.toJSON;
delete Array.prototype.toJSON;
<%- end -%>
<%- if SiteConfig['patch_prototype_framework'] -%>
if (window.Prototype && window.JSON && window.JSON.stringify) {
(function() {
var version = Prototype.Version.match(/^(\d+)\.(\d+)/);
if ((version[1] > 1) || ((version[1] == 1) && (version[2] > 6))) return;
Date.prototype.toJSON = function(key) {
function f(n) {
return n < 10 ? '0' + n : n;
}
return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z' : null;
};
String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function(key) {
return this.valueOf();
};
delete Array.prototype.toJSON;
Hash.prototype.toJSON = function() {
return this.toObject();
};
Object.toJSON = JSON.stringify;
})();
}
<%- end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment