idsk_template 0.24.0.idsk.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.txt +22 -0
  3. data/README.md +35 -0
  4. data/app/assets/images/apple-touch-icon-152x152.png +0 -0
  5. data/app/assets/images/apple-touch-icon-167x167.png +0 -0
  6. data/app/assets/images/apple-touch-icon-180x180.png +0 -0
  7. data/app/assets/images/apple-touch-icon.png +0 -0
  8. data/app/assets/images/favicon.ico +0 -0
  9. data/app/assets/images/gov.uk_logotype_crown.svg +7 -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/opengraph-image.png +0 -0
  13. data/app/assets/javascripts/idsk-template.js +114 -0
  14. data/app/assets/javascripts/ie.js +494 -0
  15. data/app/assets/stylesheets/fonts.css.erb +48 -0
  16. data/app/assets/stylesheets/fonts/v1-2c037cf7e1-light.eot +0 -0
  17. data/app/assets/stylesheets/fonts/v1-357fdfbcc3-tabular-bold.eot +0 -0
  18. data/app/assets/stylesheets/fonts/v1-458f8ea81c-light.woff +0 -0
  19. data/app/assets/stylesheets/fonts/v1-498ea8ffe2-tabular-light.eot +0 -0
  20. data/app/assets/stylesheets/fonts/v1-62cc6f0a28-tabular-light.woff +0 -0
  21. data/app/assets/stylesheets/fonts/v1-784c21afb8-tabular-bold.woff +0 -0
  22. data/app/assets/stylesheets/fonts/v1-851b10ccdd-tabular-light.woff2 +0 -0
  23. data/app/assets/stylesheets/fonts/v1-a2452cb66f-bold.woff2 +0 -0
  24. data/app/assets/stylesheets/fonts/v1-b89238d840-tabular-bold.woff2 +0 -0
  25. data/app/assets/stylesheets/fonts/v1-f38ad40456-light.woff2 +0 -0
  26. data/app/assets/stylesheets/fonts/v1-f38c792ac2-bold.woff +0 -0
  27. data/app/assets/stylesheets/fonts/v1-fb2676462a-bold.eot +0 -0
  28. data/app/assets/stylesheets/idsk-template-ie6.css.erb +588 -0
  29. data/app/assets/stylesheets/idsk-template-ie7.css.erb +586 -0
  30. data/app/assets/stylesheets/idsk-template-ie8.css.erb +564 -0
  31. data/app/assets/stylesheets/idsk-template-print.css.erb +75 -0
  32. data/app/assets/stylesheets/idsk-template.css.erb +622 -0
  33. data/app/assets/stylesheets/images/close.png +0 -0
  34. data/app/assets/stylesheets/images/gov.uk_logotype_crown-1x.png +0 -0
  35. data/app/assets/stylesheets/images/gov.uk_logotype_crown.png +0 -0
  36. data/app/assets/stylesheets/images/govuk-crest-2x.png +0 -0
  37. data/app/assets/stylesheets/images/govuk-crest-ie.png +0 -0
  38. data/app/assets/stylesheets/images/govuk-crest.png +0 -0
  39. data/app/assets/stylesheets/images/open-government-licence.png +0 -0
  40. data/app/assets/stylesheets/images/open-government-licence_2x.png +0 -0
  41. data/app/views/layouts/idsk_template.html.erb +115 -0
  42. data/lib/idsk_template.rb +5 -0
  43. data/lib/idsk_template/engine.rb +21 -0
  44. data/lib/idsk_template/version.rb +3 -0
  45. metadata +243 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9eb03c6cc2c5853e4d6fb9dbae033f97b71e5502
4
+ data.tar.gz: c260780fac4635da371a491b86096691296a462d
5
+ SHA512:
6
+ metadata.gz: 3ad0c87496a80d0d7a3465d052b8115a6e88ee84ed737f7b6a4f68c658bd8e121d8e5609275307f7e312588714488085acd691faee35fedf6b268d56abce2c53
7
+ data.tar.gz: 8301792a9d346c06cfce57a015d0ff07bbd67ab39e01c311019db2f6d5c988a8664e693b3ea9a2958fb379675f75afc8435363374a3c058bd1e344948aefd9cb
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Crown Copyright (Government Digital Service)
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.
@@ -0,0 +1,35 @@
1
+ # ID-SK Template
2
+
3
+ This provides a template containing the ID-SK header and footer, and associated assets. It provides a consistent ID-SK brand experience across government services in Slovakia.
4
+
5
+ The template is built from [`source`](source/) files, and multiple packages are generated to support different languages and frameworks.
6
+
7
+ Packages are available for [RubyGems](https://rubygems.org/gems/idsk_template), NPM ([mustache](https://npmjs.org/package/idsk_template_mustache), [ejs](https://npmjs.org/package/idsk_template_ejs), [jinja](https://npmjs.org/package/idsk_template_jinja)), and other [templating languages](docs/packaging.md).
8
+
9
+
10
+ ## Previewing the template
11
+
12
+ You can [view a collection of auto-generated examples](https://id-sk.github.io/idsk_template/) of the current idsk_template release, which show how you can use the template.
13
+
14
+ ## Requirements
15
+
16
+ The Ruby language (1.9.3+), the build tool [Rake](https://github.com/ruby/rake) & the dependancy management tool [Bundler](https://bundler.io/)
17
+
18
+ ## Detailed Docs
19
+
20
+ * [Development](docs/development.md)
21
+ * [Packaging](docs/packaging.md)
22
+ * [Publishing](docs/publishing.md)
23
+
24
+ ## Usage
25
+
26
+ * [Using with Rails](docs/using-with-rails.md)
27
+ * [ID-SK template blocks and their default values (how to customise the template)](docs/template-blocks.md)
28
+ * [Setting a Skip link](docs/usage.md#skip-link)
29
+ * [Propositional title and navigation](docs/usage.md#propositional-title-and-navigation)
30
+
31
+ ## Contributing
32
+
33
+ Please follow the [contribution guidelines](https://github.com/id-sk/idsk_template/blob/master/CONTRIBUTING.md).
34
+
35
+ This is versioned following [Semantic Versioning](http://semver.org).
@@ -0,0 +1,7 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="132" height="97" viewBox="0 0 132 97" version="1.1">
2
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
3
+ <g fill="#000000">
4
+ <path d="M25 30.2C28.5 31.7 32.7 30 34.1 26.5 35.6 22.9 33.9 18.7 30.2 17.3 26.6 15.9 22.6 17.6 21.1 21.2 19.7 24.7 21.4 28.7 25 30.2L25 30.2ZM9 39.5C12.6 41 16.8 39.3 18.2 35.8 19.7 32.2 18 28 14.3 26.7 10.7 25.2 6.7 26.9 5.2 30.5 3.8 34 5.5 38 9 39.5L9 39.5ZM4.4 57.2C7.9 58.7 12.1 57 13.5 53.4 15 49.8 13.3 45.7 9.6 44.3 6.1 42.8 2 44.6 0.5 48.1 -0.9 51.6 0.8 55.7 4.4 57.2L4.4 57.2ZM42.7 35.8C46.2 37.3 50.4 35.6 51.8 32 53.3 28.4 51.6 24.3 47.9 22.9 44.3 21.4 40.3 23.2 38.8 26.7 37.5 30.3 39.2 34.4 42.7 35.8L42.7 35.8ZM107.1 30.2C103.5 31.7 99.3 30 98 26.5 96.5 22.9 98.2 18.7 101.8 17.3 105.4 15.9 109.5 17.6 111 21.2 112.3 24.7 110.6 28.7 107.1 30.2L107.1 30.2ZM123 39.5C119.4 41 115.3 39.3 113.9 35.8 112.4 32.2 114.1 28 117.6 26.7 121.2 25.2 125.3 26.9 126.8 30.5 128.3 34 126.5 38 123 39.5L123 39.5ZM127.7 57.2C124.1 58.7 119.9 57 118.5 53.4 117 49.8 118.7 45.7 122.4 44.3 126 42.8 130.1 44.6 131.6 48.1 132.9 51.6 131.2 55.7 127.7 57.2L127.7 57.2ZM89.3 35.8C85.7 37.3 81.5 35.6 80.1 32 78.7 28.4 80.3 24.3 84 22.9 87.6 21.4 91.7 23.2 93.2 26.7 94.6 30.3 92.9 34.4 89.3 35.8L89.3 35.8ZM69.7 17.7L69.7 17.7 78.6 22.4 78.6 9.3 69.7 12.1 69.7 12.1C69.5 11.8 69.2 11.5 68.8 11.2L68.8 11.2 72.4 0 66 0 59.6 0 63.1 11.2 63.1 11.2C62.8 11.5 62.5 11.7 62.2 12.1L62.2 12.1 53.4 9.3 53.4 22.4 62.2 17.7 62.2 17.7C62.5 18 62.8 18.4 63.1 18.6L58.1 34C58.1 34 58.1 34 58.1 34.1L58.1 34.1 58.1 34.1C57.9 34.9 57.7 35.7 57.7 36.5 57.7 40.6 60.8 44 64.7 44.6L64.9 44.6C65.2 44.6 65.6 44.7 65.9 44.7 66.3 44.7 66.6 44.7 66.9 44.6L67.1 44.6C71.1 44 74.2 40.5 74.2 36.5 74.2 35.7 74.1 34.8 73.8 34.1L73.8 34.1 73.8 34.1C73.8 34.1 73.8 34.1 73.8 34L68.7 18.6C69.1 18.4 69.4 18 69.7 17.7L69.7 17.7ZM66 92.8C82.9 92.8 98.8 93.9 113.1 96 117.1 79.1 122 69.3 127.1 62.5L117.5 59.1C118.5 64 118.6 66.3 117.5 69.3 116 67.9 114.5 65 113.3 60.6L108.6 76C111.4 74 113.6 72.8 116.1 72.7 111.7 82.1 106.1 84.6 102.5 83.9 98.2 83.1 96.2 79.3 96.9 76 97.9 71.3 102.6 70.1 104.9 75.5 109.2 66.8 101.9 64.1 97.3 66.7 104.4 59.5 105.2 53.2 99.4 45.6 91.4 51.7 91.3 57.9 94.9 66.4 90.2 61 82.8 63.9 85.4 72.6 88.8 67.4 93.3 70.6 92.6 75.7 92 80 86.2 83.5 79.1 82.9 68.8 82 68.2 74.9 67.9 69.1 70.4 68.6 75 70.9 78.9 76.4L80.2 60C76.1 64.4 72.2 65.3 67.9 65.4 69.3 61 75.9 53.8 75.9 53.8L66.4 53.8 66.4 53.8 66.4 53.8 55.5 53.8C55.5 53.8 61.9 61 63.4 65.4 59.2 65.3 55.4 64.4 51.1 60L52.5 76.4C56.4 70.9 61 68.7 63.4 69.1 63.1 74.9 62.5 81.9 52.3 82.9 45.1 83.5 39.4 80 38.8 75.7 38.1 70.7 42.6 67.4 45.9 72.6 48.6 63.9 41.3 61 36.5 66.4 40.2 57.9 40.1 51.7 31.9 45.6 26.1 53.2 26.9 59.5 34.1 66.7 29.4 64.1 22.2 66.8 26.4 75.5 28.7 70 33.5 71.3 34.5 76 35.2 79.3 33.2 83.1 28.8 83.9 25.3 84.6 19.8 82.1 15.3 72.7 17.8 72.8 20 74 22.8 76L18.1 60.6C16.9 65 15.4 67.8 13.8 69.3 12.7 66.3 12.9 64 13.8 59.1L4.3 62.5C9.3 69.4 14.2 79.2 18.3 96 33.1 93.9 49.1 92.8 66 92.8L66 92.8Z"/>
5
+ </g>
6
+ </g>
7
+ </svg>
@@ -0,0 +1,114 @@
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
+ // add cookie message
81
+ if (window.GOVUK && GOVUK.addCookieMessage) {
82
+ GOVUK.addCookieMessage();
83
+ }
84
+
85
+ // header navigation toggle
86
+ if (document.querySelectorAll && document.addEventListener){
87
+ var els = document.querySelectorAll('.js-header-toggle'),
88
+ i, _i;
89
+ for(i=0,_i=els.length; i<_i; i++){
90
+ els[i].addEventListener('click', function(e){
91
+ e.preventDefault();
92
+ var target = document.getElementById(this.getAttribute('href').substr(1)),
93
+ targetClass = target.getAttribute('class') || '',
94
+ sourceClass = this.getAttribute('class') || '';
95
+
96
+ if(targetClass.indexOf('js-visible') !== -1){
97
+ target.setAttribute('class', targetClass.replace(/(^|\s)js-visible(\s|$)/, ''));
98
+ } else {
99
+ target.setAttribute('class', targetClass + " js-visible");
100
+ }
101
+ if(sourceClass.indexOf('js-visible') !== -1){
102
+ this.setAttribute('class', sourceClass.replace(/(^|\s)js-visible(\s|$)/, ''));
103
+ } else {
104
+ this.setAttribute('class', sourceClass + " js-visible");
105
+ }
106
+ this.setAttribute('aria-expanded', this.getAttribute('aria-expanded') !== "true");
107
+ target.setAttribute('aria-hidden', target.getAttribute('aria-hidden') === "false");
108
+ });
109
+ }
110
+ }
111
+ }).call(this);
112
+
113
+
114
+
@@ -0,0 +1,494 @@
1
+ /**
2
+ * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
3
+ */
4
+
5
+ !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x<style>"+b+"</style>",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=y.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=y.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),y.elements=c+" "+a,j(b)}function f(a){var b=x[a[v]];return b||(b={},w++,a[v]=w,x[w]=b),b}function g(a,c,d){if(c||(c=b),q)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():u.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||t.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),q)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return y.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(y,b.frag)}function j(a){a||(a=b);var d=f(a);return!y.shivCSS||p||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),q||i(a,d),a}function k(a){for(var b,c=a.getElementsByTagName("*"),e=c.length,f=RegExp("^(?:"+d().join("|")+")$","i"),g=[];e--;)b=c[e],f.test(b.nodeName)&&g.push(b.applyElement(l(b)));return g}function l(a){for(var b,c=a.attributes,d=c.length,e=a.ownerDocument.createElement(A+":"+a.nodeName);d--;)b=c[d],b.specified&&e.setAttribute(b.nodeName,b.nodeValue);return e.style.cssText=a.style.cssText,e}function m(a){for(var b,c=a.split("{"),e=c.length,f=RegExp("(^|[\\s,>+~])("+d().join("|")+")(?=[[\\s,>+~#.:]|$)","gi"),g="$1"+A+"\\:$2";e--;)b=c[e]=c[e].split("}"),b[b.length-1]=b[b.length-1].replace(f,g),c[e]=b.join("}");return c.join("{")}function n(a){for(var b=a.length;b--;)a[b].removeNode()}function o(a){function b(){clearTimeout(g._removeSheetTimer),d&&d.removeNode(!0),d=null}var d,e,g=f(a),h=a.namespaces,i=a.parentWindow;return!B||a.printShived?a:("undefined"==typeof h[A]&&h.add(A),i.attachEvent("onbeforeprint",function(){b();for(var f,g,h,i=a.styleSheets,j=[],l=i.length,n=Array(l);l--;)n[l]=i[l];for(;h=n.pop();)if(!h.disabled&&z.test(h.media)){try{f=h.imports,g=f.length}catch(o){g=0}for(l=0;g>l;l++)n.push(f[l]);try{j.push(h.cssText)}catch(o){}}j=m(j.reverse().join("")),e=k(a),d=c(a,j)}),i.attachEvent("onafterprint",function(){n(e),clearTimeout(g._removeSheetTimer),g._removeSheetTimer=setTimeout(b,500)}),a.printShived=!0,a)}var p,q,r="3.7.3",s=a.html5||{},t=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,u=/^(?: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,v="_html5shiv",w=0,x={};!function(){try{var a=b.createElement("a");a.innerHTML="<xyz></xyz>",p="hidden"in a,q=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){p=!0,q=!0}}();var y={elements:s.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:r,shivCSS:s.shivCSS!==!1,supportsUnknownElements:q,shivMethods:s.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=y,j(b);var z=/^$|\b(?:all|print)\b/,A="html5shiv",B=!q&&function(){var c=b.documentElement;return!("undefined"==typeof b.namespaces||"undefined"==typeof b.parentWindow||"undefined"==typeof c.applyElement||"undefined"==typeof c.removeNode||"undefined"==typeof a.attachEvent)}();y.type+=" print",y.shivPrint=o,o(b),"object"==typeof module&&module.exports&&(module.exports=y)}("undefined"!=typeof window?window:this,document);
6
+ /*
7
+ json2.js
8
+ 2011-10-19
9
+
10
+ Public Domain.
11
+
12
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
13
+
14
+ See http://www.JSON.org/js.html
15
+
16
+
17
+ This code should be minified before deployment.
18
+ See http://javascript.crockford.com/jsmin.html
19
+
20
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
21
+ NOT CONTROL.
22
+
23
+
24
+ This file creates a global JSON object containing two methods: stringify
25
+ and parse.
26
+
27
+ JSON.stringify(value, replacer, space)
28
+ value any JavaScript value, usually an object or array.
29
+
30
+ replacer an optional parameter that determines how object
31
+ values are stringified for objects. It can be a
32
+ function or an array of strings.
33
+
34
+ space an optional parameter that specifies the indentation
35
+ of nested structures. If it is omitted, the text will
36
+ be packed without extra whitespace. If it is a number,
37
+ it will specify the number of spaces to indent at each
38
+ level. If it is a string (such as '\t' or '&nbsp;'),
39
+ it contains the characters used to indent at each level.
40
+
41
+ This method produces a JSON text from a JavaScript value.
42
+
43
+ When an object value is found, if the object contains a toJSON
44
+ method, its toJSON method will be called and the result will be
45
+ stringified. A toJSON method does not serialize: it returns the
46
+ value represented by the name/value pair that should be serialized,
47
+ or undefined if nothing should be serialized. The toJSON method
48
+ will be passed the key associated with the value, and this will be
49
+ bound to the value
50
+
51
+ For example, this would serialize Dates as ISO strings.
52
+
53
+ Date.prototype.toJSON = function (key) {
54
+ function f(n) {
55
+ // Format integers to have at least two digits.
56
+ return n < 10 ? '0' + n : n;
57
+ }
58
+
59
+ return this.getUTCFullYear() + '-' +
60
+ f(this.getUTCMonth() + 1) + '-' +
61
+ f(this.getUTCDate()) + 'T' +
62
+ f(this.getUTCHours()) + ':' +
63
+ f(this.getUTCMinutes()) + ':' +
64
+ f(this.getUTCSeconds()) + 'Z';
65
+ };
66
+
67
+ You can provide an optional replacer method. It will be passed the
68
+ key and value of each member, with this bound to the containing
69
+ object. The value that is returned from your method will be
70
+ serialized. If your method returns undefined, then the member will
71
+ be excluded from the serialization.
72
+
73
+ If the replacer parameter is an array of strings, then it will be
74
+ used to select the members to be serialized. It filters the results
75
+ such that only members with keys listed in the replacer array are
76
+ stringified.
77
+
78
+ Values that do not have JSON representations, such as undefined or
79
+ functions, will not be serialized. Such values in objects will be
80
+ dropped; in arrays they will be replaced with null. You can use
81
+ a replacer function to replace those with JSON values.
82
+ JSON.stringify(undefined) returns undefined.
83
+
84
+ The optional space parameter produces a stringification of the
85
+ value that is filled with line breaks and indentation to make it
86
+ easier to read.
87
+
88
+ If the space parameter is a non-empty string, then that string will
89
+ be used for indentation. If the space parameter is a number, then
90
+ the indentation will be that many spaces.
91
+
92
+ Example:
93
+
94
+ text = JSON.stringify(['e', {pluribus: 'unum'}]);
95
+ // text is '["e",{"pluribus":"unum"}]'
96
+
97
+
98
+ text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
99
+ // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
100
+
101
+ text = JSON.stringify([new Date()], function (key, value) {
102
+ return this[key] instanceof Date ?
103
+ 'Date(' + this[key] + ')' : value;
104
+ });
105
+ // text is '["Date(---current time---)"]'
106
+
107
+
108
+ JSON.parse(text, reviver)
109
+ This method parses a JSON text to produce an object or array.
110
+ It can throw a SyntaxError exception.
111
+
112
+ The optional reviver parameter is a function that can filter and
113
+ transform the results. It receives each of the keys and values,
114
+ and its return value is used instead of the original value.
115
+ If it returns what it received, then the structure is not modified.
116
+ If it returns undefined then the member is deleted.
117
+
118
+ Example:
119
+
120
+ // Parse the text. Values that look like ISO date strings will
121
+ // be converted to Date objects.
122
+
123
+ myData = JSON.parse(text, function (key, value) {
124
+ var a;
125
+ if (typeof value === 'string') {
126
+ a =
127
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
128
+ if (a) {
129
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
130
+ +a[5], +a[6]));
131
+ }
132
+ }
133
+ return value;
134
+ });
135
+
136
+ myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
137
+ var d;
138
+ if (typeof value === 'string' &&
139
+ value.slice(0, 5) === 'Date(' &&
140
+ value.slice(-1) === ')') {
141
+ d = new Date(value.slice(5, -1));
142
+ if (d) {
143
+ return d;
144
+ }
145
+ }
146
+ return value;
147
+ });
148
+
149
+
150
+ This is a reference implementation. You are free to copy, modify, or
151
+ redistribute.
152
+ */
153
+
154
+ /*jslint evil: true, regexp: true */
155
+
156
+ /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
157
+ call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
158
+ getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
159
+ lastIndex, length, parse, prototype, push, replace, slice, stringify,
160
+ test, toJSON, toString, valueOf
161
+ */
162
+
163
+
164
+ // Create a JSON object only if one does not already exist. We create the
165
+ // methods in a closure to avoid creating global variables.
166
+
167
+ var JSON;
168
+ if (!JSON) {
169
+ JSON = {};
170
+ }
171
+
172
+ (function () {
173
+ 'use strict';
174
+
175
+ function f(n) {
176
+ // Format integers to have at least two digits.
177
+ return n < 10 ? '0' + n : n;
178
+ }
179
+
180
+ if (typeof Date.prototype.toJSON !== 'function') {
181
+
182
+ Date.prototype.toJSON = function (key) {
183
+
184
+ return isFinite(this.valueOf())
185
+ ? this.getUTCFullYear() + '-' +
186
+ f(this.getUTCMonth() + 1) + '-' +
187
+ f(this.getUTCDate()) + 'T' +
188
+ f(this.getUTCHours()) + ':' +
189
+ f(this.getUTCMinutes()) + ':' +
190
+ f(this.getUTCSeconds()) + 'Z'
191
+ : null;
192
+ };
193
+
194
+ String.prototype.toJSON =
195
+ Number.prototype.toJSON =
196
+ Boolean.prototype.toJSON = function (key) {
197
+ return this.valueOf();
198
+ };
199
+ }
200
+
201
+ var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
202
+ escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
203
+ gap,
204
+ indent,
205
+ meta = { // table of character substitutions
206
+ '\b': '\\b',
207
+ '\t': '\\t',
208
+ '\n': '\\n',
209
+ '\f': '\\f',
210
+ '\r': '\\r',
211
+ '"' : '\\"',
212
+ '\\': '\\\\'
213
+ },
214
+ rep;
215
+
216
+
217
+ function quote(string) {
218
+
219
+ // If the string contains no control characters, no quote characters, and no
220
+ // backslash characters, then we can safely slap some quotes around it.
221
+ // Otherwise we must also replace the offending characters with safe escape
222
+ // sequences.
223
+
224
+ escapable.lastIndex = 0;
225
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
226
+ var c = meta[a];
227
+ return typeof c === 'string'
228
+ ? c
229
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
230
+ }) + '"' : '"' + string + '"';
231
+ }
232
+
233
+
234
+ function str(key, holder) {
235
+
236
+ // Produce a string from holder[key].
237
+
238
+ var i, // The loop counter.
239
+ k, // The member key.
240
+ v, // The member value.
241
+ length,
242
+ mind = gap,
243
+ partial,
244
+ value = holder[key];
245
+
246
+ // If the value has a toJSON method, call it to obtain a replacement value.
247
+
248
+ if (value && typeof value === 'object' &&
249
+ typeof value.toJSON === 'function') {
250
+ value = value.toJSON(key);
251
+ }
252
+
253
+ // If we were called with a replacer function, then call the replacer to
254
+ // obtain a replacement value.
255
+
256
+ if (typeof rep === 'function') {
257
+ value = rep.call(holder, key, value);
258
+ }
259
+
260
+ // What happens next depends on the value's type.
261
+
262
+ switch (typeof value) {
263
+ case 'string':
264
+ return quote(value);
265
+
266
+ case 'number':
267
+
268
+ // JSON numbers must be finite. Encode non-finite numbers as null.
269
+
270
+ return isFinite(value) ? String(value) : 'null';
271
+
272
+ case 'boolean':
273
+ case 'null':
274
+
275
+ // If the value is a boolean or null, convert it to a string. Note:
276
+ // typeof null does not produce 'null'. The case is included here in
277
+ // the remote chance that this gets fixed someday.
278
+
279
+ return String(value);
280
+
281
+ // If the type is 'object', we might be dealing with an object or an array or
282
+ // null.
283
+
284
+ case 'object':
285
+
286
+ // Due to a specification blunder in ECMAScript, typeof null is 'object',
287
+ // so watch out for that case.
288
+
289
+ if (!value) {
290
+ return 'null';
291
+ }
292
+
293
+ // Make an array to hold the partial results of stringifying this object value.
294
+
295
+ gap += indent;
296
+ partial = [];
297
+
298
+ // Is the value an array?
299
+
300
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
301
+
302
+ // The value is an array. Stringify every element. Use null as a placeholder
303
+ // for non-JSON values.
304
+
305
+ length = value.length;
306
+ for (i = 0; i < length; i += 1) {
307
+ partial[i] = str(i, value) || 'null';
308
+ }
309
+
310
+ // Join all of the elements together, separated with commas, and wrap them in
311
+ // brackets.
312
+
313
+ v = partial.length === 0
314
+ ? '[]'
315
+ : gap
316
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
317
+ : '[' + partial.join(',') + ']';
318
+ gap = mind;
319
+ return v;
320
+ }
321
+
322
+ // If the replacer is an array, use it to select the members to be stringified.
323
+
324
+ if (rep && typeof rep === 'object') {
325
+ length = rep.length;
326
+ for (i = 0; i < length; i += 1) {
327
+ if (typeof rep[i] === 'string') {
328
+ k = rep[i];
329
+ v = str(k, value);
330
+ if (v) {
331
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
332
+ }
333
+ }
334
+ }
335
+ } else {
336
+
337
+ // Otherwise, iterate through all of the keys in the object.
338
+
339
+ for (k in value) {
340
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
341
+ v = str(k, value);
342
+ if (v) {
343
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
344
+ }
345
+ }
346
+ }
347
+ }
348
+
349
+ // Join all of the member texts together, separated with commas,
350
+ // and wrap them in braces.
351
+
352
+ v = partial.length === 0
353
+ ? '{}'
354
+ : gap
355
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
356
+ : '{' + partial.join(',') + '}';
357
+ gap = mind;
358
+ return v;
359
+ }
360
+ }
361
+
362
+ // If the JSON object does not yet have a stringify method, give it one.
363
+
364
+ if (typeof JSON.stringify !== 'function') {
365
+ JSON.stringify = function (value, replacer, space) {
366
+
367
+ // The stringify method takes a value and an optional replacer, and an optional
368
+ // space parameter, and returns a JSON text. The replacer can be a function
369
+ // that can replace values, or an array of strings that will select the keys.
370
+ // A default replacer method can be provided. Use of the space parameter can
371
+ // produce text that is more easily readable.
372
+
373
+ var i;
374
+ gap = '';
375
+ indent = '';
376
+
377
+ // If the space parameter is a number, make an indent string containing that
378
+ // many spaces.
379
+
380
+ if (typeof space === 'number') {
381
+ for (i = 0; i < space; i += 1) {
382
+ indent += ' ';
383
+ }
384
+
385
+ // If the space parameter is a string, it will be used as the indent string.
386
+
387
+ } else if (typeof space === 'string') {
388
+ indent = space;
389
+ }
390
+
391
+ // If there is a replacer, it must be a function or an array.
392
+ // Otherwise, throw an error.
393
+
394
+ rep = replacer;
395
+ if (replacer && typeof replacer !== 'function' &&
396
+ (typeof replacer !== 'object' ||
397
+ typeof replacer.length !== 'number')) {
398
+ throw new Error('JSON.stringify');
399
+ }
400
+
401
+ // Make a fake root object containing our value under the key of ''.
402
+ // Return the result of stringifying the value.
403
+
404
+ return str('', {'': value});
405
+ };
406
+ }
407
+
408
+
409
+ // If the JSON object does not yet have a parse method, give it one.
410
+
411
+ if (typeof JSON.parse !== 'function') {
412
+ JSON.parse = function (text, reviver) {
413
+
414
+ // The parse method takes a text and an optional reviver function, and returns
415
+ // a JavaScript value if the text is a valid JSON text.
416
+
417
+ var j;
418
+
419
+ function walk(holder, key) {
420
+
421
+ // The walk method is used to recursively walk the resulting structure so
422
+ // that modifications can be made.
423
+
424
+ var k, v, value = holder[key];
425
+ if (value && typeof value === 'object') {
426
+ for (k in value) {
427
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
428
+ v = walk(value, k);
429
+ if (v !== undefined) {
430
+ value[k] = v;
431
+ } else {
432
+ delete value[k];
433
+ }
434
+ }
435
+ }
436
+ }
437
+ return reviver.call(holder, key, value);
438
+ }
439
+
440
+
441
+ // Parsing happens in four stages. In the first stage, we replace certain
442
+ // Unicode characters with escape sequences. JavaScript handles many characters
443
+ // incorrectly, either silently deleting them, or treating them as line endings.
444
+
445
+ text = String(text);
446
+ cx.lastIndex = 0;
447
+ if (cx.test(text)) {
448
+ text = text.replace(cx, function (a) {
449
+ return '\\u' +
450
+ ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
451
+ });
452
+ }
453
+
454
+ // In the second stage, we run the text against regular expressions that look
455
+ // for non-JSON patterns. We are especially concerned with '()' and 'new'
456
+ // because they can cause invocation, and '=' because it can cause mutation.
457
+ // But just to be safe, we want to reject all unexpected forms.
458
+
459
+ // We split the second stage into 4 regexp operations in order to work around
460
+ // crippling inefficiencies in IE's and Safari's regexp engines. First we
461
+ // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
462
+ // replace all simple value tokens with ']' characters. Third, we delete all
463
+ // open brackets that follow a colon or comma or that begin the text. Finally,
464
+ // we look to see that the remaining characters are only whitespace or ']' or
465
+ // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
466
+
467
+ if (/^[\],:{}\s]*$/
468
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
469
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
470
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
471
+
472
+ // In the third stage we use the eval function to compile the text into a
473
+ // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
474
+ // in JavaScript: it can begin a block or an object literal. We wrap the text
475
+ // in parens to eliminate the ambiguity.
476
+
477
+ j = eval('(' + text + ')');
478
+
479
+ // In the optional fourth stage, we recursively walk the new structure, passing
480
+ // each name/value pair to a reviver function for possible transformation.
481
+
482
+ return typeof reviver === 'function'
483
+ ? walk({'': j}, '')
484
+ : j;
485
+ }
486
+
487
+ // If the text is not JSON parseable, then a SyntaxError is thrown.
488
+
489
+ throw new SyntaxError('JSON.parse');
490
+ };
491
+ }
492
+ }());
493
+
494
+