Permalink
Browse files

restored on-demand inclusion of json2.js

plus reverted unnecessary fork, upgrading the library in the process

this partially reverts f61b0dd
  • Loading branch information...
1 parent 84999c1 commit 1ebb56f65aa4aba7a38c45801b3f5185bcc48684 FND committed Jan 30, 2012
Showing with 34 additions and 26 deletions.
  1. +0 −1 app/assets/javascripts/framework.js
  2. +7 −0 app/views/layouts/application.html.erb
  3. +27 −25 vendor/assets/javascripts/json2.js
View
1 app/assets/javascripts/framework.js
@@ -5,4 +5,3 @@
//= require jquery.treeview
//= require jquery.treeview.async
//= require storage
-//= require json2
View
7 app/views/layouts/application.html.erb
@@ -53,6 +53,13 @@
</div>
</div>
</div>
+
+ <script>
+ // load JSON polyfill only if necessary
+ if(typeof JSON === "undefined") {
+ document.write('<%= javascript_include_tag("json2").sub("</", "<\\/").html_safe %>');
+ }
+ </script>
<%= javascript_include_tag "manifest" %>
<%= yield :scripts %>
</body>
View
52 vendor/assets/javascripts/json2.js
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json2.js
- 2011-02-23
+ 2011-10-19
Public Domain.
@@ -146,7 +146,7 @@
redistribute.
*/
-/*jslint evil: true, strict: false, regexp: false */
+/*jslint evil: true, regexp: true */
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
@@ -159,16 +159,13 @@
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
-// load JSON polyfill only if necessary
-if (typeof JSON === "undefined") {
-
var JSON;
if (!JSON) {
JSON = {};
}
(function () {
- "use strict";
+ 'use strict';
function f(n) {
// Format integers to have at least two digits.
@@ -179,13 +176,14 @@ if (!JSON) {
Date.prototype.toJSON = function (key) {
- 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;
+ 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 =
@@ -221,8 +219,9 @@ if (!JSON) {
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
- return typeof c === 'string' ? c :
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
+ return typeof c === 'string'
+ ? c
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + string + '"';
}
@@ -306,9 +305,11 @@ if (!JSON) {
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
- v = partial.length === 0 ? '[]' : gap ?
- '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
- '[' + partial.join(',') + ']';
+ v = partial.length === 0
+ ? '[]'
+ : gap
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
+ : '[' + partial.join(',') + ']';
gap = mind;
return v;
}
@@ -343,9 +344,11 @@ if (!JSON) {
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
- v = partial.length === 0 ? '{}' : gap ?
- '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
- '{' + partial.join(',') + '}';
+ v = partial.length === 0
+ ? '{}'
+ : gap
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
+ : '{' + partial.join(',') + '}';
gap = mind;
return v;
}
@@ -471,8 +474,9 @@ if (!JSON) {
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
- return typeof reviver === 'function' ?
- walk({'': j}, '') : j;
+ return typeof reviver === 'function'
+ ? walk({'': j}, '')
+ : j;
}
// If the text is not JSON parseable, then a SyntaxError is thrown.
@@ -481,5 +485,3 @@ if (!JSON) {
};
}
}());
-
-} // if (typeof JSON === "undefined")

0 comments on commit 1ebb56f

Please sign in to comment.