moj_template 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.txt +22 -0
  3. data/README.md +96 -0
  4. data/app/assets/images/apple-touch-icon-114x114.png +0 -0
  5. data/app/assets/images/apple-touch-icon-144x144.png +0 -0
  6. data/app/assets/images/apple-touch-icon-57x57.png +0 -0
  7. data/app/assets/images/apple-touch-icon-72x72.png +0 -0
  8. data/app/assets/images/favicon.ico +0 -0
  9. data/app/assets/images/gov.uk_logotype_crown.png +0 -0
  10. data/app/assets/images/gov.uk_logotype_crown_invert.png +0 -0
  11. data/app/assets/images/gov.uk_logotype_crown_invert_trans.png +0 -0
  12. data/app/assets/images/open-government-licence_2x.png +0 -0
  13. data/app/assets/images/opengraph-image.png +0 -0
  14. data/app/assets/javascripts/govuk-template.js +126 -0
  15. data/app/assets/javascripts/ie.js +513 -0
  16. data/app/assets/javascripts/modules/moj.tabs.js +83 -0
  17. data/app/assets/javascripts/moj.js +54 -0
  18. data/app/assets/javascripts/vendor/goog/webfont-debug.js +2127 -0
  19. data/app/assets/javascripts/vendor/jquery/jquery-1.11.0.min.js +5 -0
  20. data/app/assets/stylesheets/external-link-24x24.png +0 -0
  21. data/app/assets/stylesheets/external-link-black-12x12.png +0 -0
  22. data/app/assets/stylesheets/external-link-black-24x24.png +0 -0
  23. data/app/assets/stylesheets/external-link.png +0 -0
  24. data/app/assets/stylesheets/fonts-ie8.css.erb +31 -0
  25. data/app/assets/stylesheets/fonts.css.erb +31 -0
  26. data/app/assets/stylesheets/fonts/NTA-Bold-20130221.eot +0 -0
  27. data/app/assets/stylesheets/fonts/NTA-Bold-20130221.woff +0 -0
  28. data/app/assets/stylesheets/fonts/NTA-Light-20130221.eot +0 -0
  29. data/app/assets/stylesheets/fonts/NTA-Light-20130221.woff +0 -0
  30. data/app/assets/stylesheets/fonts/NTATabularNumbers-Bold.eot +0 -0
  31. data/app/assets/stylesheets/fonts/NTATabularNumbers-Bold.woff +0 -0
  32. data/app/assets/stylesheets/fonts/NTATabularNumbers-Light.eot +0 -0
  33. data/app/assets/stylesheets/fonts/NTATabularNumbers-Light.woff +0 -0
  34. data/app/assets/stylesheets/govuk-template-ie6.css.erb +652 -0
  35. data/app/assets/stylesheets/govuk-template-ie7.css.erb +648 -0
  36. data/app/assets/stylesheets/govuk-template-ie8.css.erb +631 -0
  37. data/app/assets/stylesheets/govuk-template-print.css.erb +78 -0
  38. data/app/assets/stylesheets/govuk-template.css.erb +691 -0
  39. data/app/assets/stylesheets/images/close.png +0 -0
  40. data/app/assets/stylesheets/images/govuk-crest-2x.png +0 -0
  41. data/app/assets/stylesheets/images/govuk-crest-ie.png +0 -0
  42. data/app/assets/stylesheets/images/govuk-crest.png +0 -0
  43. data/app/assets/stylesheets/images/separator-2x.png +0 -0
  44. data/app/assets/stylesheets/images/separator.png +0 -0
  45. data/app/assets/stylesheets/moj-template.css.erb +628 -0
  46. data/app/helpers/moj_helper.rb +9 -0
  47. data/app/views/layouts/moj_template.html.erb +223 -0
  48. data/lib/moj_template.rb +5 -0
  49. data/lib/moj_template/engine.rb +17 -0
  50. data/lib/moj_template/version.rb +3 -0
  51. data/lib/tasks/moj_template_tasks.rake +4 -0
  52. metadata +192 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e6d234e535d17c0e053d3523041e134b031604a
4
+ data.tar.gz: 22d213d27fed6e8e843c15eb528b813776b0fcf3
5
+ SHA512:
6
+ metadata.gz: 9fc3eed3cec3073917fe84fb7f327c34cfdd78d910449e16dde1e68f45dcda084f2ca03bb515026a3088e03a53a9a26e340143d3dcc0d3b1d3dd0f95659c4205
7
+ data.tar.gz: d38072064cb8d00b039817328f548acd3cd6526746428c6a98bbc0744586f51f01662962c8baf8c50753e8a53e57de94a05a94964edf6bcfbe73eb8daddfb68a
data/LICENCE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 MOJ Digital Services
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Ministry of Justice Template
2
+
3
+ This repository is intended to provide a consistent starting point for Ministry of Justice services that are hosted on the gov.uk domain. It includes a basic shared layout and assets that are used across multiple projects.
4
+
5
+ ------
6
+
7
+ [View Changelog](https://github.com/ministryofjustice/moj_template/blob/master/changelog.md)
8
+
9
+ ## Requirements
10
+
11
+ The Ruby language (1.9.3+), the build tool [Rake](http://rake.rubyforge.org/) & the dependancy management tool [Bundler](http://bundler.io/)
12
+
13
+ ## Packaging
14
+
15
+ At present this generates 5 output formats:
16
+
17
+ 1. a gem containing a Rails engine
18
+ 2. a tarball containing Play Framework templates
19
+ 3. a folder containing Mustache templates
20
+ 4. a tarball containing Mustache Inheritance templates
21
+ 5. a tarball
22
+
23
+ ### Gem version
24
+
25
+ To use it, add this line to your application's Gemfile (change the tag to the version you would like to use):
26
+
27
+ gem 'moj_template', git: 'https://github.com/ministryofjustice/moj_template.git', tag: 'v0.1.0'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ You can then use the `moj_template` layout in your app. If you need to extend the layout you can use [nested layouts](http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts).
34
+
35
+ **Note: After making changes to sass files within the template run `rake tmp:clear` in your rails app to clear any existing cached files.**
36
+
37
+ #### Gem Config
38
+
39
+ In order for these files to work, you will need to set a number of variables in your application.rb for things like project title, current phase, etc. If you are encountering errors when trying to use the toolkit, make sure the following are set inside your class Application (example values from a current project provided):
40
+
41
+ # Application Title (Populates <title>)
42
+ config.app_title = ''
43
+ # Proposition Title (Populates proposition header)
44
+ config.proposition_title = ''
45
+ # Current Phase (Sets the current phase and the colour of phase tags)
46
+ # Presumed values: alpha, beta, live
47
+ config.phase = ''
48
+ # Product Type (Adds class to body based on service type)
49
+ # Presumed values: information, service
50
+ config.product_type = ''
51
+ # Feedback URL (URL for feedback link in phase banner)
52
+ config.feedback_url = ''
53
+ # Google Analytics ID (Tracking ID for the service)
54
+ config.ga_id = ''
55
+
56
+ ### Play version
57
+
58
+ To generate the tarball of Play Framework templates run `bundle exec rake build:play`. This will produce a tarball in the `pkg` directory.
59
+
60
+ ### Mustache version
61
+
62
+ To generate the folder of Mustache templates run `bundle exec rake build:mustache`. This will produce a folder in the `pkg` directory.
63
+
64
+ ### Mustache Inheritance version
65
+
66
+ There is a [proposal for Mustache to support template inheritance](https://github.com/mustache/spec/issues/38) this is supported in both the `mustache.java` and the `hogan.js` implementations of Mustache.
67
+
68
+ To generate the tarball of the Mustache Inheritance templates run the `build:mustache_inheritance` rake task. This will produce a tarball in the `pkg` directory.
69
+
70
+ ### Liquid version
71
+
72
+ To generate the folder of Liquid templates run `bundle exec rake build:liquid`. This will produce a tarball in the `pkg` directory.
73
+
74
+ ### Tarball version
75
+
76
+ To generate the tarball, run the `bundle exec rake build:tar` rake task. This will produce a tarball in the `pkg` directory.
77
+
78
+ ## Development
79
+
80
+ The source files are in the `/source` directory. The `compile` rake task builds the `/app` contents from these sources. This process involves the following:
81
+
82
+ * compiling all stylesheets referenced in `/manifests.yml` to plain CSS (actually css.erb, so the Rails asset pipeline can work in the gem).
83
+ * combining all JavaScript files referenced in `/manifests.yml` (using Sprockets)
84
+ * copying the images across (including any needed images from the toolkit)
85
+
86
+ This resulting app directory is included in the gem and hooked in as a Rails engine
87
+
88
+ ## JS
89
+
90
+ The JS is written using a slightly adapted [Heisenberg.js](https://github.com/Heisenbergjs/heisenberg) methodology. A main MOJ namespace is created in moj.js and modules are created in separate files and added to this namespace on a project per project basis.
91
+
92
+ To make use of any modules from the `modules/` folder, include the required module file **after** the `moj.js` file. Here's an example usage:
93
+
94
+ //= require modules/moj.tabs.js
95
+
96
+ For **documentation on Modules**, see the [wiki pages](https://github.com/ministryofjustice/moj_template/wiki).
Binary file
@@ -0,0 +1,126 @@
1
+ (function () {
2
+ "use strict"
3
+ var root = this;
4
+ if(typeof root.GOVUK === 'undefined') { root.GOVUK = {}; }
5
+
6
+ /*
7
+ Cookie methods
8
+ ==============
9
+
10
+ Usage:
11
+
12
+ Setting a cookie:
13
+ GOVUK.cookie('hobnob', 'tasty', { days: 30 });
14
+
15
+ Reading a cookie:
16
+ GOVUK.cookie('hobnob');
17
+
18
+ Deleting a cookie:
19
+ GOVUK.cookie('hobnob', null);
20
+ */
21
+ GOVUK.cookie = function (name, value, options) {
22
+ if(typeof value !== 'undefined'){
23
+ if(value === false || value === null) {
24
+ return GOVUK.setCookie(name, '', { days: -1 });
25
+ } else {
26
+ return GOVUK.setCookie(name, value, options);
27
+ }
28
+ } else {
29
+ return GOVUK.getCookie(name);
30
+ }
31
+ };
32
+ GOVUK.setCookie = function (name, value, options) {
33
+ if(typeof options === 'undefined') {
34
+ options = {};
35
+ }
36
+ var cookieString = name + "=" + value + "; path=/";
37
+ if (options.days) {
38
+ var date = new Date();
39
+ date.setTime(date.getTime() + (options.days * 24 * 60 * 60 * 1000));
40
+ cookieString = cookieString + "; expires=" + date.toGMTString();
41
+ }
42
+ if (document.location.protocol == 'https:'){
43
+ cookieString = cookieString + "; Secure";
44
+ }
45
+ document.cookie = cookieString;
46
+ };
47
+ GOVUK.getCookie = function (name) {
48
+ var nameEQ = name + "=";
49
+ var cookies = document.cookie.split(';');
50
+ for(var i = 0, len = cookies.length; i < len; i++) {
51
+ var cookie = cookies[i];
52
+ while (cookie.charAt(0) == ' ') {
53
+ cookie = cookie.substring(1, cookie.length);
54
+ }
55
+ if (cookie.indexOf(nameEQ) === 0) {
56
+ return decodeURIComponent(cookie.substring(nameEQ.length));
57
+ }
58
+ }
59
+ return null;
60
+ };
61
+ }).call(this);
62
+ (function () {
63
+ "use strict"
64
+ var root = this;
65
+ if(typeof root.GOVUK === 'undefined') { root.GOVUK = {}; }
66
+
67
+ GOVUK.addCookieMessage = function () {
68
+ var message = document.getElementById('global-cookie-message'),
69
+ hasCookieMessage = (message && GOVUK.cookie('seen_cookie_message') === null);
70
+
71
+ if (hasCookieMessage) {
72
+ message.style.display = 'block';
73
+ GOVUK.cookie('seen_cookie_message', 'yes', { days: 28 });
74
+ }
75
+ };
76
+ }).call(this);
77
+ (function() {
78
+ "use strict"
79
+
80
+ // fix for printing bug in Windows Safari
81
+ var windowsSafari = (window.navigator.userAgent.match(/(\(Windows[\s\w\.]+\))[\/\(\s\w\.\,\)]+(Version\/[\d\.]+)\s(Safari\/[\d\.]+)/) !== null),
82
+ style;
83
+
84
+ if (windowsSafari) {
85
+ // set the New Transport font to Arial for printing
86
+ style = document.createElement('style');
87
+ style.setAttribute('type', 'text/css');
88
+ style.setAttribute('media', 'print');
89
+ style.innerHTML = '@font-face { font-family: nta !important; src: local("Arial") !important; }';
90
+ document.getElementsByTagName('head')[0].appendChild(style);
91
+ }
92
+
93
+
94
+ // add cookie message
95
+ if (window.GOVUK && GOVUK.addCookieMessage) {
96
+ GOVUK.addCookieMessage();
97
+ }
98
+
99
+ // header navigation toggle
100
+ if (document.querySelectorAll && document.addEventListener){
101
+ var els = document.querySelectorAll('.js-header-toggle'),
102
+ i, _i;
103
+ for(i=0,_i=els.length; i<_i; i++){
104
+ els[i].addEventListener('click', function(e){
105
+ e.preventDefault();
106
+ var target = document.getElementById(this.getAttribute('href').substr(1)),
107
+ targetClass = target.getAttribute('class') || '',
108
+ sourceClass = this.getAttribute('class') || '';
109
+
110
+ if(targetClass.indexOf('js-visible') !== -1){
111
+ target.setAttribute('class', targetClass.replace(/(^|\s)js-visible(\s|$)/, ''));
112
+ } else {
113
+ target.setAttribute('class', targetClass + " js-visible");
114
+ }
115
+ if(sourceClass.indexOf('js-hidden') !== -1){
116
+ this.setAttribute('class', sourceClass.replace(/(^|\s)js-hidden(\s|$)/, ''));
117
+ } else {
118
+ this.setAttribute('class', sourceClass + " js-hidden");
119
+ }
120
+ });
121
+ }
122
+ }
123
+ }).call(this);
124
+
125
+
126
+
@@ -0,0 +1,513 @@
1
+ /*
2
+ HTML5 Shiv v3.6.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
3
+ */
4
+
5
+
6
+ (function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag();
7
+ a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x<style>article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}</style>";
8
+ c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="<xyz></xyz>";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode||
9
+ "undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment();
10
+ for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d<h;d++)c.createElement(e[d]);return c}};l.html5=e;q(f)})(this,document);
11
+ /*
12
+ HTML5 Shiv v3.6.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
13
+ */
14
+
15
+ (function(j,f){function s(a,b){var c=a.createElement("p"),m=a.getElementsByTagName("head")[0]||a.documentElement;c.innerHTML="x<style>"+b+"</style>";return m.insertBefore(c.lastChild,m.firstChild)}function o(){var a=d.elements;return"string"==typeof a?a.split(" "):a}function n(a){var b=t[a[u]];b||(b={},p++,a[u]=p,t[p]=b);return b}function v(a,b,c){b||(b=f);if(e)return b.createElement(a);c||(c=n(b));b=c.cache[a]?c.cache[a].cloneNode():y.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);
16
+ return b.canHaveChildren&&!z.test(a)?c.frag.appendChild(b):b}function A(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag();a.createElement=function(c){return!d.shivMethods?b.createElem(c):v(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+o().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(d,b.frag)}
17
+ function w(a){a||(a=f);var b=n(a);if(d.shivCSS&&!q&&!b.hasCSS)b.hasCSS=!!s(a,"article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}");e||A(a,b);return a}function B(a){for(var b,c=a.attributes,m=c.length,f=a.ownerDocument.createElement(l+":"+a.nodeName);m--;)b=c[m],b.specified&&f.setAttribute(b.nodeName,b.nodeValue);f.style.cssText=a.style.cssText;return f}function x(a){function b(){clearTimeout(d._removeSheetTimer);c&&c.removeNode(!0);
18
+ c=null}var c,f,d=n(a),e=a.namespaces,j=a.parentWindow;if(!C||a.printShived)return a;"undefined"==typeof e[l]&&e.add(l);j.attachEvent("onbeforeprint",function(){b();var g,i,d;d=a.styleSheets;for(var e=[],h=d.length,k=Array(h);h--;)k[h]=d[h];for(;d=k.pop();)if(!d.disabled&&D.test(d.media)){try{g=d.imports,i=g.length}catch(j){i=0}for(h=0;h<i;h++)k.push(g[h]);try{e.push(d.cssText)}catch(n){}}g=e.reverse().join("").split("{");i=g.length;h=RegExp("(^|[\\s,>+~])("+o().join("|")+")(?=[[\\s,>+~#.:]|$)","gi");
19
+ for(k="$1"+l+"\\:$2";i--;)e=g[i]=g[i].split("}"),e[e.length-1]=e[e.length-1].replace(h,k),g[i]=e.join("}");e=g.join("{");i=a.getElementsByTagName("*");h=i.length;k=RegExp("^(?:"+o().join("|")+")$","i");for(d=[];h--;)g=i[h],k.test(g.nodeName)&&d.push(g.applyElement(B(g)));f=d;c=s(a,e)});j.attachEvent("onafterprint",function(){for(var a=f,c=a.length;c--;)a[c].removeNode();clearTimeout(d._removeSheetTimer);d._removeSheetTimer=setTimeout(b,500)});a.printShived=!0;return a}var r=j.html5||{},z=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,
20
+ y=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q,u="_html5shiv",p=0,t={},e;(function(){try{var a=f.createElement("a");a.innerHTML="<xyz></xyz>";q="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode||"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}e=b}catch(d){e=q=!0}})();var d={elements:r.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",
21
+ version:"3.6.2",shivCSS:!1!==r.shivCSS,supportsUnknownElements:e,shivMethods:!1!==r.shivMethods,type:"default",shivDocument:w,createElement:v,createDocumentFragment:function(a,b){a||(a=f);if(e)return a.createDocumentFragment();for(var b=b||n(a),c=b.frag.cloneNode(),d=0,j=o(),l=j.length;d<l;d++)c.createElement(j[d]);return c}};j.html5=d;w(f);var D=/^$|\b(?:all|print)\b/,l="html5shiv",C=!e&&function(){var a=f.documentElement;return!("undefined"==typeof f.namespaces||"undefined"==typeof f.parentWindow||
22
+ "undefined"==typeof a.applyElement||"undefined"==typeof a.removeNode||"undefined"==typeof j.attachEvent)}();d.type+=" print";d.shivPrint=x;x(f)})(this,document);
23
+
24
+
25
+ /*
26
+ json2.js
27
+ 2011-10-19
28
+
29
+ Public Domain.
30
+
31
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
32
+
33
+ See http://www.JSON.org/js.html
34
+
35
+
36
+ This code should be minified before deployment.
37
+ See http://javascript.crockford.com/jsmin.html
38
+
39
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
40
+ NOT CONTROL.
41
+
42
+
43
+ This file creates a global JSON object containing two methods: stringify
44
+ and parse.
45
+
46
+ JSON.stringify(value, replacer, space)
47
+ value any JavaScript value, usually an object or array.
48
+
49
+ replacer an optional parameter that determines how object
50
+ values are stringified for objects. It can be a
51
+ function or an array of strings.
52
+
53
+ space an optional parameter that specifies the indentation
54
+ of nested structures. If it is omitted, the text will
55
+ be packed without extra whitespace. If it is a number,
56
+ it will specify the number of spaces to indent at each
57
+ level. If it is a string (such as '\t' or '&nbsp;'),
58
+ it contains the characters used to indent at each level.
59
+
60
+ This method produces a JSON text from a JavaScript value.
61
+
62
+ When an object value is found, if the object contains a toJSON
63
+ method, its toJSON method will be called and the result will be
64
+ stringified. A toJSON method does not serialize: it returns the
65
+ value represented by the name/value pair that should be serialized,
66
+ or undefined if nothing should be serialized. The toJSON method
67
+ will be passed the key associated with the value, and this will be
68
+ bound to the value
69
+
70
+ For example, this would serialize Dates as ISO strings.
71
+
72
+ Date.prototype.toJSON = function (key) {
73
+ function f(n) {
74
+ // Format integers to have at least two digits.
75
+ return n < 10 ? '0' + n : n;
76
+ }
77
+
78
+ return this.getUTCFullYear() + '-' +
79
+ f(this.getUTCMonth() + 1) + '-' +
80
+ f(this.getUTCDate()) + 'T' +
81
+ f(this.getUTCHours()) + ':' +
82
+ f(this.getUTCMinutes()) + ':' +
83
+ f(this.getUTCSeconds()) + 'Z';
84
+ };
85
+
86
+ You can provide an optional replacer method. It will be passed the
87
+ key and value of each member, with this bound to the containing
88
+ object. The value that is returned from your method will be
89
+ serialized. If your method returns undefined, then the member will
90
+ be excluded from the serialization.
91
+
92
+ If the replacer parameter is an array of strings, then it will be
93
+ used to select the members to be serialized. It filters the results
94
+ such that only members with keys listed in the replacer array are
95
+ stringified.
96
+
97
+ Values that do not have JSON representations, such as undefined or
98
+ functions, will not be serialized. Such values in objects will be
99
+ dropped; in arrays they will be replaced with null. You can use
100
+ a replacer function to replace those with JSON values.
101
+ JSON.stringify(undefined) returns undefined.
102
+
103
+ The optional space parameter produces a stringification of the
104
+ value that is filled with line breaks and indentation to make it
105
+ easier to read.
106
+
107
+ If the space parameter is a non-empty string, then that string will
108
+ be used for indentation. If the space parameter is a number, then
109
+ the indentation will be that many spaces.
110
+
111
+ Example:
112
+
113
+ text = JSON.stringify(['e', {pluribus: 'unum'}]);
114
+ // text is '["e",{"pluribus":"unum"}]'
115
+
116
+
117
+ text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
118
+ // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
119
+
120
+ text = JSON.stringify([new Date()], function (key, value) {
121
+ return this[key] instanceof Date ?
122
+ 'Date(' + this[key] + ')' : value;
123
+ });
124
+ // text is '["Date(---current time---)"]'
125
+
126
+
127
+ JSON.parse(text, reviver)
128
+ This method parses a JSON text to produce an object or array.
129
+ It can throw a SyntaxError exception.
130
+
131
+ The optional reviver parameter is a function that can filter and
132
+ transform the results. It receives each of the keys and values,
133
+ and its return value is used instead of the original value.
134
+ If it returns what it received, then the structure is not modified.
135
+ If it returns undefined then the member is deleted.
136
+
137
+ Example:
138
+
139
+ // Parse the text. Values that look like ISO date strings will
140
+ // be converted to Date objects.
141
+
142
+ myData = JSON.parse(text, function (key, value) {
143
+ var a;
144
+ if (typeof value === 'string') {
145
+ a =
146
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
147
+ if (a) {
148
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
149
+ +a[5], +a[6]));
150
+ }
151
+ }
152
+ return value;
153
+ });
154
+
155
+ myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
156
+ var d;
157
+ if (typeof value === 'string' &&
158
+ value.slice(0, 5) === 'Date(' &&
159
+ value.slice(-1) === ')') {
160
+ d = new Date(value.slice(5, -1));
161
+ if (d) {
162
+ return d;
163
+ }
164
+ }
165
+ return value;
166
+ });
167
+
168
+
169
+ This is a reference implementation. You are free to copy, modify, or
170
+ redistribute.
171
+ */
172
+
173
+ /*jslint evil: true, regexp: true */
174
+
175
+ /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
176
+ call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
177
+ getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
178
+ lastIndex, length, parse, prototype, push, replace, slice, stringify,
179
+ test, toJSON, toString, valueOf
180
+ */
181
+
182
+
183
+ // Create a JSON object only if one does not already exist. We create the
184
+ // methods in a closure to avoid creating global variables.
185
+
186
+ var JSON;
187
+ if (!JSON) {
188
+ JSON = {};
189
+ }
190
+
191
+ (function () {
192
+ 'use strict';
193
+
194
+ function f(n) {
195
+ // Format integers to have at least two digits.
196
+ return n < 10 ? '0' + n : n;
197
+ }
198
+
199
+ if (typeof Date.prototype.toJSON !== 'function') {
200
+
201
+ Date.prototype.toJSON = function (key) {
202
+
203
+ return isFinite(this.valueOf())
204
+ ? this.getUTCFullYear() + '-' +
205
+ f(this.getUTCMonth() + 1) + '-' +
206
+ f(this.getUTCDate()) + 'T' +
207
+ f(this.getUTCHours()) + ':' +
208
+ f(this.getUTCMinutes()) + ':' +
209
+ f(this.getUTCSeconds()) + 'Z'
210
+ : null;
211
+ };
212
+
213
+ String.prototype.toJSON =
214
+ Number.prototype.toJSON =
215
+ Boolean.prototype.toJSON = function (key) {
216
+ return this.valueOf();
217
+ };
218
+ }
219
+
220
+ var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
221
+ escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
222
+ gap,
223
+ indent,
224
+ meta = { // table of character substitutions
225
+ '\b': '\\b',
226
+ '\t': '\\t',
227
+ '\n': '\\n',
228
+ '\f': '\\f',
229
+ '\r': '\\r',
230
+ '"' : '\\"',
231
+ '\\': '\\\\'
232
+ },
233
+ rep;
234
+
235
+
236
+ function quote(string) {
237
+
238
+ // If the string contains no control characters, no quote characters, and no
239
+ // backslash characters, then we can safely slap some quotes around it.
240
+ // Otherwise we must also replace the offending characters with safe escape
241
+ // sequences.
242
+
243
+ escapable.lastIndex = 0;
244
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
245
+ var c = meta[a];
246
+ return typeof c === 'string'
247
+ ? c
248
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
249
+ }) + '"' : '"' + string + '"';
250
+ }
251
+
252
+
253
+ function str(key, holder) {
254
+
255
+ // Produce a string from holder[key].
256
+
257
+ var i, // The loop counter.
258
+ k, // The member key.
259
+ v, // The member value.
260
+ length,
261
+ mind = gap,
262
+ partial,
263
+ value = holder[key];
264
+
265
+ // If the value has a toJSON method, call it to obtain a replacement value.
266
+
267
+ if (value && typeof value === 'object' &&
268
+ typeof value.toJSON === 'function') {
269
+ value = value.toJSON(key);
270
+ }
271
+
272
+ // If we were called with a replacer function, then call the replacer to
273
+ // obtain a replacement value.
274
+
275
+ if (typeof rep === 'function') {
276
+ value = rep.call(holder, key, value);
277
+ }
278
+
279
+ // What happens next depends on the value's type.
280
+
281
+ switch (typeof value) {
282
+ case 'string':
283
+ return quote(value);
284
+
285
+ case 'number':
286
+
287
+ // JSON numbers must be finite. Encode non-finite numbers as null.
288
+
289
+ return isFinite(value) ? String(value) : 'null';
290
+
291
+ case 'boolean':
292
+ case 'null':
293
+
294
+ // If the value is a boolean or null, convert it to a string. Note:
295
+ // typeof null does not produce 'null'. The case is included here in
296
+ // the remote chance that this gets fixed someday.
297
+
298
+ return String(value);
299
+
300
+ // If the type is 'object', we might be dealing with an object or an array or
301
+ // null.
302
+
303
+ case 'object':
304
+
305
+ // Due to a specification blunder in ECMAScript, typeof null is 'object',
306
+ // so watch out for that case.
307
+
308
+ if (!value) {
309
+ return 'null';
310
+ }
311
+
312
+ // Make an array to hold the partial results of stringifying this object value.
313
+
314
+ gap += indent;
315
+ partial = [];
316
+
317
+ // Is the value an array?
318
+
319
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
320
+
321
+ // The value is an array. Stringify every element. Use null as a placeholder
322
+ // for non-JSON values.
323
+
324
+ length = value.length;
325
+ for (i = 0; i < length; i += 1) {
326
+ partial[i] = str(i, value) || 'null';
327
+ }
328
+
329
+ // Join all of the elements together, separated with commas, and wrap them in
330
+ // brackets.
331
+
332
+ v = partial.length === 0
333
+ ? '[]'
334
+ : gap
335
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
336
+ : '[' + partial.join(',') + ']';
337
+ gap = mind;
338
+ return v;
339
+ }
340
+
341
+ // If the replacer is an array, use it to select the members to be stringified.
342
+
343
+ if (rep && typeof rep === 'object') {
344
+ length = rep.length;
345
+ for (i = 0; i < length; i += 1) {
346
+ if (typeof rep[i] === 'string') {
347
+ k = rep[i];
348
+ v = str(k, value);
349
+ if (v) {
350
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
351
+ }
352
+ }
353
+ }
354
+ } else {
355
+
356
+ // Otherwise, iterate through all of the keys in the object.
357
+
358
+ for (k in value) {
359
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
360
+ v = str(k, value);
361
+ if (v) {
362
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
363
+ }
364
+ }
365
+ }
366
+ }
367
+
368
+ // Join all of the member texts together, separated with commas,
369
+ // and wrap them in braces.
370
+
371
+ v = partial.length === 0
372
+ ? '{}'
373
+ : gap
374
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
375
+ : '{' + partial.join(',') + '}';
376
+ gap = mind;
377
+ return v;
378
+ }
379
+ }
380
+
381
+ // If the JSON object does not yet have a stringify method, give it one.
382
+
383
+ if (typeof JSON.stringify !== 'function') {
384
+ JSON.stringify = function (value, replacer, space) {
385
+
386
+ // The stringify method takes a value and an optional replacer, and an optional
387
+ // space parameter, and returns a JSON text. The replacer can be a function
388
+ // that can replace values, or an array of strings that will select the keys.
389
+ // A default replacer method can be provided. Use of the space parameter can
390
+ // produce text that is more easily readable.
391
+
392
+ var i;
393
+ gap = '';
394
+ indent = '';
395
+
396
+ // If the space parameter is a number, make an indent string containing that
397
+ // many spaces.
398
+
399
+ if (typeof space === 'number') {
400
+ for (i = 0; i < space; i += 1) {
401
+ indent += ' ';
402
+ }
403
+
404
+ // If the space parameter is a string, it will be used as the indent string.
405
+
406
+ } else if (typeof space === 'string') {
407
+ indent = space;
408
+ }
409
+
410
+ // If there is a replacer, it must be a function or an array.
411
+ // Otherwise, throw an error.
412
+
413
+ rep = replacer;
414
+ if (replacer && typeof replacer !== 'function' &&
415
+ (typeof replacer !== 'object' ||
416
+ typeof replacer.length !== 'number')) {
417
+ throw new Error('JSON.stringify');
418
+ }
419
+
420
+ // Make a fake root object containing our value under the key of ''.
421
+ // Return the result of stringifying the value.
422
+
423
+ return str('', {'': value});
424
+ };
425
+ }
426
+
427
+
428
+ // If the JSON object does not yet have a parse method, give it one.
429
+
430
+ if (typeof JSON.parse !== 'function') {
431
+ JSON.parse = function (text, reviver) {
432
+
433
+ // The parse method takes a text and an optional reviver function, and returns
434
+ // a JavaScript value if the text is a valid JSON text.
435
+
436
+ var j;
437
+
438
+ function walk(holder, key) {
439
+
440
+ // The walk method is used to recursively walk the resulting structure so
441
+ // that modifications can be made.
442
+
443
+ var k, v, value = holder[key];
444
+ if (value && typeof value === 'object') {
445
+ for (k in value) {
446
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
447
+ v = walk(value, k);
448
+ if (v !== undefined) {
449
+ value[k] = v;
450
+ } else {
451
+ delete value[k];
452
+ }
453
+ }
454
+ }
455
+ }
456
+ return reviver.call(holder, key, value);
457
+ }
458
+
459
+
460
+ // Parsing happens in four stages. In the first stage, we replace certain
461
+ // Unicode characters with escape sequences. JavaScript handles many characters
462
+ // incorrectly, either silently deleting them, or treating them as line endings.
463
+
464
+ text = String(text);
465
+ cx.lastIndex = 0;
466
+ if (cx.test(text)) {
467
+ text = text.replace(cx, function (a) {
468
+ return '\\u' +
469
+ ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
470
+ });
471
+ }
472
+
473
+ // In the second stage, we run the text against regular expressions that look
474
+ // for non-JSON patterns. We are especially concerned with '()' and 'new'
475
+ // because they can cause invocation, and '=' because it can cause mutation.
476
+ // But just to be safe, we want to reject all unexpected forms.
477
+
478
+ // We split the second stage into 4 regexp operations in order to work around
479
+ // crippling inefficiencies in IE's and Safari's regexp engines. First we
480
+ // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
481
+ // replace all simple value tokens with ']' characters. Third, we delete all
482
+ // open brackets that follow a colon or comma or that begin the text. Finally,
483
+ // we look to see that the remaining characters are only whitespace or ']' or
484
+ // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
485
+
486
+ if (/^[\],:{}\s]*$/
487
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
488
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
489
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
490
+
491
+ // In the third stage we use the eval function to compile the text into a
492
+ // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
493
+ // in JavaScript: it can begin a block or an object literal. We wrap the text
494
+ // in parens to eliminate the ambiguity.
495
+
496
+ j = eval('(' + text + ')');
497
+
498
+ // In the optional fourth stage, we recursively walk the new structure, passing
499
+ // each name/value pair to a reviver function for possible transformation.
500
+
501
+ return typeof reviver === 'function'
502
+ ? walk({'': j}, '')
503
+ : j;
504
+ }
505
+
506
+ // If the text is not JSON parseable, then a SyntaxError is thrown.
507
+
508
+ throw new SyntaxError('JSON.parse');
509
+ };
510
+ }
511
+ }());
512
+
513
+