faye 0.1.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of faye might be problematic. Click here for more details.

@@ -1,69 +0,0 @@
1
- Faye.URI = Faye.extend(Faye.Class({
2
- queryString: function() {
3
- var pairs = [], key;
4
- Faye.each(this.params, function(key, value) {
5
- pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
6
- });
7
- return pairs.join('&');
8
- },
9
-
10
- isLocal: function() {
11
- var host = Faye.URI.parse(Faye.ENV.location.href);
12
-
13
- var external = (host.hostname !== this.hostname) ||
14
- (host.port !== this.port) ||
15
- (host.protocol !== this.protocol);
16
-
17
- return !external;
18
- },
19
-
20
- toURL: function() {
21
- return this.protocol + this.hostname + ':' + this.port +
22
- this.pathname + '?' + this.queryString();
23
- }
24
- }), {
25
- parse: function(url, params) {
26
- if (typeof url !== 'string') return url;
27
-
28
- var location = new this();
29
-
30
- var consume = function(name, pattern) {
31
- url = url.replace(pattern, function(match) {
32
- if (match) location[name] = match;
33
- return '';
34
- });
35
- };
36
- consume('protocol', /^https?\:\/+/);
37
- consume('hostname', /^[a-z0-9\-]+(\.[a-z0-9\-]+)*\.[a-z0-9\-]{2,6}/i);
38
- consume('port', /^:[0-9]+/);
39
-
40
- Faye.extend(location, {
41
- protocol: 'http://',
42
- hostname: Faye.ENV.location.hostname,
43
- port: Faye.ENV.location.port
44
- }, false);
45
-
46
- if (!location.port) location.port = (location.protocol === 'https://') ? '443' : '80';
47
- location.port = location.port.replace(/\D/g, '');
48
-
49
- var parts = url.split('?'),
50
- path = parts.shift(),
51
- query = parts.join('?'),
52
-
53
- pairs = query ? query.split('&') : [],
54
- n = pairs.length,
55
- data = {};
56
-
57
- while (n--) {
58
- parts = pairs[n].split('=');
59
- data[decodeURIComponent(parts[0] || '')] = decodeURIComponent(parts[1] || '');
60
- }
61
- Faye.extend(data, params);
62
-
63
- location.pathname = path;
64
- location.params = data;
65
-
66
- return location;
67
- }
68
- });
69
-
@@ -1,99 +0,0 @@
1
- Faye.XHR = {
2
- request: function(method, url, params, callbacks, scope) {
3
- var req = new this.Request(method, url, params, callbacks, scope);
4
- req.send();
5
- return req;
6
- },
7
-
8
- getXhrObject: function() {
9
- return Faye.ENV.ActiveXObject
10
- ? new ActiveXObject("Microsoft.XMLHTTP")
11
- : new XMLHttpRequest();
12
- },
13
-
14
- Request: Faye.Class({
15
- initialize: function(method, url, params, callbacks, scope) {
16
- this._method = method.toUpperCase();
17
- this._endpoint = Faye.URI.parse(url, params);
18
- this._callbacks = (typeof callbacks === 'function') ? {success: callbacks} : callbacks;
19
- this._scope = scope || null;
20
- this._xhr = null;
21
- },
22
-
23
- send: function() {
24
- if (this._waiting) return;
25
-
26
- var path = this._endpoint.pathname, qs = this._endpoint.queryString();
27
- if (this._method === 'GET') path += '?' + qs;
28
-
29
- var body = this._method === 'POST' ? qs : '';
30
-
31
- this._waiting = true;
32
- this._xhr = Faye.XHR.getXhrObject();
33
- this._xhr.open(this._method, path, true);
34
-
35
- if (this._method === 'POST')
36
- this._xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
37
-
38
- var self = this, handleState = function() {
39
- if (self._xhr.readyState !== 4) return;
40
-
41
- if (poll) {
42
- clearInterval(poll);
43
- poll = null;
44
- }
45
-
46
- Faye.Event.detach(Faye.ENV, 'beforeunload', self.abort, self);
47
- self._waiting = false;
48
- self._handleResponse();
49
- self = null;
50
- };
51
-
52
- var poll = setInterval(handleState, 10);
53
- Faye.Event.on(Faye.ENV, 'beforeunload', this.abort, this);
54
- this._xhr.send(body);
55
- },
56
-
57
- abort: function() {
58
- this._xhr.abort();
59
- },
60
-
61
- _handleResponse: function() {
62
- var cb = this._callbacks;
63
- if (!cb) return;
64
- return this.success()
65
- ? cb.success && cb.success.call(this._scope, this)
66
- : cb.failure && cb.failure.call(this._scope, this);
67
- },
68
-
69
- waiting: function() {
70
- return !!this._waiting;
71
- },
72
-
73
- complete: function() {
74
- return this._xhr && !this.waiting();
75
- },
76
-
77
- success: function() {
78
- if (!this.complete()) return false;
79
- var status = this._xhr.status;
80
- return (status >= 200 && status < 300) || status === 304 || status === 1223;
81
- },
82
-
83
- failure: function() {
84
- if (!this.complete()) return false;
85
- return !this.success();
86
- },
87
-
88
- text: function() {
89
- if (!this.complete()) return null;
90
- return this._xhr.responseText;
91
- },
92
-
93
- status: function() {
94
- if (!this.complete()) return null;
95
- return this._xhr.status;
96
- }
97
- })
98
- };
99
-
@@ -1,22 +0,0 @@
1
- Soapbox -- a Twitter-style chat app
2
- ===================================
3
-
4
- -- Running the demo
5
-
6
- * `sudo gem install sinatra`
7
- * Run `rackup config.ru` in this directory
8
- * Open some browsers at http://localhost:9292
9
-
10
- Within the app, pick a username, type in some users to follow, and
11
- enter messages. You receive messages from anyone you're following,
12
- and any messages that mention you using the `@username` syntax.
13
-
14
- -- Source code
15
-
16
- There is no server-side logic for this app; the Faye server simply
17
- handles message routing between clients. Your username and followees
18
- are not persisted, if you refresh the page your previous connection
19
- is closed.
20
-
21
- * See public/soapbox.js
22
-
@@ -1,8 +0,0 @@
1
- require 'rubygems'
2
- require 'sinatra'
3
-
4
- get '/' do
5
- @server = env['faye.server']
6
- erb :index
7
- end
8
-
@@ -1 +0,0 @@
1
- if(!this.Faye)Faye={};Faye.extend=function(a,c,b){if(!c)return a;for(var d in c){if(c.hasOwnProperty(d)&&a[d]!==c[d]){if(!a.hasOwnProperty(d)||b!==false)a[d]=c[d]}}return a};Faye.extend(Faye,{BAYEUX_VERSION:'1.0',ENV:this,VERSION:'0.1.0',Grammar:{LOWALPHA:/^[a-z]$/,UPALPHA:/^[A-Z]$/,ALPHA:/^([a-z]|[A-Z])$/,DIGIT:/^[0-9]$/,ALPHANUM:/^(([a-z]|[A-Z])|[0-9])$/,MARK:/^(\-|\_|\!|\~|\(|\)|\$|\@)$/,STRING:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,TOKEN:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,INTEGER:/^([0-9])+$/,CHANNEL_SEGMENT:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,CHANNEL_SEGMENTS:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,CHANNEL_NAME:/^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,WILD_CARD:/^\*{1,2}$/,CHANNEL_PATTERN:/^(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*\/\*{1,2}$/,VERSION_ELEMENT:/^(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*$/,VERSION:/^([0-9])+(\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*)*$/,CLIENT_ID:/^((([a-z]|[A-Z])|[0-9]))+$/,ID:/^((([a-z]|[A-Z])|[0-9]))+$/,ERROR_MESSAGE:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,ERROR_ARGS:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*$/,ERROR_CODE:/^[0-9][0-9][0-9]$/,ERROR:/^([0-9][0-9][0-9]:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*|[0-9][0-9][0-9]::(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/},commonElement:function(a,c){for(var b=0,d=a.length;b<d;b++){if(this.indexOf(c,a[b])!==-1)return a[b]}return null},indexOf:function(a,c){for(var b=0,d=a.length;b<d;b++){if(a[b]===c)return b}return-1},each:function(a,c,b){if(a instanceof Array){for(var d=0,f=a.length;d<f;d++){if(a[d]!==undefined)c.call(b||null,a[d],d)}}else{for(var g in a){if(a.hasOwnProperty(g))c.call(b||null,g,a[g])}}},size:function(a){var c=0;this.each(a,function(){c+=1});return c},enumEqual:function(b,d){if(d instanceof Array){if(!(b instanceof Array))return false;var f=b.length;if(f!==d.length)return false;while(f--){if(b[f]!==d[f])return false}return true}else{if(!(b instanceof Object))return false;if(this.size(d)!==this.size(b))return false;var g=true;this.each(b,function(a,c){g=g&&(d[a]===c)});return g}}});Faye.Class=function(a,c){if(typeof a!=='function'){c=a;a=Object}var b=function(){if(!this.initialize)return this;return this.initialize.apply(this,arguments)||this};var d=function(){};d.prototype=a.prototype;b.prototype=new d();Faye.extend(b.prototype,c);return b};Faye.Event={_9:[],on:function(a,c,b,d){var f=function(){b.call(d)};if(a.addEventListener)a.addEventListener(c,f,false);else a.attachEvent('on'+c,f);this._9.push({_a:a,_g:c,_r:b,_b:d,_l:f})},detach:function(a,c,b,d){var f=this._9.length,g;while(f--){g=this._9[f];if((a&&a!==g._a)||(c&&c!==g._g)||(b&&b!==g._r)||(d&&d!==g._b))continue;if(g._a.removeEventListener)g._a.removeEventListener(g._g,g._l,false);else g._a.detachEvent('on'+g._g,g._l);this._9.splice(f,1);g=null}}};Faye.Event.on(Faye.ENV,'unload',Faye.Event.detach,Faye.Event);Faye.URI=Faye.extend(Faye.Class({queryString:function(){var b=[],d;Faye.each(this.params,function(a,c){b.push(encodeURIComponent(a)+'='+encodeURIComponent(c))});return b.join('&')},isLocal:function(){var a=Faye.URI.parse(Faye.ENV.location.href);var c=(a.hostname!==this.hostname)||(a.port!==this.port)||(a.protocol!==this.protocol);return!c},toURL:function(){return this.protocol+this.hostname+':'+this.port+this.pathname+'?'+this.queryString()}}),{parse:function(d,f){if(typeof d!=='string')return d;var g=new this();var k=function(c,b){d=d.replace(b,function(a){if(a)g[c]=a;return''})};k('protocol',/^https?\:\/+/);k('hostname',/^[a-z0-9\-]+(\.[a-z0-9\-]+)*\.[a-z0-9\-]{2,6}/i);k('port',/^:[0-9]+/);Faye.extend(g,{protocol:'http://',hostname:Faye.ENV.location.hostname,port:Faye.ENV.location.port},false);if(!g.port)g.port=(g.protocol==='https://')?'443':'80';g.port=g.port.replace(/\D/g,'');var i=d.split('?'),h=i.shift(),l=i.join('?'),n=l?l.split('&'):[],o=n.length,j={};while(o--){i=n[o].split('=');j[decodeURIComponent(i[0]||'')]=decodeURIComponent(i[1]||'')}Faye.extend(j,f);g.pathname=h;g.params=j;return g}});Faye.XHR={request:function(a,c,b,d,f){var g=new this.Request(a,c,b,d,f);g.send();return g},getXhrObject:function(){return Faye.ENV.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},Request:Faye.Class({initialize:function(a,c,b,d,f){this._c=a.toUpperCase();this._4=Faye.URI.parse(c,b);this._s=(typeof d==='function')?{success:d}:d;this._b=f||null;this._1=null},send:function(){if(this._h)return;var a=this._4.pathname,c=this._4.queryString();if(this._c==='GET')a+='?'+c;var b=this._c==='POST'?c:'';this._h=true;this._1=Faye.XHR.getXhrObject();this._1.open(this._c,a,true);if(this._c==='POST')this._1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');var d=this,f=function(){if(d._1.readyState!==4)return;if(g){clearInterval(g);g=null}Faye.Event.detach(Faye.ENV,'beforeunload',d.abort,d);d._h=false;d._t();d=null};var g=setInterval(f,10);Faye.Event.on(Faye.ENV,'beforeunload',this.abort,this);this._1.send(b)},abort:function(){this._1.abort()},_t:function(){var a=this._s;if(!a)return;return this.success()?a.success&&a.success.call(this._b,this):a.failure&&a.failure.call(this._b,this)},waiting:function(){return!!this._h},complete:function(){return this._1&&!this.waiting()},success:function(){if(!this.complete())return false;var a=this._1.status;return(a>=200&&a<300)||a===304||a===1223},failure:function(){if(!this.complete())return false;return!this.success()},text:function(){if(!this.complete())return null;return this._1.responseText},status:function(){if(!this.complete())return null;return this._1.status}})};Faye.Channel={HANDSHAKE:'/meta/handshake',CONNECT:'/meta/connect',SUBSCRIBE:'/meta/subscribe',UNSUBSCRIBE:'/meta/unsubscribe',DISCONNECT:'/meta/disconnect',META:'meta',SERVICE:'service',isValid:function(a){return Faye.Grammar.CHANNEL_NAME.test(a)||Faye.Grammar.CHANNEL_PATTERN.test(a)},parse:function(a){if(!this.isValid(a))return null;return a.split('/').slice(1)},isMeta:function(a){var c=this.parse(a);return c?(c[0]===this.META):null},isService:function(a){var c=this.parse(a);return c?(c[0]===this.SERVICE):null},isSubscribable:function(a){if(!this.isValid(a))return null;return!this.isMeta(a)&&!this.isService(a)},Tree:Faye.Class({initialize:function(a){this._2=a;this._5={}},eachChild:function(b,d){Faye.each(this._5,function(a,c){b.call(d,a,c)})},each:function(b,d,f){this.eachChild(function(a,c){a=b.concat(a);c.each(a,d,f)});if(this._2!==undefined)d.call(f,b,this._2)},map:function(b,d){var f=[];this.each([],function(a,c){f.push(b.call(d,a,c))});return f},get:function(a){var c=this.traverse(a);return c?c._2:null},set:function(a,c){var b=this.traverse(a,true);if(b)b._2=c},traverse:function(a,c){if(typeof a==='string')a=Faye.Channel.parse(a);if(a===null)return null;if(a.length===0)return this;var b=this._5[a[0]];if(!b&&!c)return null;if(!b)b=this._5[a[0]]=new Faye.Channel.Tree();return b.traverse(a.slice(1),c)},glob:function(f){if(typeof f==='string')f=Faye.Channel.parse(f);if(f===null)return[];if(f.length===0)return(this._2===undefined)?[]:[this._2];var g=[];if(Faye.enumEqual(f,['*'])){Faye.each(this._5,function(a,c){if(c._2!==undefined)g.push(c._2)});return g}if(Faye.enumEqual(f,['**'])){g=this.map(function(a,c){return c});g.pop();return g}Faye.each(this._5,function(c,b){if(c!==f[0]&&c!=='*')return;var d=b.glob(f.slice(1));Faye.each(d,function(a){g.push(a)})});if(this._5['**'])g.push(this._5['**']._2);return g}})};Faye.Transport=Faye.extend(Faye.Class({initialize:function(a,c){this._m=a;this._4=c},send:function(b,d,f){b={message:JSON.stringify(b)};return this.request(b,function(c){if(!d)return;Faye.each([].concat(c),function(a){d.call(f,a);if(a.advice)this._m._u(a.advice);if(a.data&&a.channel)this._m._v(a)},this)},this)}}),{get:function(a,c){var b=a._4;if(c===undefined)c=this.supportedConnectionTypes();var d=Faye.URI.parse(b).isLocal()?['long-polling','callback-polling']:['callback-polling'];var f=Faye.commonElement(d,c);if(!f)throw'Could not find a usable connection type for '+b;var g=this._i[f];return new g(a,b)},register:function(a,c){this._i[a]=c;c.prototype.connectionType=a},_i:{},supportedConnectionTypes:function(){var b=[],d;Faye.each(this._i,function(a,c){b.push(a)});return b}});Faye.XHRTransport=Faye.Class(Faye.Transport,{request:function(c,b,d){Faye.XHR.request('post',this._4,c,function(a){if(b)b.call(d,JSON.parse(a.text()))})}});Faye.Transport.register('long-polling',Faye.XHRTransport);Faye.JSONPTransport=Faye.extend(Faye.Class(Faye.Transport,{request:function(c,b,d){var f=document.getElementsByTagName('head')[0],g=document.createElement('script'),k=Faye.JSONPTransport.getCallbackName(),i=Faye.URI.parse(this._4,c);Faye.ENV[k]=function(a){Faye.ENV[k]=undefined;try{delete Faye.ENV[k]}catch(e){}f.removeChild(g);if(b)b.call(d,a)};i.params.jsonp=k;g.type='text/javascript';g.src=i.toURL();f.appendChild(g)}}),{_n:0,getCallbackName:function(){this._n+=1;return'__jsonp'+this._n+'__'}});Faye.Transport.register('callback-polling',Faye.JSONPTransport);Faye.Client=Faye.Class({_d:{},_w:{},_7:{},_x:{},_o:'handshake',_y:'retry',_p:'none',DEFAULT_ENDPOINT:'/bayeux',MAX_DELAY:0.1,INTERVAL:1000.0,initialize:function(a){this._4=a||this.DEFAULT_ENDPOINT;this._3=Faye.Transport.get(this);this._0=this._d;this._j=[];this._e=new Faye.Channel.Tree();this._6={reconnect:this._y,interval:this.INTERVAL};Faye.Event.on(Faye.ENV,'beforeunload',this.disconnect,this)},handshake:function(c,b){if(this._6.reconnect===this._p)return;if(this._0!==this._d)return;this._0=this._w;var d=this,f=this.generateId();this._3.send({channel:Faye.Channel.HANDSHAKE,version:Faye.BAYEUX_VERSION,supportedConnectionTypes:Faye.Transport.supportedConnectionTypes(),id:f},function(a){if(a.id!==f)return;if(!a.successful){setTimeout(function(){d.handshake(c,b)},this._6.interval);return this._0=this._d}this._0=this._7;this._8=a.clientId;this._3=Faye.Transport.get(this,a.supportedConnectionTypes);if(c)c.call(b)},this)},connect:function(c,b){if(this._6.reconnect===this._p)return;if(this._6.reconnect===this._o||this._0===this._d)return this.handshake(function(){this.connect(c,b)},this);if(this._0!==this._7)return;if(this._f)return;this._f=this.generateId();var d=this;this._3.send({channel:Faye.Channel.CONNECT,clientId:this._8,connectionType:this._3.connectionType,id:this._f},function(a){if(a.id!==this._f)return;delete this._f;if(a.successful)this.connect();else setTimeout(function(){d.connect()},this._6.interval)},this);if(c)c.call(b)},disconnect:function(){if(this._0!==this._7)return;this._0=this._x;this._3.send({channel:Faye.Channel.DISCONNECT,clientId:this._8});this._e=new Faye.Channel.Tree()},subscribe:function(b,d,f){if(this._0!==this._7)return;b=[].concat(b);this._k(b);var g=this.generateId();this._3.send({channel:Faye.Channel.SUBSCRIBE,clientId:this._8,subscription:b,id:g},function(c){if(c.id!==g)return;if(!c.successful)return;b=[].concat(c.subscription);Faye.each(b,function(a){this._e.set(a,[d,f])},this)},this)},unsubscribe:function(b,d,f){if(this._0!==this._7)return;b=[].concat(b);this._k(b);var g=this.generateId();this._3.send({channel:Faye.Channel.UNSUBSCRIBE,clientId:this._8,subscription:b,id:g},function(c){if(c.id!==g)return;if(!c.successful)return;b=[].concat(c.subscription);Faye.each(b,function(a){this._e.set(a,null)},this)},this)},publish:function(a,c){if(this._0!==this._7)return;this._k([a]);this.enqueue({channel:a,data:c,clientId:this._8});if(this._q)return;var b=this;this._q=setTimeout(function(){delete b._q;b.flush()},this.MAX_DELAY*1000)},generateId:function(a){a=a||32;return Math.floor(Math.pow(2,a)*Math.random()).toString(16)},enqueue:function(a){this._j.push(a)},flush:function(){this._3.send(this._j);this._j=[]},_k:function(c){Faye.each(c,function(a){if(!Faye.Channel.isValid(a))throw'"'+a+'" is not a valid channel name';if(!Faye.Channel.isSubscribable(a))throw'Clients may not subscribe to channel "'+a+'"';})},_u:function(a){Faye.extend(this._6,a);if(this._6.reconnect===this._o)this._8=null},_v:function(c){var b=this._e.glob(c.channel);Faye.each(b,function(a){if(!a)return;a[0].call(a[1],c.data)})}});if(!this.JSON){JSON={}}(function(){function l(a){return a<10?'0'+a:a}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(a){return this.getUTCFullYear()+'-'+l(this.getUTCMonth()+1)+'-'+l(this.getUTCDate())+'T'+l(this.getUTCHours())+':'+l(this.getUTCMinutes())+':'+l(this.getUTCSeconds())+'Z'};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()}}var n=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,o=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,j,p,s={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},m;function r(b){o.lastIndex=0;return o.test(b)?'"'+b.replace(o,function(a){var c=s[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+b+'"'}function q(a,c){var b,d,f,g,k=j,i,h=c[a];if(h&&typeof h==='object'&&typeof h.toJSON==='function'){h=h.toJSON(a)}if(typeof m==='function'){h=m.call(c,a,h)}switch(typeof h){case'string':return r(h);case'number':return isFinite(h)?String(h):'null';case'boolean':case'null':return String(h);case'object':if(!h){return'null'}j+=p;i=[];if(Object.prototype.toString.apply(h)==='[object Array]'){g=h.length;for(b=0;b<g;b+=1){i[b]=q(b,h)||'null'}f=i.length===0?'[]':j?'[\n'+j+i.join(',\n'+j)+'\n'+k+']':'['+i.join(',')+']';j=k;return f}if(m&&typeof m==='object'){g=m.length;for(b=0;b<g;b+=1){d=m[b];if(typeof d==='string'){f=q(d,h);if(f){i.push(r(d)+(j?': ':':')+f)}}}}else{for(d in h){if(Object.hasOwnProperty.call(h,d)){f=q(d,h);if(f){i.push(r(d)+(j?': ':':')+f)}}}}f=i.length===0?'{}':j?'{\n'+j+i.join(',\n'+j)+'\n'+k+'}':'{'+i.join(',')+'}';j=k;return f}}if(typeof JSON.stringify!=='function'){JSON.stringify=function(a,c,b){var d;j='';p='';if(typeof b==='number'){for(d=0;d<b;d+=1){p+=' '}}else if(typeof b==='string'){p=b}m=c;if(c&&typeof c!=='function'&&(typeof c!=='object'||typeof c.length!=='number')){throw new Error('JSON.stringify');}return q('',{'':a})}}if(typeof JSON.parse!=='function'){JSON.parse=function(g,k){var i;function h(a,c){var b,d,f=a[c];if(f&&typeof f==='object'){for(b in f){if(Object.hasOwnProperty.call(f,b)){d=h(f,b);if(d!==undefined){f[b]=d}else{delete f[b]}}}}return k.call(a,c,f)}n.lastIndex=0;if(n.test(g)){g=g.replace(n,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(g.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){i=eval('('+g+')');return typeof k==='function'?h({'':i},''):i}throw new SyntaxError('JSON.parse');}}}());