iqvoc 3.3.1 → 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +101 -0
- data/app/assets/javascripts/framework.js +1 -0
- data/app/assets/stylesheets/framework.css +2 -0
- data/app/views/layouts/application.html.erb +2 -11
- data/iqvoc.gemspec +2 -1
- data/lib/iqvoc.rb +0 -3
- data/lib/iqvoc/version.rb +1 -1
- data/public/assets/blueprint/ie-0761b92d02baf44f0b2011e3009e6aa9.css.gz +0 -0
- data/public/assets/blueprint/ie.css.gz +0 -0
- data/public/assets/iqvoc/ie_fixes-7a001f31445ddfb2e0668c419f81742f.css.gz +0 -0
- data/public/assets/iqvoc/ie_fixes.css.gz +0 -0
- data/public/assets/manifest-6f0772f7ec93cc20de428ae859353e92.js +21 -0
- data/public/assets/manifest-6f0772f7ec93cc20de428ae859353e92.js.gz +0 -0
- data/public/assets/manifest-d52be2520b68121c73695e4026876a98.css +1421 -0
- data/public/assets/manifest-d52be2520b68121c73695e4026876a98.css.gz +0 -0
- data/public/assets/manifest.css +295 -0
- data/public/assets/manifest.css.gz +0 -0
- data/public/assets/manifest.js +2 -2
- data/public/assets/manifest.js.gz +0 -0
- data/public/assets/manifest.yml +2 -5
- data/vendor/assets/images/ajax-loader.gif +0 -0
- data/vendor/assets/images/file.gif +0 -0
- data/vendor/assets/images/folder-closed.gif +0 -0
- data/vendor/assets/images/folder.gif +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_flat_55_fbec88_40x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_85_dfeffc_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_217bc0_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_2e83ff_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_469bdd_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_6da8d5_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_cd0a0a_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_d8e7f3_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_f9bd01_256x240.png +0 -0
- data/vendor/assets/images/minus.gif +0 -0
- data/vendor/assets/images/plus.gif +0 -0
- data/vendor/assets/images/treeview-black-line.gif +0 -0
- data/vendor/assets/images/treeview-black.gif +0 -0
- data/vendor/assets/images/treeview-default-line.gif +0 -0
- data/vendor/assets/images/treeview-default.gif +0 -0
- data/vendor/assets/images/treeview-famfamfam-line.gif +0 -0
- data/vendor/assets/images/treeview-famfamfam.gif +0 -0
- data/vendor/assets/images/treeview-gray-line.gif +0 -0
- data/vendor/assets/images/treeview-gray.gif +0 -0
- data/vendor/assets/images/treeview-red-line.gif +0 -0
- data/vendor/assets/images/treeview-red.gif +0 -0
- data/vendor/assets/javascripts/excanvas.js +35 -0
- data/vendor/assets/javascripts/jit_rgraph.js +153 -0
- data/vendor/assets/javascripts/jquery-1.7.1.js +9266 -0
- data/vendor/assets/javascripts/jquery-ui-1.8.16.custom.js +3269 -0
- data/vendor/assets/javascripts/jquery-ui.datepicker-de.js +22 -0
- data/vendor/assets/javascripts/jquery.treeview.async.js +82 -0
- data/vendor/assets/javascripts/jquery.treeview.js +251 -0
- data/vendor/assets/javascripts/json2.js +485 -0
- data/vendor/assets/javascripts/rails.js +373 -0
- data/vendor/assets/javascripts/storage.js +122 -0
- data/vendor/assets/stylesheets/blueprint/ie.css +35 -0
- data/vendor/assets/stylesheets/blueprint/print.css +33 -0
- data/vendor/assets/stylesheets/blueprint/screen.css +262 -0
- data/vendor/assets/stylesheets/jquery-ui-1.8.16.custom.css +410 -0
- data/vendor/assets/stylesheets/jquery.treeview.css.erb +75 -0
- metadata +68 -17
@@ -0,0 +1,22 @@
|
|
1
|
+
/* German initialisation for the jQuery UI date picker plugin. */
|
2
|
+
/* Written by Milian Wolff (mail@milianw.de). */
|
3
|
+
jQuery(function($){
|
4
|
+
$.datepicker.regional['de'] = {
|
5
|
+
closeText: 'schließen',
|
6
|
+
prevText: '<zurück',
|
7
|
+
nextText: 'Vor>',
|
8
|
+
currentText: 'heute',
|
9
|
+
monthNames: ['Januar','Februar','März','April','Mai','Juni',
|
10
|
+
'Juli','August','September','Oktober','November','Dezember'],
|
11
|
+
monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
|
12
|
+
'Jul','Aug','Sep','Okt','Nov','Dez'],
|
13
|
+
dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
|
14
|
+
dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
|
15
|
+
dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
|
16
|
+
weekHeader: 'Wo',
|
17
|
+
dateFormat: 'yy-mm-dd',
|
18
|
+
firstDay: 1,
|
19
|
+
isRTL: false,
|
20
|
+
showMonthAfterYear: false,
|
21
|
+
yearSuffix: ''};
|
22
|
+
});
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
* Async Treeview 0.1 - Lazy-loading extension for Treeview
|
3
|
+
*
|
4
|
+
* http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
|
5
|
+
*
|
6
|
+
* Copyright (c) 2007 Jörn Zaefferer
|
7
|
+
*
|
8
|
+
* Dual licensed under the MIT and GPL licenses:
|
9
|
+
* http://www.opensource.org/licenses/mit-license.php
|
10
|
+
* http://www.gnu.org/licenses/gpl.html
|
11
|
+
*
|
12
|
+
* Revision: $Id$
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
|
16
|
+
;
|
17
|
+
(function($) {
|
18
|
+
|
19
|
+
function load(settings, root, child, container) {
|
20
|
+
function createNode(parent) {
|
21
|
+
var current = $("<li/>").attr("id", this.id || "").html("<a href=\"" + this.url + "\" class=\"" + (this.classes || "") + "\">" + this.text + "</a>" + (this.additionalText ? this.additionalText : "")).appendTo(parent);
|
22
|
+
if (this.classes) {
|
23
|
+
current.children("span").addClass(this.classes);
|
24
|
+
}
|
25
|
+
if (this.expanded) {
|
26
|
+
current.addClass("open");
|
27
|
+
}
|
28
|
+
if (this.hasChildren || this.children && this.children.length) {
|
29
|
+
var branch = $("<ul/>").appendTo(current);
|
30
|
+
if (this.hasChildren) {
|
31
|
+
current.addClass("hasChildren");
|
32
|
+
createNode.call({
|
33
|
+
classes: "placeholder",
|
34
|
+
text: " ",
|
35
|
+
children:[]
|
36
|
+
}, branch);
|
37
|
+
}
|
38
|
+
if (this.children && this.children.length) {
|
39
|
+
$.each(this.children, createNode, [branch])
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
$.ajax($.extend(true, {
|
44
|
+
url: settings.url,
|
45
|
+
dataType: "json",
|
46
|
+
data: {
|
47
|
+
root: root
|
48
|
+
},
|
49
|
+
success: function(response) {
|
50
|
+
child.empty();
|
51
|
+
$.each(response, createNode, [child]);
|
52
|
+
$(container).treeview({add: child});
|
53
|
+
}
|
54
|
+
}, settings.ajax));
|
55
|
+
}
|
56
|
+
|
57
|
+
$.fn.treeviewLoad = load;
|
58
|
+
|
59
|
+
var proxied = $.fn.treeview;
|
60
|
+
$.fn.treeview = function(settings) {
|
61
|
+
if (!settings.url) {
|
62
|
+
return proxied.apply(this, arguments);
|
63
|
+
}
|
64
|
+
var container = this;
|
65
|
+
if (!container.children().size())
|
66
|
+
load(settings, (settings.root || "source"), this, container);
|
67
|
+
var userToggle = settings.toggle;
|
68
|
+
return proxied.call(this, $.extend({}, settings, {
|
69
|
+
collapsed: true,
|
70
|
+
toggle: function() {
|
71
|
+
var $this = $(this);
|
72
|
+
if ($this.hasClass("hasChildren")) {
|
73
|
+
var childList = $this.removeClass("hasChildren").find("ul");
|
74
|
+
load(settings, this.id, childList, container);
|
75
|
+
}
|
76
|
+
if (userToggle) {
|
77
|
+
userToggle.apply(this, arguments);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}));
|
81
|
+
};
|
82
|
+
})(jQuery);
|
@@ -0,0 +1,251 @@
|
|
1
|
+
/*
|
2
|
+
* Treeview 1.4 - jQuery plugin to hide and show branches of a tree
|
3
|
+
*
|
4
|
+
* http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
|
5
|
+
* http://docs.jquery.com/Plugins/Treeview
|
6
|
+
*
|
7
|
+
* Copyright (c) 2007 Jörn Zaefferer
|
8
|
+
*
|
9
|
+
* Dual licensed under the MIT and GPL licenses:
|
10
|
+
* http://www.opensource.org/licenses/mit-license.php
|
11
|
+
* http://www.gnu.org/licenses/gpl.html
|
12
|
+
*
|
13
|
+
* Revision: $Id: jquery.treeview.js 4684 2008-02-07 19:08:06Z joern.zaefferer $
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
|
17
|
+
;(function($) {
|
18
|
+
|
19
|
+
$.extend($.fn, {
|
20
|
+
swapClass: function(c1, c2) {
|
21
|
+
var c1Elements = this.filter('.' + c1);
|
22
|
+
this.filter('.' + c2).removeClass(c2).addClass(c1);
|
23
|
+
c1Elements.removeClass(c1).addClass(c2);
|
24
|
+
return this;
|
25
|
+
},
|
26
|
+
replaceClass: function(c1, c2) {
|
27
|
+
return this.filter('.' + c1).removeClass(c1).addClass(c2).end();
|
28
|
+
},
|
29
|
+
hoverClass: function(className) {
|
30
|
+
className = className || "hover";
|
31
|
+
return this.hover(function() {
|
32
|
+
$(this).addClass(className);
|
33
|
+
}, function() {
|
34
|
+
$(this).removeClass(className);
|
35
|
+
});
|
36
|
+
},
|
37
|
+
heightToggle: function(animated, callback) {
|
38
|
+
animated ?
|
39
|
+
this.animate({ height: "toggle" }, animated, callback) :
|
40
|
+
this.each(function(){
|
41
|
+
jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
|
42
|
+
if(callback)
|
43
|
+
callback.apply(this, arguments);
|
44
|
+
});
|
45
|
+
},
|
46
|
+
heightHide: function(animated, callback) {
|
47
|
+
if (animated) {
|
48
|
+
this.animate({ height: "hide" }, animated, callback);
|
49
|
+
} else {
|
50
|
+
this.hide();
|
51
|
+
if (callback)
|
52
|
+
this.each(callback);
|
53
|
+
}
|
54
|
+
},
|
55
|
+
prepareBranches: function(settings) {
|
56
|
+
if (!settings.prerendered) {
|
57
|
+
// mark last tree items
|
58
|
+
this.filter(":last-child:not(ul)").addClass(CLASSES.last);
|
59
|
+
// collapse whole tree, or only those marked as closed, anyway except those marked as open
|
60
|
+
this.filter((settings.collapsed ? "" : "." + CLASSES.closed) + ":not(." + CLASSES.open + ")").find(">ul").hide();
|
61
|
+
}
|
62
|
+
// return all items with sublists
|
63
|
+
return this.filter(":has(>ul)");
|
64
|
+
},
|
65
|
+
applyClasses: function(settings, toggler) {
|
66
|
+
this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
|
67
|
+
toggler.apply($(this).next());
|
68
|
+
}).add( $("a", this) ).hoverClass();
|
69
|
+
|
70
|
+
if (!settings.prerendered) {
|
71
|
+
// handle closed ones first
|
72
|
+
this.filter(":has(>ul:hidden)")
|
73
|
+
.addClass(CLASSES.expandable)
|
74
|
+
.replaceClass(CLASSES.last, CLASSES.lastExpandable);
|
75
|
+
|
76
|
+
// handle open ones
|
77
|
+
this.not(":has(>ul:hidden)")
|
78
|
+
.addClass(CLASSES.collapsable)
|
79
|
+
.replaceClass(CLASSES.last, CLASSES.lastCollapsable);
|
80
|
+
|
81
|
+
// create hitarea
|
82
|
+
this.prepend("<div class=\"" + CLASSES.hitarea + "\"/>").find("div." + CLASSES.hitarea).each(function() {
|
83
|
+
var classes = "";
|
84
|
+
$.each($(this).parent().attr("class").split(" "), function() {
|
85
|
+
classes += this + "-hitarea ";
|
86
|
+
});
|
87
|
+
$(this).addClass( classes );
|
88
|
+
});
|
89
|
+
}
|
90
|
+
|
91
|
+
// apply event to hitarea
|
92
|
+
this.find("div." + CLASSES.hitarea).click( toggler );
|
93
|
+
},
|
94
|
+
treeview: function(settings) {
|
95
|
+
|
96
|
+
settings = $.extend({
|
97
|
+
cookieId: "treeview"
|
98
|
+
}, settings);
|
99
|
+
|
100
|
+
if (settings.add) {
|
101
|
+
return this.trigger("add", [settings.add]);
|
102
|
+
}
|
103
|
+
|
104
|
+
if ( settings.toggle ) {
|
105
|
+
var callback = settings.toggle;
|
106
|
+
settings.toggle = function() {
|
107
|
+
return callback.apply($(this).parent()[0], arguments);
|
108
|
+
};
|
109
|
+
}
|
110
|
+
|
111
|
+
// factory for treecontroller
|
112
|
+
function treeController(tree, control) {
|
113
|
+
// factory for click handlers
|
114
|
+
function handler(filter) {
|
115
|
+
return function() {
|
116
|
+
// reuse toggle event handler, applying the elements to toggle
|
117
|
+
// start searching for all hitareas
|
118
|
+
toggler.apply( $("div." + CLASSES.hitarea, tree).filter(function() {
|
119
|
+
// for plain toggle, no filter is provided, otherwise we need to check the parent element
|
120
|
+
return filter ? $(this).parent("." + filter).length : true;
|
121
|
+
}) );
|
122
|
+
return false;
|
123
|
+
};
|
124
|
+
}
|
125
|
+
// click on first element to collapse tree
|
126
|
+
$("a:eq(0)", control).click( handler(CLASSES.collapsable) );
|
127
|
+
// click on second to expand tree
|
128
|
+
$("a:eq(1)", control).click( handler(CLASSES.expandable) );
|
129
|
+
// click on third to toggle tree
|
130
|
+
$("a:eq(2)", control).click( handler() );
|
131
|
+
}
|
132
|
+
|
133
|
+
// handle toggle event
|
134
|
+
function toggler() {
|
135
|
+
$(this)
|
136
|
+
.parent()
|
137
|
+
// swap classes for hitarea
|
138
|
+
.find(">.hitarea")
|
139
|
+
.swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
|
140
|
+
.swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
|
141
|
+
.end()
|
142
|
+
// swap classes for parent li
|
143
|
+
.swapClass( CLASSES.collapsable, CLASSES.expandable )
|
144
|
+
.swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
|
145
|
+
// find child lists
|
146
|
+
.find( ">ul" )
|
147
|
+
// toggle them
|
148
|
+
.heightToggle( settings.animated, settings.toggle );
|
149
|
+
if ( settings.unique ) {
|
150
|
+
$(this).parent()
|
151
|
+
.siblings()
|
152
|
+
// swap classes for hitarea
|
153
|
+
.find(">.hitarea")
|
154
|
+
.replaceClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
|
155
|
+
.replaceClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
|
156
|
+
.end()
|
157
|
+
.replaceClass( CLASSES.collapsable, CLASSES.expandable )
|
158
|
+
.replaceClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
|
159
|
+
.find( ">ul" )
|
160
|
+
.heightHide( settings.animated, settings.toggle );
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
function serialize() {
|
165
|
+
function binary(arg) {
|
166
|
+
return arg ? 1 : 0;
|
167
|
+
}
|
168
|
+
var data = [];
|
169
|
+
branches.each(function(i, e) {
|
170
|
+
data[i] = $(e).is(":has(>ul:visible)") ? 1 : 0;
|
171
|
+
});
|
172
|
+
$.cookie(settings.cookieId, data.join("") );
|
173
|
+
}
|
174
|
+
|
175
|
+
function deserialize() {
|
176
|
+
var stored = $.cookie(settings.cookieId);
|
177
|
+
if ( stored ) {
|
178
|
+
var data = stored.split("");
|
179
|
+
branches.each(function(i, e) {
|
180
|
+
$(e).find(">ul")[ parseInt(data[i]) ? "show" : "hide" ]();
|
181
|
+
});
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
// add treeview class to activate styles
|
186
|
+
this.addClass("treeview");
|
187
|
+
|
188
|
+
// prepare branches and find all tree items with child lists
|
189
|
+
var branches = this.find("li").prepareBranches(settings);
|
190
|
+
|
191
|
+
switch(settings.persist) {
|
192
|
+
case "cookie":
|
193
|
+
var toggleCallback = settings.toggle;
|
194
|
+
settings.toggle = function() {
|
195
|
+
serialize();
|
196
|
+
if (toggleCallback) {
|
197
|
+
toggleCallback.apply(this, arguments);
|
198
|
+
}
|
199
|
+
};
|
200
|
+
deserialize();
|
201
|
+
break;
|
202
|
+
case "location":
|
203
|
+
var current = this.find("a").filter(function() { return this.href.toLowerCase() == location.href.toLowerCase(); });
|
204
|
+
if ( current.length ) {
|
205
|
+
current.addClass("selected").parents("ul, li").add( current.next() ).show();
|
206
|
+
}
|
207
|
+
break;
|
208
|
+
}
|
209
|
+
|
210
|
+
branches.applyClasses(settings, toggler);
|
211
|
+
|
212
|
+
// if control option is set, create the treecontroller and show it
|
213
|
+
if ( settings.control ) {
|
214
|
+
treeController(this, settings.control);
|
215
|
+
$(settings.control).show();
|
216
|
+
}
|
217
|
+
|
218
|
+
return this.bind("add", function(event, branches) {
|
219
|
+
$(branches).prev()
|
220
|
+
.removeClass(CLASSES.last)
|
221
|
+
.removeClass(CLASSES.lastCollapsable)
|
222
|
+
.removeClass(CLASSES.lastExpandable)
|
223
|
+
.find(">.hitarea")
|
224
|
+
.removeClass(CLASSES.lastCollapsableHitarea)
|
225
|
+
.removeClass(CLASSES.lastExpandableHitarea);
|
226
|
+
$(branches).find("li").andSelf().prepareBranches(settings).applyClasses(settings, toggler);
|
227
|
+
});
|
228
|
+
}
|
229
|
+
});
|
230
|
+
|
231
|
+
// classes used by the plugin
|
232
|
+
// need to be styled via external stylesheet, see first example
|
233
|
+
var CLASSES = $.fn.treeview.classes = {
|
234
|
+
open: "open",
|
235
|
+
closed: "closed",
|
236
|
+
expandable: "expandable",
|
237
|
+
expandableHitarea: "expandable-hitarea",
|
238
|
+
lastExpandableHitarea: "lastExpandable-hitarea",
|
239
|
+
collapsable: "collapsable",
|
240
|
+
collapsableHitarea: "collapsable-hitarea",
|
241
|
+
lastCollapsableHitarea: "lastCollapsable-hitarea",
|
242
|
+
lastCollapsable: "lastCollapsable",
|
243
|
+
lastExpandable: "lastExpandable",
|
244
|
+
last: "last",
|
245
|
+
hitarea: "hitarea"
|
246
|
+
};
|
247
|
+
|
248
|
+
// provide backwards compability
|
249
|
+
$.fn.Treeview = $.fn.treeview;
|
250
|
+
|
251
|
+
})(jQuery);
|
@@ -0,0 +1,485 @@
|
|
1
|
+
/*
|
2
|
+
http://www.JSON.org/json2.js
|
3
|
+
2011-02-23
|
4
|
+
|
5
|
+
Public Domain.
|
6
|
+
|
7
|
+
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
8
|
+
|
9
|
+
See http://www.JSON.org/js.html
|
10
|
+
|
11
|
+
|
12
|
+
This code should be minified before deployment.
|
13
|
+
See http://javascript.crockford.com/jsmin.html
|
14
|
+
|
15
|
+
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
16
|
+
NOT CONTROL.
|
17
|
+
|
18
|
+
|
19
|
+
This file creates a global JSON object containing two methods: stringify
|
20
|
+
and parse.
|
21
|
+
|
22
|
+
JSON.stringify(value, replacer, space)
|
23
|
+
value any JavaScript value, usually an object or array.
|
24
|
+
|
25
|
+
replacer an optional parameter that determines how object
|
26
|
+
values are stringified for objects. It can be a
|
27
|
+
function or an array of strings.
|
28
|
+
|
29
|
+
space an optional parameter that specifies the indentation
|
30
|
+
of nested structures. If it is omitted, the text will
|
31
|
+
be packed without extra whitespace. If it is a number,
|
32
|
+
it will specify the number of spaces to indent at each
|
33
|
+
level. If it is a string (such as '\t' or ' '),
|
34
|
+
it contains the characters used to indent at each level.
|
35
|
+
|
36
|
+
This method produces a JSON text from a JavaScript value.
|
37
|
+
|
38
|
+
When an object value is found, if the object contains a toJSON
|
39
|
+
method, its toJSON method will be called and the result will be
|
40
|
+
stringified. A toJSON method does not serialize: it returns the
|
41
|
+
value represented by the name/value pair that should be serialized,
|
42
|
+
or undefined if nothing should be serialized. The toJSON method
|
43
|
+
will be passed the key associated with the value, and this will be
|
44
|
+
bound to the value
|
45
|
+
|
46
|
+
For example, this would serialize Dates as ISO strings.
|
47
|
+
|
48
|
+
Date.prototype.toJSON = function (key) {
|
49
|
+
function f(n) {
|
50
|
+
// Format integers to have at least two digits.
|
51
|
+
return n < 10 ? '0' + n : n;
|
52
|
+
}
|
53
|
+
|
54
|
+
return this.getUTCFullYear() + '-' +
|
55
|
+
f(this.getUTCMonth() + 1) + '-' +
|
56
|
+
f(this.getUTCDate()) + 'T' +
|
57
|
+
f(this.getUTCHours()) + ':' +
|
58
|
+
f(this.getUTCMinutes()) + ':' +
|
59
|
+
f(this.getUTCSeconds()) + 'Z';
|
60
|
+
};
|
61
|
+
|
62
|
+
You can provide an optional replacer method. It will be passed the
|
63
|
+
key and value of each member, with this bound to the containing
|
64
|
+
object. The value that is returned from your method will be
|
65
|
+
serialized. If your method returns undefined, then the member will
|
66
|
+
be excluded from the serialization.
|
67
|
+
|
68
|
+
If the replacer parameter is an array of strings, then it will be
|
69
|
+
used to select the members to be serialized. It filters the results
|
70
|
+
such that only members with keys listed in the replacer array are
|
71
|
+
stringified.
|
72
|
+
|
73
|
+
Values that do not have JSON representations, such as undefined or
|
74
|
+
functions, will not be serialized. Such values in objects will be
|
75
|
+
dropped; in arrays they will be replaced with null. You can use
|
76
|
+
a replacer function to replace those with JSON values.
|
77
|
+
JSON.stringify(undefined) returns undefined.
|
78
|
+
|
79
|
+
The optional space parameter produces a stringification of the
|
80
|
+
value that is filled with line breaks and indentation to make it
|
81
|
+
easier to read.
|
82
|
+
|
83
|
+
If the space parameter is a non-empty string, then that string will
|
84
|
+
be used for indentation. If the space parameter is a number, then
|
85
|
+
the indentation will be that many spaces.
|
86
|
+
|
87
|
+
Example:
|
88
|
+
|
89
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
90
|
+
// text is '["e",{"pluribus":"unum"}]'
|
91
|
+
|
92
|
+
|
93
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
94
|
+
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
95
|
+
|
96
|
+
text = JSON.stringify([new Date()], function (key, value) {
|
97
|
+
return this[key] instanceof Date ?
|
98
|
+
'Date(' + this[key] + ')' : value;
|
99
|
+
});
|
100
|
+
// text is '["Date(---current time---)"]'
|
101
|
+
|
102
|
+
|
103
|
+
JSON.parse(text, reviver)
|
104
|
+
This method parses a JSON text to produce an object or array.
|
105
|
+
It can throw a SyntaxError exception.
|
106
|
+
|
107
|
+
The optional reviver parameter is a function that can filter and
|
108
|
+
transform the results. It receives each of the keys and values,
|
109
|
+
and its return value is used instead of the original value.
|
110
|
+
If it returns what it received, then the structure is not modified.
|
111
|
+
If it returns undefined then the member is deleted.
|
112
|
+
|
113
|
+
Example:
|
114
|
+
|
115
|
+
// Parse the text. Values that look like ISO date strings will
|
116
|
+
// be converted to Date objects.
|
117
|
+
|
118
|
+
myData = JSON.parse(text, function (key, value) {
|
119
|
+
var a;
|
120
|
+
if (typeof value === 'string') {
|
121
|
+
a =
|
122
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
123
|
+
if (a) {
|
124
|
+
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
125
|
+
+a[5], +a[6]));
|
126
|
+
}
|
127
|
+
}
|
128
|
+
return value;
|
129
|
+
});
|
130
|
+
|
131
|
+
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
132
|
+
var d;
|
133
|
+
if (typeof value === 'string' &&
|
134
|
+
value.slice(0, 5) === 'Date(' &&
|
135
|
+
value.slice(-1) === ')') {
|
136
|
+
d = new Date(value.slice(5, -1));
|
137
|
+
if (d) {
|
138
|
+
return d;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
return value;
|
142
|
+
});
|
143
|
+
|
144
|
+
|
145
|
+
This is a reference implementation. You are free to copy, modify, or
|
146
|
+
redistribute.
|
147
|
+
*/
|
148
|
+
|
149
|
+
/*jslint evil: true, strict: false, regexp: false */
|
150
|
+
|
151
|
+
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
152
|
+
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
153
|
+
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
154
|
+
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
155
|
+
test, toJSON, toString, valueOf
|
156
|
+
*/
|
157
|
+
|
158
|
+
|
159
|
+
// Create a JSON object only if one does not already exist. We create the
|
160
|
+
// methods in a closure to avoid creating global variables.
|
161
|
+
|
162
|
+
// load JSON polyfill only if necessary
|
163
|
+
if (typeof JSON === "undefined") {
|
164
|
+
|
165
|
+
var JSON;
|
166
|
+
if (!JSON) {
|
167
|
+
JSON = {};
|
168
|
+
}
|
169
|
+
|
170
|
+
(function () {
|
171
|
+
"use strict";
|
172
|
+
|
173
|
+
function f(n) {
|
174
|
+
// Format integers to have at least two digits.
|
175
|
+
return n < 10 ? '0' + n : n;
|
176
|
+
}
|
177
|
+
|
178
|
+
if (typeof Date.prototype.toJSON !== 'function') {
|
179
|
+
|
180
|
+
Date.prototype.toJSON = function (key) {
|
181
|
+
|
182
|
+
return isFinite(this.valueOf()) ?
|
183
|
+
this.getUTCFullYear() + '-' +
|
184
|
+
f(this.getUTCMonth() + 1) + '-' +
|
185
|
+
f(this.getUTCDate()) + 'T' +
|
186
|
+
f(this.getUTCHours()) + ':' +
|
187
|
+
f(this.getUTCMinutes()) + ':' +
|
188
|
+
f(this.getUTCSeconds()) + 'Z' : null;
|
189
|
+
};
|
190
|
+
|
191
|
+
String.prototype.toJSON =
|
192
|
+
Number.prototype.toJSON =
|
193
|
+
Boolean.prototype.toJSON = function (key) {
|
194
|
+
return this.valueOf();
|
195
|
+
};
|
196
|
+
}
|
197
|
+
|
198
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
199
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
200
|
+
gap,
|
201
|
+
indent,
|
202
|
+
meta = { // table of character substitutions
|
203
|
+
'\b': '\\b',
|
204
|
+
'\t': '\\t',
|
205
|
+
'\n': '\\n',
|
206
|
+
'\f': '\\f',
|
207
|
+
'\r': '\\r',
|
208
|
+
'"' : '\\"',
|
209
|
+
'\\': '\\\\'
|
210
|
+
},
|
211
|
+
rep;
|
212
|
+
|
213
|
+
|
214
|
+
function quote(string) {
|
215
|
+
|
216
|
+
// If the string contains no control characters, no quote characters, and no
|
217
|
+
// backslash characters, then we can safely slap some quotes around it.
|
218
|
+
// Otherwise we must also replace the offending characters with safe escape
|
219
|
+
// sequences.
|
220
|
+
|
221
|
+
escapable.lastIndex = 0;
|
222
|
+
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
223
|
+
var c = meta[a];
|
224
|
+
return typeof c === 'string' ? c :
|
225
|
+
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
226
|
+
}) + '"' : '"' + string + '"';
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
function str(key, holder) {
|
231
|
+
|
232
|
+
// Produce a string from holder[key].
|
233
|
+
|
234
|
+
var i, // The loop counter.
|
235
|
+
k, // The member key.
|
236
|
+
v, // The member value.
|
237
|
+
length,
|
238
|
+
mind = gap,
|
239
|
+
partial,
|
240
|
+
value = holder[key];
|
241
|
+
|
242
|
+
// If the value has a toJSON method, call it to obtain a replacement value.
|
243
|
+
|
244
|
+
if (value && typeof value === 'object' &&
|
245
|
+
typeof value.toJSON === 'function') {
|
246
|
+
value = value.toJSON(key);
|
247
|
+
}
|
248
|
+
|
249
|
+
// If we were called with a replacer function, then call the replacer to
|
250
|
+
// obtain a replacement value.
|
251
|
+
|
252
|
+
if (typeof rep === 'function') {
|
253
|
+
value = rep.call(holder, key, value);
|
254
|
+
}
|
255
|
+
|
256
|
+
// What happens next depends on the value's type.
|
257
|
+
|
258
|
+
switch (typeof value) {
|
259
|
+
case 'string':
|
260
|
+
return quote(value);
|
261
|
+
|
262
|
+
case 'number':
|
263
|
+
|
264
|
+
// JSON numbers must be finite. Encode non-finite numbers as null.
|
265
|
+
|
266
|
+
return isFinite(value) ? String(value) : 'null';
|
267
|
+
|
268
|
+
case 'boolean':
|
269
|
+
case 'null':
|
270
|
+
|
271
|
+
// If the value is a boolean or null, convert it to a string. Note:
|
272
|
+
// typeof null does not produce 'null'. The case is included here in
|
273
|
+
// the remote chance that this gets fixed someday.
|
274
|
+
|
275
|
+
return String(value);
|
276
|
+
|
277
|
+
// If the type is 'object', we might be dealing with an object or an array or
|
278
|
+
// null.
|
279
|
+
|
280
|
+
case 'object':
|
281
|
+
|
282
|
+
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
283
|
+
// so watch out for that case.
|
284
|
+
|
285
|
+
if (!value) {
|
286
|
+
return 'null';
|
287
|
+
}
|
288
|
+
|
289
|
+
// Make an array to hold the partial results of stringifying this object value.
|
290
|
+
|
291
|
+
gap += indent;
|
292
|
+
partial = [];
|
293
|
+
|
294
|
+
// Is the value an array?
|
295
|
+
|
296
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
297
|
+
|
298
|
+
// The value is an array. Stringify every element. Use null as a placeholder
|
299
|
+
// for non-JSON values.
|
300
|
+
|
301
|
+
length = value.length;
|
302
|
+
for (i = 0; i < length; i += 1) {
|
303
|
+
partial[i] = str(i, value) || 'null';
|
304
|
+
}
|
305
|
+
|
306
|
+
// Join all of the elements together, separated with commas, and wrap them in
|
307
|
+
// brackets.
|
308
|
+
|
309
|
+
v = partial.length === 0 ? '[]' : gap ?
|
310
|
+
'[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
|
311
|
+
'[' + partial.join(',') + ']';
|
312
|
+
gap = mind;
|
313
|
+
return v;
|
314
|
+
}
|
315
|
+
|
316
|
+
// If the replacer is an array, use it to select the members to be stringified.
|
317
|
+
|
318
|
+
if (rep && typeof rep === 'object') {
|
319
|
+
length = rep.length;
|
320
|
+
for (i = 0; i < length; i += 1) {
|
321
|
+
if (typeof rep[i] === 'string') {
|
322
|
+
k = rep[i];
|
323
|
+
v = str(k, value);
|
324
|
+
if (v) {
|
325
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
326
|
+
}
|
327
|
+
}
|
328
|
+
}
|
329
|
+
} else {
|
330
|
+
|
331
|
+
// Otherwise, iterate through all of the keys in the object.
|
332
|
+
|
333
|
+
for (k in value) {
|
334
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
335
|
+
v = str(k, value);
|
336
|
+
if (v) {
|
337
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
338
|
+
}
|
339
|
+
}
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
// Join all of the member texts together, separated with commas,
|
344
|
+
// and wrap them in braces.
|
345
|
+
|
346
|
+
v = partial.length === 0 ? '{}' : gap ?
|
347
|
+
'{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
|
348
|
+
'{' + partial.join(',') + '}';
|
349
|
+
gap = mind;
|
350
|
+
return v;
|
351
|
+
}
|
352
|
+
}
|
353
|
+
|
354
|
+
// If the JSON object does not yet have a stringify method, give it one.
|
355
|
+
|
356
|
+
if (typeof JSON.stringify !== 'function') {
|
357
|
+
JSON.stringify = function (value, replacer, space) {
|
358
|
+
|
359
|
+
// The stringify method takes a value and an optional replacer, and an optional
|
360
|
+
// space parameter, and returns a JSON text. The replacer can be a function
|
361
|
+
// that can replace values, or an array of strings that will select the keys.
|
362
|
+
// A default replacer method can be provided. Use of the space parameter can
|
363
|
+
// produce text that is more easily readable.
|
364
|
+
|
365
|
+
var i;
|
366
|
+
gap = '';
|
367
|
+
indent = '';
|
368
|
+
|
369
|
+
// If the space parameter is a number, make an indent string containing that
|
370
|
+
// many spaces.
|
371
|
+
|
372
|
+
if (typeof space === 'number') {
|
373
|
+
for (i = 0; i < space; i += 1) {
|
374
|
+
indent += ' ';
|
375
|
+
}
|
376
|
+
|
377
|
+
// If the space parameter is a string, it will be used as the indent string.
|
378
|
+
|
379
|
+
} else if (typeof space === 'string') {
|
380
|
+
indent = space;
|
381
|
+
}
|
382
|
+
|
383
|
+
// If there is a replacer, it must be a function or an array.
|
384
|
+
// Otherwise, throw an error.
|
385
|
+
|
386
|
+
rep = replacer;
|
387
|
+
if (replacer && typeof replacer !== 'function' &&
|
388
|
+
(typeof replacer !== 'object' ||
|
389
|
+
typeof replacer.length !== 'number')) {
|
390
|
+
throw new Error('JSON.stringify');
|
391
|
+
}
|
392
|
+
|
393
|
+
// Make a fake root object containing our value under the key of ''.
|
394
|
+
// Return the result of stringifying the value.
|
395
|
+
|
396
|
+
return str('', {'': value});
|
397
|
+
};
|
398
|
+
}
|
399
|
+
|
400
|
+
|
401
|
+
// If the JSON object does not yet have a parse method, give it one.
|
402
|
+
|
403
|
+
if (typeof JSON.parse !== 'function') {
|
404
|
+
JSON.parse = function (text, reviver) {
|
405
|
+
|
406
|
+
// The parse method takes a text and an optional reviver function, and returns
|
407
|
+
// a JavaScript value if the text is a valid JSON text.
|
408
|
+
|
409
|
+
var j;
|
410
|
+
|
411
|
+
function walk(holder, key) {
|
412
|
+
|
413
|
+
// The walk method is used to recursively walk the resulting structure so
|
414
|
+
// that modifications can be made.
|
415
|
+
|
416
|
+
var k, v, value = holder[key];
|
417
|
+
if (value && typeof value === 'object') {
|
418
|
+
for (k in value) {
|
419
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
420
|
+
v = walk(value, k);
|
421
|
+
if (v !== undefined) {
|
422
|
+
value[k] = v;
|
423
|
+
} else {
|
424
|
+
delete value[k];
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}
|
428
|
+
}
|
429
|
+
return reviver.call(holder, key, value);
|
430
|
+
}
|
431
|
+
|
432
|
+
|
433
|
+
// Parsing happens in four stages. In the first stage, we replace certain
|
434
|
+
// Unicode characters with escape sequences. JavaScript handles many characters
|
435
|
+
// incorrectly, either silently deleting them, or treating them as line endings.
|
436
|
+
|
437
|
+
text = String(text);
|
438
|
+
cx.lastIndex = 0;
|
439
|
+
if (cx.test(text)) {
|
440
|
+
text = text.replace(cx, function (a) {
|
441
|
+
return '\\u' +
|
442
|
+
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
443
|
+
});
|
444
|
+
}
|
445
|
+
|
446
|
+
// In the second stage, we run the text against regular expressions that look
|
447
|
+
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
448
|
+
// because they can cause invocation, and '=' because it can cause mutation.
|
449
|
+
// But just to be safe, we want to reject all unexpected forms.
|
450
|
+
|
451
|
+
// We split the second stage into 4 regexp operations in order to work around
|
452
|
+
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
453
|
+
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
454
|
+
// replace all simple value tokens with ']' characters. Third, we delete all
|
455
|
+
// open brackets that follow a colon or comma or that begin the text. Finally,
|
456
|
+
// we look to see that the remaining characters are only whitespace or ']' or
|
457
|
+
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
458
|
+
|
459
|
+
if (/^[\],:{}\s]*$/
|
460
|
+
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
461
|
+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
462
|
+
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
463
|
+
|
464
|
+
// In the third stage we use the eval function to compile the text into a
|
465
|
+
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
466
|
+
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
467
|
+
// in parens to eliminate the ambiguity.
|
468
|
+
|
469
|
+
j = eval('(' + text + ')');
|
470
|
+
|
471
|
+
// In the optional fourth stage, we recursively walk the new structure, passing
|
472
|
+
// each name/value pair to a reviver function for possible transformation.
|
473
|
+
|
474
|
+
return typeof reviver === 'function' ?
|
475
|
+
walk({'': j}, '') : j;
|
476
|
+
}
|
477
|
+
|
478
|
+
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
479
|
+
|
480
|
+
throw new SyntaxError('JSON.parse');
|
481
|
+
};
|
482
|
+
}
|
483
|
+
}());
|
484
|
+
|
485
|
+
} // if (typeof JSON === "undefined")
|