jquery_cheats 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/app/assets/javascripts/jquery_cheats/jquery_cheats.js +1 -1
- data/app/assets/javascripts/jquery_cheats/replacementContextMenu.js +62 -0
- data/jquery_cheats.gemspec +2 -2
- data/lib/jquery_cheats/jquery_cheats.rb +58 -0
- data/vendor/assets/javascripts/jqplot/excanvas.js +1438 -0
- data/vendor/assets/javascripts/jqplot/jquery.jqplot.js +10901 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.BezierCurveRenderer.js +312 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.BezierCurveRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.barRenderer.js +747 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.barRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.blockRenderer.js +234 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.blockRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.bubbleRenderer.js +754 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.bubbleRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js +202 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasAxisLabelRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasAxisTickRenderer.js +242 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasOverlay.js +864 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasOverlay.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasTextRenderer.js +448 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasTextRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.categoryAxisRenderer.js +636 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.categoryAxisRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.ciParser.js +115 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.ciParser.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.cursor.js +1093 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.cursor.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.dateAxisRenderer.js +702 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.dateAxisRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.donutRenderer.js +800 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.donutRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.dragable.js +224 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.dragable.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.enhancedLegendRenderer.js +241 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.enhancedLegendRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.funnelRenderer.js +938 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.funnelRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.highlighter.js +454 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.highlighter.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.json2.js +475 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.json2.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.logAxisRenderer.js +528 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.logAxisRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.mekkoAxisRenderer.js +610 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.mekkoAxisRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.mekkoRenderer.js +436 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.mekkoRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.meterGaugeRenderer.js +1029 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.meterGaugeRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.ohlcRenderer.js +372 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.ohlcRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pieRenderer.js +899 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pieRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pointLabels.js +362 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pointLabels.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidAxisRenderer.js +730 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidAxisRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidGridRenderer.js +423 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidGridRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidRenderer.js +490 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidRenderer.min.js +57 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.trendline.js +222 -0
- data/vendor/assets/javascripts/jqplot/plugins/jqplot.trendline.min.js +57 -0
- data/vendor/assets/javascripts/jquery_cheats/spinjs/spin.min.js +1 -1
- data/vendor/assets/stylesheets/jquery.jqplot.css +259 -0
- metadata +66 -3
@@ -0,0 +1,57 @@
|
|
1
|
+
/**
|
2
|
+
* jqPlot
|
3
|
+
* Pure JavaScript plotting plugin using jQuery
|
4
|
+
*
|
5
|
+
* Version: 1.0.0b2_r1012
|
6
|
+
*
|
7
|
+
* Copyright (c) 2009-2011 Chris Leonello
|
8
|
+
* jqPlot is currently available for use in all personal or commercial projects
|
9
|
+
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
|
10
|
+
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
|
11
|
+
* choose the license that best suits your project and use it accordingly.
|
12
|
+
*
|
13
|
+
* Although not required, the author would appreciate an email letting him
|
14
|
+
* know of any substantial use of jqPlot. You can reach the author at:
|
15
|
+
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
|
16
|
+
*
|
17
|
+
* If you are feeling kind and generous, consider supporting the project by
|
18
|
+
* making a donation at: http://www.jqplot.com/donate.php .
|
19
|
+
*
|
20
|
+
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
|
21
|
+
*
|
22
|
+
* version 2007.04.27
|
23
|
+
* author Ash Searle
|
24
|
+
* http://hexmen.com/blog/2007/03/printf-sprintf/
|
25
|
+
* http://hexmen.com/js/sprintf.js
|
26
|
+
* The author (Ash Searle) has placed this code in the public domain:
|
27
|
+
* "This code is unrestricted: you are free to use it however you like."
|
28
|
+
*
|
29
|
+
* included jsDate library by Chris Leonello:
|
30
|
+
*
|
31
|
+
* Copyright (c) 2010-2011 Chris Leonello
|
32
|
+
*
|
33
|
+
* jsDate is currently available for use in all personal or commercial projects
|
34
|
+
* under both the MIT and GPL version 2.0 licenses. This means that you can
|
35
|
+
* choose the license that best suits your project and use it accordingly.
|
36
|
+
*
|
37
|
+
* jsDate borrows many concepts and ideas from the Date Instance
|
38
|
+
* Methods by Ken Snyder along with some parts of Ken's actual code.
|
39
|
+
*
|
40
|
+
* Ken's origianl Date Instance Methods and copyright notice:
|
41
|
+
*
|
42
|
+
* Ken Snyder (ken d snyder at gmail dot com)
|
43
|
+
* 2008-09-10
|
44
|
+
* version 2.0.2 (http://kendsnyder.com/sandbox/date/)
|
45
|
+
* Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
|
46
|
+
*
|
47
|
+
* jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
|
48
|
+
* Larry has generously given permission to adapt his code for inclusion
|
49
|
+
* into jqPlot.
|
50
|
+
*
|
51
|
+
* Larry's original code can be found here:
|
52
|
+
*
|
53
|
+
* https://github.com/lsiden/export-jqplot-to-png
|
54
|
+
*
|
55
|
+
*
|
56
|
+
*/
|
57
|
+
(function(d){d.jqplot.eventListenerHooks.push(["jqplotMouseMove",f]);d.jqplot.Highlighter=function(h){this.show=d.jqplot.config.enablePlugins;this.markerRenderer=new d.jqplot.MarkerRenderer({shadow:false});this.showMarker=true;this.lineWidthAdjust=2.5;this.sizeAdjust=5;this.showTooltip=true;this.tooltipLocation="nw";this.fadeTooltip=true;this.tooltipFadeSpeed="fast";this.tooltipOffset=2;this.tooltipAxes="both";this.tooltipSeparator=", ";this.tooltipContentEditor=null;this.useAxesFormatters=true;this.tooltipFormatString="%.5P";this.formatString=null;this.yvalues=1;this.bringSeriesToFront=false;this._tooltipElem;this.isHighlighting=false;this.currentNeighbor=null;d.extend(true,this,h)};var b=["nw","n","ne","e","se","s","sw","w"];var e={nw:0,n:1,ne:2,e:3,se:4,s:5,sw:6,w:7};var c=["se","s","sw","w","nw","n","ne","e"];d.jqplot.Highlighter.init=function(k,j,i){var h=i||{};this.plugins.highlighter=new d.jqplot.Highlighter(h.highlighter)};d.jqplot.Highlighter.parseOptions=function(i,h){this.showHighlight=true};d.jqplot.Highlighter.postPlotDraw=function(){if(this.plugins.highlighter&&this.plugins.highlighter.highlightCanvas){this.plugins.highlighter.highlightCanvas.resetCanvas();this.plugins.highlighter.highlightCanvas=null}if(this.plugins.highlighter&&this.plugins.highlighter._tooltipElem){this.plugins.highlighter._tooltipElem.emptyForce();this.plugins.highlighter._tooltipElem=null}this.plugins.highlighter.highlightCanvas=new d.jqplot.GenericCanvas();this.eventCanvas._elem.before(this.plugins.highlighter.highlightCanvas.createElement(this._gridPadding,"jqplot-highlight-canvas",this._plotDimensions,this));this.plugins.highlighter.highlightCanvas.setContext();var h=document.createElement("div");this.plugins.highlighter._tooltipElem=d(h);h=null;this.plugins.highlighter._tooltipElem.addClass("jqplot-highlighter-tooltip");this.plugins.highlighter._tooltipElem.css({position:"absolute",display:"none"});this.eventCanvas._elem.before(this.plugins.highlighter._tooltipElem)};d.jqplot.preInitHooks.push(d.jqplot.Highlighter.init);d.jqplot.preParseSeriesOptionsHooks.push(d.jqplot.Highlighter.parseOptions);d.jqplot.postDrawHooks.push(d.jqplot.Highlighter.postPlotDraw);function a(m,o){var j=m.plugins.highlighter;var p=m.series[o.seriesIndex];var h=p.markerRenderer;var i=j.markerRenderer;i.style=h.style;i.lineWidth=h.lineWidth+j.lineWidthAdjust;i.size=h.size+j.sizeAdjust;var l=d.jqplot.getColorComponents(h.color);var n=[l[0],l[1],l[2]];var k=(l[3]>=0.6)?l[3]*0.6:l[3]*(2-l[3]);i.color="rgba("+n[0]+","+n[1]+","+n[2]+","+k+")";i.init();i.draw(p.gridData[o.pointIndex][0],p.gridData[o.pointIndex][1],j.highlightCanvas._ctx)}function g(A,q,m){var k=A.plugins.highlighter;var D=k._tooltipElem;var r=q.highlighter||{};var t=d.extend(true,{},k,r);if(t.useAxesFormatters){var w=q._xaxis._ticks[0].formatter;var h=q._yaxis._ticks[0].formatter;var E=q._xaxis._ticks[0].formatString;var s=q._yaxis._ticks[0].formatString;var z;var u=w(E,m.data[0]);var l=[];for(var B=1;B<t.yvalues+1;B++){l.push(h(s,m.data[B]))}if(typeof t.formatString==="string"){switch(t.tooltipAxes){case"both":case"xy":l.unshift(u);l.unshift(t.formatString);z=d.jqplot.sprintf.apply(d.jqplot.sprintf,l);break;case"yx":l.push(u);l.unshift(t.formatString);z=d.jqplot.sprintf.apply(d.jqplot.sprintf,l);break;case"x":z=d.jqplot.sprintf.apply(d.jqplot.sprintf,[t.formatString,u]);break;case"y":l.unshift(t.formatString);z=d.jqplot.sprintf.apply(d.jqplot.sprintf,l);break;default:l.unshift(u);l.unshift(t.formatString);z=d.jqplot.sprintf.apply(d.jqplot.sprintf,l);break}}else{switch(t.tooltipAxes){case"both":case"xy":z=u;for(var B=0;B<l.length;B++){z+=t.tooltipSeparator+l[B]}break;case"yx":z="";for(var B=0;B<l.length;B++){z+=l[B]+t.tooltipSeparator}z+=u;break;case"x":z=u;break;case"y":z=l.join(t.tooltipSeparator);break;default:z=u;for(var B=0;B<l.length;B++){z+=t.tooltipSeparator+l[B]}break}}}else{var z;if(typeof t.formatString==="string"){z=d.jqplot.sprintf.apply(d.jqplot.sprintf,[t.formatString].concat(m.data))}else{if(t.tooltipAxes=="both"||t.tooltipAxes=="xy"){z=d.jqplot.sprintf(t.tooltipFormatString,m.data[0])+t.tooltipSeparator+d.jqplot.sprintf(t.tooltipFormatString,m.data[1])}else{if(t.tooltipAxes=="yx"){z=d.jqplot.sprintf(t.tooltipFormatString,m.data[1])+t.tooltipSeparator+d.jqplot.sprintf(t.tooltipFormatString,m.data[0])}else{if(t.tooltipAxes=="x"){z=d.jqplot.sprintf(t.tooltipFormatString,m.data[0])}else{if(t.tooltipAxes=="y"){z=d.jqplot.sprintf(t.tooltipFormatString,m.data[1])}}}}}}if(d.isFunction(t.tooltipContentEditor)){z=t.tooltipContentEditor(z,m.seriesIndex,m.pointIndex,A)}D.html(z);var C={x:m.gridData[0],y:m.gridData[1]};var v=0;var j=0.707;if(q.markerRenderer.show==true){v=(q.markerRenderer.size+t.sizeAdjust)/2}var o=b;if(q.fillToZero&&q.fill&&m.data[1]<0){o=c}switch(o[e[t.tooltipLocation]]){case"nw":var p=C.x+A._gridPadding.left-D.outerWidth(true)-t.tooltipOffset-j*v;var n=C.y+A._gridPadding.top-t.tooltipOffset-D.outerHeight(true)-j*v;break;case"n":var p=C.x+A._gridPadding.left-D.outerWidth(true)/2;var n=C.y+A._gridPadding.top-t.tooltipOffset-D.outerHeight(true)-v;break;case"ne":var p=C.x+A._gridPadding.left+t.tooltipOffset+j*v;var n=C.y+A._gridPadding.top-t.tooltipOffset-D.outerHeight(true)-j*v;break;case"e":var p=C.x+A._gridPadding.left+t.tooltipOffset+v;var n=C.y+A._gridPadding.top-D.outerHeight(true)/2;break;case"se":var p=C.x+A._gridPadding.left+t.tooltipOffset+j*v;var n=C.y+A._gridPadding.top+t.tooltipOffset+j*v;break;case"s":var p=C.x+A._gridPadding.left-D.outerWidth(true)/2;var n=C.y+A._gridPadding.top+t.tooltipOffset+v;break;case"sw":var p=C.x+A._gridPadding.left-D.outerWidth(true)-t.tooltipOffset-j*v;var n=C.y+A._gridPadding.top+t.tooltipOffset+j*v;break;case"w":var p=C.x+A._gridPadding.left-D.outerWidth(true)-t.tooltipOffset-v;var n=C.y+A._gridPadding.top-D.outerHeight(true)/2;break;default:var p=C.x+A._gridPadding.left-D.outerWidth(true)-t.tooltipOffset-j*v;var n=C.y+A._gridPadding.top-t.tooltipOffset-D.outerHeight(true)-j*v;break}D.css("left",p);D.css("top",n);if(t.fadeTooltip){D.stop(true,true).fadeIn(t.tooltipFadeSpeed)}else{D.show()}D=null}function f(k,j,n,m,l){var h=l.plugins.highlighter;var o=l.plugins.cursor;if(h.show){if(m==null&&h.isHighlighting){var i=h.highlightCanvas._ctx;i.clearRect(0,0,i.canvas.width,i.canvas.height);if(h.fadeTooltip){h._tooltipElem.fadeOut(h.tooltipFadeSpeed)}else{h._tooltipElem.hide()}if(h.bringSeriesToFront){l.restorePreviousSeriesOrder()}h.isHighlighting=false;h.currentNeighbor=null;i=null}else{if(m!=null&&l.series[m.seriesIndex].showHighlight&&!h.isHighlighting){h.isHighlighting=true;h.currentNeighbor=m;if(h.showMarker){a(l,m)}if(h.showTooltip&&(!o||!o._zoom.started)){g(l,l.series[m.seriesIndex],m)}if(h.bringSeriesToFront){l.moveSeriesToFront(m.seriesIndex)}}else{if(m!=null&&h.isHighlighting&&h.currentNeighbor!=m){if(l.series[m.seriesIndex].showHighlight){var i=h.highlightCanvas._ctx;i.clearRect(0,0,i.canvas.width,i.canvas.height);h.isHighlighting=true;h.currentNeighbor=m;if(h.showMarker){a(l,m)}if(h.showTooltip&&(!o||!o._zoom.started)){g(l,l.series[m.seriesIndex],m)}if(h.bringSeriesToFront){l.moveSeriesToFront(m.seriesIndex)}}}}}}}})(jQuery);
|
@@ -0,0 +1,475 @@
|
|
1
|
+
/*
|
2
|
+
2010-11-01 Chris Leonello
|
3
|
+
|
4
|
+
Slightly modified version of the original json2.js to put JSON
|
5
|
+
functions under the $.jqplot namespace.
|
6
|
+
|
7
|
+
licensing and orignal comments follow:
|
8
|
+
|
9
|
+
http://www.JSON.org/json2.js
|
10
|
+
2010-08-25
|
11
|
+
|
12
|
+
Public Domain.
|
13
|
+
|
14
|
+
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
15
|
+
|
16
|
+
See http://www.JSON.org/js.html
|
17
|
+
|
18
|
+
|
19
|
+
This code should be minified before deployment.
|
20
|
+
See http://javascript.crockford.com/jsmin.html
|
21
|
+
|
22
|
+
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
23
|
+
NOT CONTROL.
|
24
|
+
|
25
|
+
|
26
|
+
This file creates a global JSON object containing two methods: stringify
|
27
|
+
and parse.
|
28
|
+
|
29
|
+
$.jqplot.JSON.stringify(value, replacer, space)
|
30
|
+
value any JavaScript value, usually an object or array.
|
31
|
+
|
32
|
+
replacer an optional parameter that determines how object
|
33
|
+
values are stringified for objects. It can be a
|
34
|
+
function or an array of strings.
|
35
|
+
|
36
|
+
space an optional parameter that specifies the indentation
|
37
|
+
of nested structures. If it is omitted, the text will
|
38
|
+
be packed without extra whitespace. If it is a number,
|
39
|
+
it will specify the number of spaces to indent at each
|
40
|
+
level. If it is a string (such as '\t' or ' '),
|
41
|
+
it contains the characters used to indent at each level.
|
42
|
+
|
43
|
+
This method produces a JSON text from a JavaScript value.
|
44
|
+
|
45
|
+
When an object value is found, if the object contains a toJSON
|
46
|
+
method, its toJSON method will be called and the result will be
|
47
|
+
stringified. A toJSON method does not serialize: it returns the
|
48
|
+
value represented by the name/value pair that should be serialized,
|
49
|
+
or undefined if nothing should be serialized. The toJSON method
|
50
|
+
will be passed the key associated with the value, and this will be
|
51
|
+
bound to the value
|
52
|
+
|
53
|
+
For example, this would serialize Dates as ISO strings.
|
54
|
+
|
55
|
+
Date.prototype.toJSON = function (key) {
|
56
|
+
function f(n) {
|
57
|
+
// Format integers to have at least two digits.
|
58
|
+
return n < 10 ? '0' + n : n;
|
59
|
+
}
|
60
|
+
|
61
|
+
return this.getUTCFullYear() + '-' +
|
62
|
+
f(this.getUTCMonth() + 1) + '-' +
|
63
|
+
f(this.getUTCDate()) + 'T' +
|
64
|
+
f(this.getUTCHours()) + ':' +
|
65
|
+
f(this.getUTCMinutes()) + ':' +
|
66
|
+
f(this.getUTCSeconds()) + 'Z';
|
67
|
+
};
|
68
|
+
|
69
|
+
You can provide an optional replacer method. It will be passed the
|
70
|
+
key and value of each member, with this bound to the containing
|
71
|
+
object. The value that is returned from your method will be
|
72
|
+
serialized. If your method returns undefined, then the member will
|
73
|
+
be excluded from the serialization.
|
74
|
+
|
75
|
+
If the replacer parameter is an array of strings, then it will be
|
76
|
+
used to select the members to be serialized. It filters the results
|
77
|
+
such that only members with keys listed in the replacer array are
|
78
|
+
stringified.
|
79
|
+
|
80
|
+
Values that do not have JSON representations, such as undefined or
|
81
|
+
functions, will not be serialized. Such values in objects will be
|
82
|
+
dropped; in arrays they will be replaced with null. You can use
|
83
|
+
a replacer function to replace those with JSON values.
|
84
|
+
$.jqplot.JSON.stringify(undefined) returns undefined.
|
85
|
+
|
86
|
+
The optional space parameter produces a stringification of the
|
87
|
+
value that is filled with line breaks and indentation to make it
|
88
|
+
easier to read.
|
89
|
+
|
90
|
+
If the space parameter is a non-empty string, then that string will
|
91
|
+
be used for indentation. If the space parameter is a number, then
|
92
|
+
the indentation will be that many spaces.
|
93
|
+
|
94
|
+
Example:
|
95
|
+
|
96
|
+
text = $.jqplot.JSON.stringify(['e', {pluribus: 'unum'}]);
|
97
|
+
// text is '["e",{"pluribus":"unum"}]'
|
98
|
+
|
99
|
+
|
100
|
+
text = $.jqplot.JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
101
|
+
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
102
|
+
|
103
|
+
text = $.jqplot.JSON.stringify([new Date()], function (key, value) {
|
104
|
+
return this[key] instanceof Date ?
|
105
|
+
'Date(' + this[key] + ')' : value;
|
106
|
+
});
|
107
|
+
// text is '["Date(---current time---)"]'
|
108
|
+
|
109
|
+
|
110
|
+
$.jqplot.JSON.parse(text, reviver)
|
111
|
+
This method parses a JSON text to produce an object or array.
|
112
|
+
It can throw a SyntaxError exception.
|
113
|
+
|
114
|
+
The optional reviver parameter is a function that can filter and
|
115
|
+
transform the results. It receives each of the keys and values,
|
116
|
+
and its return value is used instead of the original value.
|
117
|
+
If it returns what it received, then the structure is not modified.
|
118
|
+
If it returns undefined then the member is deleted.
|
119
|
+
|
120
|
+
Example:
|
121
|
+
|
122
|
+
// Parse the text. Values that look like ISO date strings will
|
123
|
+
// be converted to Date objects.
|
124
|
+
|
125
|
+
myData = $.jqplot.JSON.parse(text, function (key, value) {
|
126
|
+
var a;
|
127
|
+
if (typeof value === 'string') {
|
128
|
+
a =
|
129
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
130
|
+
if (a) {
|
131
|
+
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
132
|
+
+a[5], +a[6]));
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return value;
|
136
|
+
});
|
137
|
+
|
138
|
+
myData = $.jqplot.JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
139
|
+
var d;
|
140
|
+
if (typeof value === 'string' &&
|
141
|
+
value.slice(0, 5) === 'Date(' &&
|
142
|
+
value.slice(-1) === ')') {
|
143
|
+
d = new Date(value.slice(5, -1));
|
144
|
+
if (d) {
|
145
|
+
return d;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
return value;
|
149
|
+
});
|
150
|
+
|
151
|
+
|
152
|
+
This is a reference implementation. You are free to copy, modify, or
|
153
|
+
redistribute.
|
154
|
+
*/
|
155
|
+
|
156
|
+
(function($) {
|
157
|
+
|
158
|
+
$.jqplot.JSON = window.JSON;
|
159
|
+
|
160
|
+
if (!window.JSON) {
|
161
|
+
$.jqplot.JSON = {};
|
162
|
+
}
|
163
|
+
|
164
|
+
function f(n) {
|
165
|
+
// Format integers to have at least two digits.
|
166
|
+
return n < 10 ? '0' + n : n;
|
167
|
+
}
|
168
|
+
|
169
|
+
if (typeof Date.prototype.toJSON !== 'function') {
|
170
|
+
|
171
|
+
Date.prototype.toJSON = function (key) {
|
172
|
+
|
173
|
+
return isFinite(this.valueOf()) ?
|
174
|
+
this.getUTCFullYear() + '-' +
|
175
|
+
f(this.getUTCMonth() + 1) + '-' +
|
176
|
+
f(this.getUTCDate()) + 'T' +
|
177
|
+
f(this.getUTCHours()) + ':' +
|
178
|
+
f(this.getUTCMinutes()) + ':' +
|
179
|
+
f(this.getUTCSeconds()) + 'Z' : null;
|
180
|
+
};
|
181
|
+
|
182
|
+
String.prototype.toJSON =
|
183
|
+
Number.prototype.toJSON =
|
184
|
+
Boolean.prototype.toJSON = function (key) {
|
185
|
+
return this.valueOf();
|
186
|
+
};
|
187
|
+
}
|
188
|
+
|
189
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
190
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
191
|
+
gap,
|
192
|
+
indent,
|
193
|
+
meta = { // table of character substitutions
|
194
|
+
'\b': '\\b',
|
195
|
+
'\t': '\\t',
|
196
|
+
'\n': '\\n',
|
197
|
+
'\f': '\\f',
|
198
|
+
'\r': '\\r',
|
199
|
+
'"' : '\\"',
|
200
|
+
'\\': '\\\\'
|
201
|
+
},
|
202
|
+
rep;
|
203
|
+
|
204
|
+
|
205
|
+
function quote(string) {
|
206
|
+
|
207
|
+
// If the string contains no control characters, no quote characters, and no
|
208
|
+
// backslash characters, then we can safely slap some quotes around it.
|
209
|
+
// Otherwise we must also replace the offending characters with safe escape
|
210
|
+
// sequences.
|
211
|
+
|
212
|
+
escapable.lastIndex = 0;
|
213
|
+
return escapable.test(string) ?
|
214
|
+
'"' + string.replace(escapable, function (a) {
|
215
|
+
var c = meta[a];
|
216
|
+
return typeof c === 'string' ? c :
|
217
|
+
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
218
|
+
}) + '"' :
|
219
|
+
'"' + string + '"';
|
220
|
+
}
|
221
|
+
|
222
|
+
|
223
|
+
function str(key, holder) {
|
224
|
+
|
225
|
+
// Produce a string from holder[key].
|
226
|
+
|
227
|
+
var i, // The loop counter.
|
228
|
+
k, // The member key.
|
229
|
+
v, // The member value.
|
230
|
+
length,
|
231
|
+
mind = gap,
|
232
|
+
partial,
|
233
|
+
value = holder[key];
|
234
|
+
|
235
|
+
// If the value has a toJSON method, call it to obtain a replacement value.
|
236
|
+
|
237
|
+
if (value && typeof value === 'object' &&
|
238
|
+
typeof value.toJSON === 'function') {
|
239
|
+
value = value.toJSON(key);
|
240
|
+
}
|
241
|
+
|
242
|
+
// If we were called with a replacer function, then call the replacer to
|
243
|
+
// obtain a replacement value.
|
244
|
+
|
245
|
+
if (typeof rep === 'function') {
|
246
|
+
value = rep.call(holder, key, value);
|
247
|
+
}
|
248
|
+
|
249
|
+
// What happens next depends on the value's type.
|
250
|
+
|
251
|
+
switch (typeof value) {
|
252
|
+
case 'string':
|
253
|
+
return quote(value);
|
254
|
+
|
255
|
+
case 'number':
|
256
|
+
|
257
|
+
// JSON numbers must be finite. Encode non-finite numbers as null.
|
258
|
+
|
259
|
+
return isFinite(value) ? String(value) : 'null';
|
260
|
+
|
261
|
+
case 'boolean':
|
262
|
+
case 'null':
|
263
|
+
|
264
|
+
// If the value is a boolean or null, convert it to a string. Note:
|
265
|
+
// typeof null does not produce 'null'. The case is included here in
|
266
|
+
// the remote chance that this gets fixed someday.
|
267
|
+
|
268
|
+
return String(value);
|
269
|
+
|
270
|
+
// If the type is 'object', we might be dealing with an object or an array or
|
271
|
+
// null.
|
272
|
+
|
273
|
+
case 'object':
|
274
|
+
|
275
|
+
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
276
|
+
// so watch out for that case.
|
277
|
+
|
278
|
+
if (!value) {
|
279
|
+
return 'null';
|
280
|
+
}
|
281
|
+
|
282
|
+
// Make an array to hold the partial results of stringifying this object value.
|
283
|
+
|
284
|
+
gap += indent;
|
285
|
+
partial = [];
|
286
|
+
|
287
|
+
// Is the value an array?
|
288
|
+
|
289
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
290
|
+
|
291
|
+
// The value is an array. Stringify every element. Use null as a placeholder
|
292
|
+
// for non-JSON values.
|
293
|
+
|
294
|
+
length = value.length;
|
295
|
+
for (i = 0; i < length; i += 1) {
|
296
|
+
partial[i] = str(i, value) || 'null';
|
297
|
+
}
|
298
|
+
|
299
|
+
// Join all of the elements together, separated with commas, and wrap them in
|
300
|
+
// brackets.
|
301
|
+
|
302
|
+
v = partial.length === 0 ? '[]' :
|
303
|
+
gap ? '[\n' + gap +
|
304
|
+
partial.join(',\n' + gap) + '\n' +
|
305
|
+
mind + ']' :
|
306
|
+
'[' + partial.join(',') + ']';
|
307
|
+
gap = mind;
|
308
|
+
return v;
|
309
|
+
}
|
310
|
+
|
311
|
+
// If the replacer is an array, use it to select the members to be stringified.
|
312
|
+
|
313
|
+
if (rep && typeof rep === 'object') {
|
314
|
+
length = rep.length;
|
315
|
+
for (i = 0; i < length; i += 1) {
|
316
|
+
k = rep[i];
|
317
|
+
if (typeof k === 'string') {
|
318
|
+
v = str(k, value);
|
319
|
+
if (v) {
|
320
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
} else {
|
325
|
+
|
326
|
+
// Otherwise, iterate through all of the keys in the object.
|
327
|
+
|
328
|
+
for (k in value) {
|
329
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
330
|
+
v = str(k, value);
|
331
|
+
if (v) {
|
332
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
333
|
+
}
|
334
|
+
}
|
335
|
+
}
|
336
|
+
}
|
337
|
+
|
338
|
+
// Join all of the member texts together, separated with commas,
|
339
|
+
// and wrap them in braces.
|
340
|
+
|
341
|
+
v = partial.length === 0 ? '{}' :
|
342
|
+
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
343
|
+
mind + '}' : '{' + partial.join(',') + '}';
|
344
|
+
gap = mind;
|
345
|
+
return v;
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
// If the JSON object does not yet have a stringify method, give it one.
|
350
|
+
|
351
|
+
if (typeof $.jqplot.JSON.stringify !== 'function') {
|
352
|
+
$.jqplot.JSON.stringify = function (value, replacer, space) {
|
353
|
+
|
354
|
+
// The stringify method takes a value and an optional replacer, and an optional
|
355
|
+
// space parameter, and returns a JSON text. The replacer can be a function
|
356
|
+
// that can replace values, or an array of strings that will select the keys.
|
357
|
+
// A default replacer method can be provided. Use of the space parameter can
|
358
|
+
// produce text that is more easily readable.
|
359
|
+
|
360
|
+
var i;
|
361
|
+
gap = '';
|
362
|
+
indent = '';
|
363
|
+
|
364
|
+
// If the space parameter is a number, make an indent string containing that
|
365
|
+
// many spaces.
|
366
|
+
|
367
|
+
if (typeof space === 'number') {
|
368
|
+
for (i = 0; i < space; i += 1) {
|
369
|
+
indent += ' ';
|
370
|
+
}
|
371
|
+
|
372
|
+
// If the space parameter is a string, it will be used as the indent string.
|
373
|
+
|
374
|
+
} else if (typeof space === 'string') {
|
375
|
+
indent = space;
|
376
|
+
}
|
377
|
+
|
378
|
+
// If there is a replacer, it must be a function or an array.
|
379
|
+
// Otherwise, throw an error.
|
380
|
+
|
381
|
+
rep = replacer;
|
382
|
+
if (replacer && typeof replacer !== 'function' &&
|
383
|
+
(typeof replacer !== 'object' ||
|
384
|
+
typeof replacer.length !== 'number')) {
|
385
|
+
throw new Error('$.jqplot.JSON.stringify');
|
386
|
+
}
|
387
|
+
|
388
|
+
// Make a fake root object containing our value under the key of ''.
|
389
|
+
// Return the result of stringifying the value.
|
390
|
+
|
391
|
+
return str('', {'': value});
|
392
|
+
};
|
393
|
+
}
|
394
|
+
|
395
|
+
|
396
|
+
// If the JSON object does not yet have a parse method, give it one.
|
397
|
+
|
398
|
+
if (typeof $.jqplot.JSON.parse !== 'function') {
|
399
|
+
$.jqplot.JSON.parse = function (text, reviver) {
|
400
|
+
|
401
|
+
// The parse method takes a text and an optional reviver function, and returns
|
402
|
+
// a JavaScript value if the text is a valid JSON text.
|
403
|
+
|
404
|
+
var j;
|
405
|
+
|
406
|
+
function walk(holder, key) {
|
407
|
+
|
408
|
+
// The walk method is used to recursively walk the resulting structure so
|
409
|
+
// that modifications can be made.
|
410
|
+
|
411
|
+
var k, v, value = holder[key];
|
412
|
+
if (value && typeof value === 'object') {
|
413
|
+
for (k in value) {
|
414
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
415
|
+
v = walk(value, k);
|
416
|
+
if (v !== undefined) {
|
417
|
+
value[k] = v;
|
418
|
+
} else {
|
419
|
+
delete value[k];
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
}
|
424
|
+
return reviver.call(holder, key, value);
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
// Parsing happens in four stages. In the first stage, we replace certain
|
429
|
+
// Unicode characters with escape sequences. JavaScript handles many characters
|
430
|
+
// incorrectly, either silently deleting them, or treating them as line endings.
|
431
|
+
|
432
|
+
text = String(text);
|
433
|
+
cx.lastIndex = 0;
|
434
|
+
if (cx.test(text)) {
|
435
|
+
text = text.replace(cx, function (a) {
|
436
|
+
return '\\u' +
|
437
|
+
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
438
|
+
});
|
439
|
+
}
|
440
|
+
|
441
|
+
// In the second stage, we run the text against regular expressions that look
|
442
|
+
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
443
|
+
// because they can cause invocation, and '=' because it can cause mutation.
|
444
|
+
// But just to be safe, we want to reject all unexpected forms.
|
445
|
+
|
446
|
+
// We split the second stage into 4 regexp operations in order to work around
|
447
|
+
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
448
|
+
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
449
|
+
// replace all simple value tokens with ']' characters. Third, we delete all
|
450
|
+
// open brackets that follow a colon or comma or that begin the text. Finally,
|
451
|
+
// we look to see that the remaining characters are only whitespace or ']' or
|
452
|
+
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
453
|
+
|
454
|
+
if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
455
|
+
|
456
|
+
// In the third stage we use the eval function to compile the text into a
|
457
|
+
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
458
|
+
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
459
|
+
// in parens to eliminate the ambiguity.
|
460
|
+
|
461
|
+
j = eval('(' + text + ')');
|
462
|
+
|
463
|
+
// In the optional fourth stage, we recursively walk the new structure, passing
|
464
|
+
// each name/value pair to a reviver function for possible transformation.
|
465
|
+
|
466
|
+
return typeof reviver === 'function' ?
|
467
|
+
walk({'': j}, '') : j;
|
468
|
+
}
|
469
|
+
|
470
|
+
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
471
|
+
|
472
|
+
throw new SyntaxError('$.jqplot.JSON.parse');
|
473
|
+
};
|
474
|
+
}
|
475
|
+
})(jQuery);
|