bladerunner 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +20 -0
- data/README.md +56 -0
- data/Rakefile +38 -0
- data/app/assets/javascripts/bladerunner/application.js +6 -0
- data/app/assets/javascripts/bladerunner/bladerunner.coffee +31 -0
- data/app/assets/javascripts/bladerunner/vendor/bootstrap.js +1999 -0
- data/app/assets/javascripts/bladerunner/vendor/jquery.js +8829 -0
- data/app/assets/javascripts/bladerunner/vendor/prettify-lang-sql.js +2 -0
- data/app/assets/javascripts/bladerunner/vendor/prettify.js +30 -0
- data/app/assets/javascripts/bladerunner/vendor/pubnub.js +1436 -0
- data/app/assets/stylesheets/bladerunner/application.css +7 -0
- data/app/assets/stylesheets/bladerunner/bladerunner.css.scss +17 -0
- data/app/assets/stylesheets/bladerunner/bootstrap-theme.css +384 -0
- data/app/assets/stylesheets/bladerunner/bootstrap.css +6805 -0
- data/app/assets/stylesheets/bladerunner/prettify-desert.css +34 -0
- data/app/assets/stylesheets/bladerunner/prettify.css +1 -0
- data/app/controllers/bladerunner/application_controller.rb +50 -0
- data/app/helpers/bladerunner/application_helper.rb +4 -0
- data/app/views/bladerunner/application/_query_info.html.erb +8 -0
- data/app/views/bladerunner/application/index.html.erb +14 -0
- data/app/views/bladerunner/application/run.html.erb +41 -0
- data/app/views/layouts/bladerunner/application.html.erb +34 -0
- data/config/routes.rb +5 -0
- data/lib/bladerunner.rb +4 -0
- data/lib/bladerunner/engine.rb +5 -0
- data/lib/bladerunner/version.rb +3 -0
- data/lib/tasks/bladerunner_tasks.rake +4 -0
- data/test/bladerunner_test.rb +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +65 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +31 -0
- data/test/dummy/config/environments/production.rb +64 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +10 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/log/development.log +202 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +9 -0
- data/test/test_helper.rb +15 -0
- metadata +162 -0
@@ -0,0 +1,2 @@
|
|
1
|
+
PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\r \xa0]+/,null,"\t\n\r \u00a0"],["str",/^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/,null,"\"'"]],[["com",/^(?:--[^\n\r]*|\/\*[\S\s]*?(?:\*\/|$))/],["kwd",/^(?:add|all|alter|and|any|apply|as|asc|authorization|backup|begin|between|break|browse|bulk|by|cascade|case|check|checkpoint|close|clustered|coalesce|collate|column|commit|compute|connect|constraint|contains|containstable|continue|convert|create|cross|current|current_date|current_time|current_timestamp|current_user|cursor|database|dbcc|deallocate|declare|default|delete|deny|desc|disk|distinct|distributed|double|drop|dummy|dump|else|end|errlvl|escape|except|exec|execute|exists|exit|fetch|file|fillfactor|following|for|foreign|freetext|freetexttable|from|full|function|goto|grant|group|having|holdlock|identity|identitycol|identity_insert|if|in|index|inner|insert|intersect|into|is|join|key|kill|left|like|lineno|load|match|matched|merge|natural|national|nocheck|nonclustered|nocycle|not|null|nullif|of|off|offsets|on|open|opendatasource|openquery|openrowset|openxml|option|or|order|outer|over|partition|percent|pivot|plan|preceding|precision|primary|print|proc|procedure|public|raiserror|read|readtext|reconfigure|references|replication|restore|restrict|return|revoke|right|rollback|rowcount|rowguidcol|rows?|rule|save|schema|select|session_user|set|setuser|shutdown|some|start|statistics|system_user|table|textsize|then|to|top|tran|transaction|trigger|truncate|tsequal|unbounded|union|unique|unpivot|update|updatetext|use|user|using|values|varying|view|waitfor|when|where|while|with|within|writetext|xml)(?=[^\w-]|$)/i,
|
2
|
+
null],["lit",/^[+-]?(?:0x[\da-f]+|(?:\.\d+|\d+(?:\.\d*)?)(?:e[+-]?\d+)?)/i],["pln",/^[_a-z][\w-]*/i],["pun",/^[^\w\t\n\r "'\xa0][^\w\t\n\r "'+\xa0-]*/]]),["sql"]);
|
@@ -0,0 +1,30 @@
|
|
1
|
+
!function(){var q=null;window.PR_SHOULD_USE_CONTINUATION=!0;
|
2
|
+
(function(){function S(a){function d(e){var b=e.charCodeAt(0);if(b!==92)return b;var a=e.charAt(1);return(b=r[a])?b:"0"<=a&&a<="7"?parseInt(e.substring(1),8):a==="u"||a==="x"?parseInt(e.substring(2),16):e.charCodeAt(1)}function g(e){if(e<32)return(e<16?"\\x0":"\\x")+e.toString(16);e=String.fromCharCode(e);return e==="\\"||e==="-"||e==="]"||e==="^"?"\\"+e:e}function b(e){var b=e.substring(1,e.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),e=[],a=
|
3
|
+
b[0]==="^",c=["["];a&&c.push("^");for(var a=a?1:0,f=b.length;a<f;++a){var h=b[a];if(/\\[bdsw]/i.test(h))c.push(h);else{var h=d(h),l;a+2<f&&"-"===b[a+1]?(l=d(b[a+2]),a+=2):l=h;e.push([h,l]);l<65||h>122||(l<65||h>90||e.push([Math.max(65,h)|32,Math.min(l,90)|32]),l<97||h>122||e.push([Math.max(97,h)&-33,Math.min(l,122)&-33]))}}e.sort(function(e,a){return e[0]-a[0]||a[1]-e[1]});b=[];f=[];for(a=0;a<e.length;++a)h=e[a],h[0]<=f[1]+1?f[1]=Math.max(f[1],h[1]):b.push(f=h);for(a=0;a<b.length;++a)h=b[a],c.push(g(h[0])),
|
4
|
+
h[1]>h[0]&&(h[1]+1>h[0]&&c.push("-"),c.push(g(h[1])));c.push("]");return c.join("")}function s(e){for(var a=e.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),c=a.length,d=[],f=0,h=0;f<c;++f){var l=a[f];l==="("?++h:"\\"===l.charAt(0)&&(l=+l.substring(1))&&(l<=h?d[l]=-1:a[f]=g(l))}for(f=1;f<d.length;++f)-1===d[f]&&(d[f]=++x);for(h=f=0;f<c;++f)l=a[f],l==="("?(++h,d[h]||(a[f]="(?:")):"\\"===l.charAt(0)&&(l=+l.substring(1))&&l<=h&&
|
5
|
+
(a[f]="\\"+d[l]);for(f=0;f<c;++f)"^"===a[f]&&"^"!==a[f+1]&&(a[f]="");if(e.ignoreCase&&m)for(f=0;f<c;++f)l=a[f],e=l.charAt(0),l.length>=2&&e==="["?a[f]=b(l):e!=="\\"&&(a[f]=l.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return a.join("")}for(var x=0,m=!1,j=!1,k=0,c=a.length;k<c;++k){var i=a[k];if(i.ignoreCase)j=!0;else if(/[a-z]/i.test(i.source.replace(/\\u[\da-f]{4}|\\x[\da-f]{2}|\\[^UXux]/gi,""))){m=!0;j=!1;break}}for(var r={b:8,t:9,n:10,v:11,
|
6
|
+
f:12,r:13},n=[],k=0,c=a.length;k<c;++k){i=a[k];if(i.global||i.multiline)throw Error(""+i);n.push("(?:"+s(i)+")")}return RegExp(n.join("|"),j?"gi":"g")}function T(a,d){function g(a){var c=a.nodeType;if(c==1){if(!b.test(a.className)){for(c=a.firstChild;c;c=c.nextSibling)g(c);c=a.nodeName.toLowerCase();if("br"===c||"li"===c)s[j]="\n",m[j<<1]=x++,m[j++<<1|1]=a}}else if(c==3||c==4)c=a.nodeValue,c.length&&(c=d?c.replace(/\r\n?/g,"\n"):c.replace(/[\t\n\r ]+/g," "),s[j]=c,m[j<<1]=x,x+=c.length,m[j++<<1|1]=
|
7
|
+
a)}var b=/(?:^|\s)nocode(?:\s|$)/,s=[],x=0,m=[],j=0;g(a);return{a:s.join("").replace(/\n$/,""),d:m}}function H(a,d,g,b){d&&(a={a:d,e:a},g(a),b.push.apply(b,a.g))}function U(a){for(var d=void 0,g=a.firstChild;g;g=g.nextSibling)var b=g.nodeType,d=b===1?d?a:g:b===3?V.test(g.nodeValue)?a:d:d;return d===a?void 0:d}function C(a,d){function g(a){for(var j=a.e,k=[j,"pln"],c=0,i=a.a.match(s)||[],r={},n=0,e=i.length;n<e;++n){var z=i[n],w=r[z],t=void 0,f;if(typeof w==="string")f=!1;else{var h=b[z.charAt(0)];
|
8
|
+
if(h)t=z.match(h[1]),w=h[0];else{for(f=0;f<x;++f)if(h=d[f],t=z.match(h[1])){w=h[0];break}t||(w="pln")}if((f=w.length>=5&&"lang-"===w.substring(0,5))&&!(t&&typeof t[1]==="string"))f=!1,w="src";f||(r[z]=w)}h=c;c+=z.length;if(f){f=t[1];var l=z.indexOf(f),B=l+f.length;t[2]&&(B=z.length-t[2].length,l=B-f.length);w=w.substring(5);H(j+h,z.substring(0,l),g,k);H(j+h+l,f,I(w,f),k);H(j+h+B,z.substring(B),g,k)}else k.push(j+h,w)}a.g=k}var b={},s;(function(){for(var g=a.concat(d),j=[],k={},c=0,i=g.length;c<i;++c){var r=
|
9
|
+
g[c],n=r[3];if(n)for(var e=n.length;--e>=0;)b[n.charAt(e)]=r;r=r[1];n=""+r;k.hasOwnProperty(n)||(j.push(r),k[n]=q)}j.push(/[\S\s]/);s=S(j)})();var x=d.length;return g}function v(a){var d=[],g=[];a.tripleQuotedStrings?d.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?d.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/,
|
10
|
+
q,"'\"`"]):d.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&g.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var b=a.hashComments;b&&(a.cStyleComments?(b>1?d.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):d.push(["com",/^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),g.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h(?:h|pp|\+\+)?|[a-z]\w*)>/,q])):d.push(["com",
|
11
|
+
/^#[^\n\r]*/,q,"#"]));a.cStyleComments&&(g.push(["com",/^\/\/[^\n\r]*/,q]),g.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));if(b=a.regexLiterals){var s=(b=b>1?"":"\n\r")?".":"[\\S\\s]";g.push(["lang-regex",RegExp("^(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<<?=?|>>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*("+("/(?=[^/*"+b+"])(?:[^/\\x5B\\x5C"+b+"]|\\x5C"+s+"|\\x5B(?:[^\\x5C\\x5D"+b+"]|\\x5C"+
|
12
|
+
s+")*(?:\\x5D|$))+/")+")")])}(b=a.types)&&g.push(["typ",b]);b=(""+a.keywords).replace(/^ | $/g,"");b.length&&g.push(["kwd",RegExp("^(?:"+b.replace(/[\s,]+/g,"|")+")\\b"),q]);d.push(["pln",/^\s+/,q," \r\n\t\u00a0"]);b="^.[^\\s\\w.$@'\"`/\\\\]*";a.regexLiterals&&(b+="(?!s*/)");g.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,
|
13
|
+
q],["pun",RegExp(b),q]);return C(d,g)}function J(a,d,g){function b(a){var c=a.nodeType;if(c==1&&!x.test(a.className))if("br"===a.nodeName)s(a),a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)b(a);else if((c==3||c==4)&&g){var d=a.nodeValue,i=d.match(m);if(i)c=d.substring(0,i.index),a.nodeValue=c,(d=d.substring(i.index+i[0].length))&&a.parentNode.insertBefore(j.createTextNode(d),a.nextSibling),s(a),c||a.parentNode.removeChild(a)}}function s(a){function b(a,c){var d=
|
14
|
+
c?a.cloneNode(!1):a,e=a.parentNode;if(e){var e=b(e,1),g=a.nextSibling;e.appendChild(d);for(var i=g;i;i=g)g=i.nextSibling,e.appendChild(i)}return d}for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),d;(d=a.parentNode)&&d.nodeType===1;)a=d;c.push(a)}for(var x=/(?:^|\s)nocode(?:\s|$)/,m=/\r\n?|\n/,j=a.ownerDocument,k=j.createElement("li");a.firstChild;)k.appendChild(a.firstChild);for(var c=[k],i=0;i<c.length;++i)b(c[i]);d===(d|0)&&c[0].setAttribute("value",d);var r=j.createElement("ol");
|
15
|
+
r.className="linenums";for(var d=Math.max(0,d-1|0)||0,i=0,n=c.length;i<n;++i)k=c[i],k.className="L"+(i+d)%10,k.firstChild||k.appendChild(j.createTextNode("\u00a0")),r.appendChild(k);a.appendChild(r)}function p(a,d){for(var g=d.length;--g>=0;){var b=d[g];F.hasOwnProperty(b)?D.console&&console.warn("cannot override language handler %s",b):F[b]=a}}function I(a,d){if(!a||!F.hasOwnProperty(a))a=/^\s*</.test(d)?"default-markup":"default-code";return F[a]}function K(a){var d=a.h;try{var g=T(a.c,a.i),b=g.a;
|
16
|
+
a.a=b;a.d=g.d;a.e=0;I(d,b)(a);var s=/\bMSIE\s(\d+)/.exec(navigator.userAgent),s=s&&+s[1]<=8,d=/\n/g,x=a.a,m=x.length,g=0,j=a.d,k=j.length,b=0,c=a.g,i=c.length,r=0;c[i]=m;var n,e;for(e=n=0;e<i;)c[e]!==c[e+2]?(c[n++]=c[e++],c[n++]=c[e++]):e+=2;i=n;for(e=n=0;e<i;){for(var p=c[e],w=c[e+1],t=e+2;t+2<=i&&c[t+1]===w;)t+=2;c[n++]=p;c[n++]=w;e=t}c.length=n;var f=a.c,h;if(f)h=f.style.display,f.style.display="none";try{for(;b<k;){var l=j[b+2]||m,B=c[r+2]||m,t=Math.min(l,B),A=j[b+1],G;if(A.nodeType!==1&&(G=x.substring(g,
|
17
|
+
t))){s&&(G=G.replace(d,"\r"));A.nodeValue=G;var L=A.ownerDocument,o=L.createElement("span");o.className=c[r+1];var v=A.parentNode;v.replaceChild(o,A);o.appendChild(A);g<l&&(j[b+1]=A=L.createTextNode(x.substring(t,l)),v.insertBefore(A,o.nextSibling))}g=t;g>=l&&(b+=2);g>=B&&(r+=2)}}finally{if(f)f.style.display=h}}catch(u){D.console&&console.log(u&&u.stack||u)}}var D=window,y=["break,continue,do,else,for,if,return,while"],E=[[y,"auto,case,char,const,default,double,enum,extern,float,goto,inline,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],
|
18
|
+
"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],M=[E,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,delegate,dynamic_cast,explicit,export,friend,generic,late_check,mutable,namespace,nullptr,property,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],N=[E,"abstract,assert,boolean,byte,extends,final,finally,implements,import,instanceof,interface,null,native,package,strictfp,super,synchronized,throws,transient"],
|
19
|
+
O=[N,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,internal,into,is,let,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var,virtual,where"],E=[E,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],P=[y,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],
|
20
|
+
Q=[y,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],W=[y,"as,assert,const,copy,drop,enum,extern,fail,false,fn,impl,let,log,loop,match,mod,move,mut,priv,pub,pure,ref,self,static,struct,true,trait,type,unsafe,use"],y=[y,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],R=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)\b/,
|
21
|
+
V=/\S/,X=v({keywords:[M,O,E,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",P,Q,y],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),F={};p(X,["default-code"]);p(C([],[["pln",/^[^<?]+/],["dec",/^<!\w[^>]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",
|
22
|
+
/^<xmp\b[^>]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);p(C([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],
|
23
|
+
["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css",/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);p(C([],[["atv",/^[\S\s]+/]]),["uq.val"]);p(v({keywords:M,hashComments:!0,cStyleComments:!0,types:R}),["c","cc","cpp","cxx","cyc","m"]);p(v({keywords:"null,true,false"}),["json"]);p(v({keywords:O,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:R}),
|
24
|
+
["cs"]);p(v({keywords:N,cStyleComments:!0}),["java"]);p(v({keywords:y,hashComments:!0,multiLineStrings:!0}),["bash","bsh","csh","sh"]);p(v({keywords:P,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),["cv","py","python"]);p(v({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:2}),["perl","pl","pm"]);p(v({keywords:Q,
|
25
|
+
hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb","ruby"]);p(v({keywords:E,cStyleComments:!0,regexLiterals:!0}),["javascript","js"]);p(v({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,throw,true,try,unless,until,when,while,yes",hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);p(v({keywords:W,cStyleComments:!0,multilineStrings:!0}),["rc","rs","rust"]);
|
26
|
+
p(C([],[["str",/^[\S\s]+/]]),["regex"]);var Y=D.PR={createSimpleLexer:C,registerLangHandler:p,sourceDecorator:v,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ",prettyPrintOne:D.prettyPrintOne=function(a,d,g){var b=document.createElement("div");b.innerHTML="<pre>"+a+"</pre>";b=b.firstChild;g&&J(b,g,!0);K({h:d,j:g,c:b,i:1});
|
27
|
+
return b.innerHTML},prettyPrint:D.prettyPrint=function(a,d){function g(){for(var b=D.PR_SHOULD_USE_CONTINUATION?c.now()+250:Infinity;i<p.length&&c.now()<b;i++){for(var d=p[i],j=h,k=d;k=k.previousSibling;){var m=k.nodeType,o=(m===7||m===8)&&k.nodeValue;if(o?!/^\??prettify\b/.test(o):m!==3||/\S/.test(k.nodeValue))break;if(o){j={};o.replace(/\b(\w+)=([\w%+\-.:]+)/g,function(a,b,c){j[b]=c});break}}k=d.className;if((j!==h||e.test(k))&&!v.test(k)){m=!1;for(o=d.parentNode;o;o=o.parentNode)if(f.test(o.tagName)&&
|
28
|
+
o.className&&e.test(o.className)){m=!0;break}if(!m){d.className+=" prettyprinted";m=j.lang;if(!m){var m=k.match(n),y;if(!m&&(y=U(d))&&t.test(y.tagName))m=y.className.match(n);m&&(m=m[1])}if(w.test(d.tagName))o=1;else var o=d.currentStyle,u=s.defaultView,o=(o=o?o.whiteSpace:u&&u.getComputedStyle?u.getComputedStyle(d,q).getPropertyValue("white-space"):0)&&"pre"===o.substring(0,3);u=j.linenums;if(!(u=u==="true"||+u))u=(u=k.match(/\blinenums\b(?::(\d+))?/))?u[1]&&u[1].length?+u[1]:!0:!1;u&&J(d,u,o);r=
|
29
|
+
{h:m,c:d,j:u,i:o};K(r)}}}i<p.length?setTimeout(g,250):"function"===typeof a&&a()}for(var b=d||document.body,s=b.ownerDocument||document,b=[b.getElementsByTagName("pre"),b.getElementsByTagName("code"),b.getElementsByTagName("xmp")],p=[],m=0;m<b.length;++m)for(var j=0,k=b[m].length;j<k;++j)p.push(b[m][j]);var b=q,c=Date;c.now||(c={now:function(){return+new Date}});var i=0,r,n=/\blang(?:uage)?-([\w.]+)(?!\S)/,e=/\bprettyprint\b/,v=/\bprettyprinted\b/,w=/pre|xmp/i,t=/^code$/i,f=/^(?:pre|code|xmp)$/i,
|
30
|
+
h={};g()}};typeof define==="function"&&define.amd&&define("google-code-prettify",[],function(){return Y})})();}()
|
@@ -0,0 +1,1436 @@
|
|
1
|
+
// Version: 3.5.3.1
|
2
|
+
/* =-====================================================================-= */
|
3
|
+
/* =-====================================================================-= */
|
4
|
+
/* =-========================= JSON =============================-= */
|
5
|
+
/* =-====================================================================-= */
|
6
|
+
/* =-====================================================================-= */
|
7
|
+
|
8
|
+
(window['JSON'] && window['JSON']['stringify']) || (function () {
|
9
|
+
window['JSON'] || (window['JSON'] = {});
|
10
|
+
|
11
|
+
function toJSON(key) {
|
12
|
+
try { return this.valueOf() }
|
13
|
+
catch(e) { return null }
|
14
|
+
}
|
15
|
+
|
16
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
17
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
18
|
+
gap,
|
19
|
+
indent,
|
20
|
+
meta = { // table of character substitutions
|
21
|
+
'\b': '\\b',
|
22
|
+
'\t': '\\t',
|
23
|
+
'\n': '\\n',
|
24
|
+
'\f': '\\f',
|
25
|
+
'\r': '\\r',
|
26
|
+
'"' : '\\"',
|
27
|
+
'\\': '\\\\'
|
28
|
+
},
|
29
|
+
rep;
|
30
|
+
|
31
|
+
function quote(string) {
|
32
|
+
escapable.lastIndex = 0;
|
33
|
+
return escapable.test(string) ?
|
34
|
+
'"' + string.replace(escapable, function (a) {
|
35
|
+
var c = meta[a];
|
36
|
+
return typeof c === 'string' ? c :
|
37
|
+
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
38
|
+
}) + '"' :
|
39
|
+
'"' + string + '"';
|
40
|
+
}
|
41
|
+
|
42
|
+
function str(key, holder) {
|
43
|
+
var i, // The loop counter.
|
44
|
+
k, // The member key.
|
45
|
+
v, // The member value.
|
46
|
+
length,
|
47
|
+
partial,
|
48
|
+
mind = gap,
|
49
|
+
value = holder[key];
|
50
|
+
|
51
|
+
if (value && typeof value === 'object') {
|
52
|
+
value = toJSON.call( value, key );
|
53
|
+
}
|
54
|
+
|
55
|
+
if (typeof rep === 'function') {
|
56
|
+
value = rep.call(holder, key, value);
|
57
|
+
}
|
58
|
+
|
59
|
+
switch (typeof value) {
|
60
|
+
case 'string':
|
61
|
+
return quote(value);
|
62
|
+
|
63
|
+
case 'number':
|
64
|
+
return isFinite(value) ? String(value) : 'null';
|
65
|
+
|
66
|
+
case 'boolean':
|
67
|
+
case 'null':
|
68
|
+
return String(value);
|
69
|
+
|
70
|
+
case 'object':
|
71
|
+
|
72
|
+
if (!value) {
|
73
|
+
return 'null';
|
74
|
+
}
|
75
|
+
|
76
|
+
gap += indent;
|
77
|
+
partial = [];
|
78
|
+
|
79
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
80
|
+
|
81
|
+
length = value.length;
|
82
|
+
for (i = 0; i < length; i += 1) {
|
83
|
+
partial[i] = str(i, value) || 'null';
|
84
|
+
}
|
85
|
+
|
86
|
+
v = partial.length === 0 ? '[]' :
|
87
|
+
gap ? '[\n' + gap +
|
88
|
+
partial.join(',\n' + gap) + '\n' +
|
89
|
+
mind + ']' :
|
90
|
+
'[' + partial.join(',') + ']';
|
91
|
+
gap = mind;
|
92
|
+
return v;
|
93
|
+
}
|
94
|
+
if (rep && typeof rep === 'object') {
|
95
|
+
length = rep.length;
|
96
|
+
for (i = 0; i < length; i += 1) {
|
97
|
+
k = rep[i];
|
98
|
+
if (typeof k === 'string') {
|
99
|
+
v = str(k, value);
|
100
|
+
if (v) {
|
101
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
} else {
|
106
|
+
for (k in value) {
|
107
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
108
|
+
v = str(k, value);
|
109
|
+
if (v) {
|
110
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
v = partial.length === 0 ? '{}' :
|
117
|
+
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
118
|
+
mind + '}' : '{' + partial.join(',') + '}';
|
119
|
+
gap = mind;
|
120
|
+
return v;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
if (typeof JSON['stringify'] !== 'function') {
|
125
|
+
JSON['stringify'] = function (value, replacer, space) {
|
126
|
+
var i;
|
127
|
+
gap = '';
|
128
|
+
indent = '';
|
129
|
+
|
130
|
+
if (typeof space === 'number') {
|
131
|
+
for (i = 0; i < space; i += 1) {
|
132
|
+
indent += ' ';
|
133
|
+
}
|
134
|
+
} else if (typeof space === 'string') {
|
135
|
+
indent = space;
|
136
|
+
}
|
137
|
+
rep = replacer;
|
138
|
+
if (replacer && typeof replacer !== 'function' &&
|
139
|
+
(typeof replacer !== 'object' ||
|
140
|
+
typeof replacer.length !== 'number')) {
|
141
|
+
throw new Error('JSON.stringify');
|
142
|
+
}
|
143
|
+
return str('', {'': value});
|
144
|
+
};
|
145
|
+
}
|
146
|
+
|
147
|
+
if (typeof JSON['parse'] !== 'function') {
|
148
|
+
// JSON is parsed on the server for security.
|
149
|
+
JSON['parse'] = function (text) {return eval('('+text+')')};
|
150
|
+
}
|
151
|
+
}());
|
152
|
+
var NOW = 1
|
153
|
+
, READY = false
|
154
|
+
, READY_BUFFER = []
|
155
|
+
, PRESENCE_SUFFIX = '-pnpres'
|
156
|
+
, DEF_WINDOWING = 10 // MILLISECONDS.
|
157
|
+
, DEF_TIMEOUT = 10000 // MILLISECONDS.
|
158
|
+
, DEF_SUB_TIMEOUT = 310 // SECONDS.
|
159
|
+
, DEF_KEEPALIVE = 60 // SECONDS.
|
160
|
+
, SECOND = 1000 // A THOUSAND MILLISECONDS.
|
161
|
+
, URLBIT = '/'
|
162
|
+
, PARAMSBIT = '&'
|
163
|
+
, REPL = /{([\w\-]+)}/g;
|
164
|
+
|
165
|
+
/**
|
166
|
+
* UTILITIES
|
167
|
+
*/
|
168
|
+
function unique() { return'x'+ ++NOW+''+(+new Date) }
|
169
|
+
function rnow() { return+new Date }
|
170
|
+
|
171
|
+
/**
|
172
|
+
* NEXTORIGIN
|
173
|
+
* ==========
|
174
|
+
* var next_origin = nextorigin();
|
175
|
+
*/
|
176
|
+
var nextorigin = (function() {
|
177
|
+
var max = 20
|
178
|
+
, ori = Math.floor(Math.random() * max);
|
179
|
+
return function( origin, failover ) {
|
180
|
+
return origin.indexOf('pubsub.') > 0
|
181
|
+
&& origin.replace(
|
182
|
+
'pubsub', 'ps' + (
|
183
|
+
failover ? uuid().split('-')[0] :
|
184
|
+
(++ori < max? ori : ori=1)
|
185
|
+
) ) || origin;
|
186
|
+
}
|
187
|
+
})();
|
188
|
+
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Build Url
|
192
|
+
* =======
|
193
|
+
*
|
194
|
+
*/
|
195
|
+
function build_url( url_components, url_params ) {
|
196
|
+
var url = url_components.join(URLBIT)
|
197
|
+
, params = [];
|
198
|
+
|
199
|
+
if (!url_params) return url;
|
200
|
+
|
201
|
+
each( url_params, function( key, value ) {
|
202
|
+
params.push(key + "=" + encode(value));
|
203
|
+
} );
|
204
|
+
|
205
|
+
url += "?" + params.join(PARAMSBIT);
|
206
|
+
|
207
|
+
return url;
|
208
|
+
}
|
209
|
+
|
210
|
+
/**
|
211
|
+
* UPDATER
|
212
|
+
* =======
|
213
|
+
* var timestamp = unique();
|
214
|
+
*/
|
215
|
+
function updater( fun, rate ) {
|
216
|
+
var timeout
|
217
|
+
, last = 0
|
218
|
+
, runnit = function() {
|
219
|
+
if (last + rate > rnow()) {
|
220
|
+
clearTimeout(timeout);
|
221
|
+
timeout = setTimeout( runnit, rate );
|
222
|
+
}
|
223
|
+
else {
|
224
|
+
last = rnow();
|
225
|
+
fun();
|
226
|
+
}
|
227
|
+
};
|
228
|
+
|
229
|
+
return runnit;
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* GREP
|
234
|
+
* ====
|
235
|
+
* var list = grep( [1,2,3], function(item) { return item % 2 } )
|
236
|
+
*/
|
237
|
+
function grep( list, fun ) {
|
238
|
+
var fin = [];
|
239
|
+
each( list || [], function(l) { fun(l) && fin.push(l) } );
|
240
|
+
return fin
|
241
|
+
}
|
242
|
+
|
243
|
+
/**
|
244
|
+
* SUPPLANT
|
245
|
+
* ========
|
246
|
+
* var text = supplant( 'Hello {name}!', { name : 'John' } )
|
247
|
+
*/
|
248
|
+
function supplant( str, values ) {
|
249
|
+
return str.replace( REPL, function( _, match ) {
|
250
|
+
return values[match] || _
|
251
|
+
} );
|
252
|
+
}
|
253
|
+
|
254
|
+
/**
|
255
|
+
* timeout
|
256
|
+
* =======
|
257
|
+
* timeout( function(){}, 100 );
|
258
|
+
*/
|
259
|
+
function timeout( fun, wait ) {
|
260
|
+
return setTimeout( fun, wait );
|
261
|
+
}
|
262
|
+
|
263
|
+
/**
|
264
|
+
* uuid
|
265
|
+
* ====
|
266
|
+
* var my_uuid = uuid();
|
267
|
+
*/
|
268
|
+
function uuid(callback) {
|
269
|
+
var u = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
|
270
|
+
function(c) {
|
271
|
+
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
272
|
+
return v.toString(16);
|
273
|
+
});
|
274
|
+
if (callback) callback(u);
|
275
|
+
return u;
|
276
|
+
}
|
277
|
+
|
278
|
+
/**
|
279
|
+
* EACH
|
280
|
+
* ====
|
281
|
+
* each( [1,2,3], function(item) { } )
|
282
|
+
*/
|
283
|
+
function each( o, f ) {
|
284
|
+
if ( !o || !f ) return;
|
285
|
+
|
286
|
+
if ( typeof o[0] != 'undefined' )
|
287
|
+
for ( var i = 0, l = o.length; i < l; )
|
288
|
+
f.call( o[i], o[i], i++ );
|
289
|
+
else
|
290
|
+
for ( var i in o )
|
291
|
+
o.hasOwnProperty &&
|
292
|
+
o.hasOwnProperty(i) &&
|
293
|
+
f.call( o[i], i, o[i] );
|
294
|
+
}
|
295
|
+
|
296
|
+
/**
|
297
|
+
* MAP
|
298
|
+
* ===
|
299
|
+
* var list = map( [1,2,3], function(item) { return item + 1 } )
|
300
|
+
*/
|
301
|
+
function map( list, fun ) {
|
302
|
+
var fin = [];
|
303
|
+
each( list || [], function( k, v ) { fin.push(fun( k, v )) } );
|
304
|
+
return fin;
|
305
|
+
}
|
306
|
+
|
307
|
+
/**
|
308
|
+
* ENCODE
|
309
|
+
* ======
|
310
|
+
* var encoded_path = encode('path');
|
311
|
+
*/
|
312
|
+
function encode(path) {
|
313
|
+
return map( (encodeURIComponent(path)).split(''), function(chr) {
|
314
|
+
return "-_.!~*'()".indexOf(chr) < 0 ? chr :
|
315
|
+
"%"+chr.charCodeAt(0).toString(16).toUpperCase()
|
316
|
+
} ).join('');
|
317
|
+
}
|
318
|
+
|
319
|
+
/**
|
320
|
+
* Generate Subscription Channel List
|
321
|
+
* ==================================
|
322
|
+
* generate_channel_list(channels_object);
|
323
|
+
*/
|
324
|
+
function generate_channel_list(channels) {
|
325
|
+
var list = [];
|
326
|
+
each( channels, function( channel, status ) {
|
327
|
+
if (status.subscribed) list.push(channel);
|
328
|
+
} );
|
329
|
+
return list.sort();
|
330
|
+
}
|
331
|
+
|
332
|
+
// PUBNUB READY TO CONNECT
|
333
|
+
function ready() { timeout( function() {
|
334
|
+
if (READY) return;
|
335
|
+
READY = 1;
|
336
|
+
each( READY_BUFFER, function(connect) { connect() } );
|
337
|
+
}, SECOND ); }
|
338
|
+
|
339
|
+
function PN_API(setup) {
|
340
|
+
var SUB_WINDOWING = +setup['windowing'] || DEF_WINDOWING
|
341
|
+
, SUB_TIMEOUT = (+setup['timeout'] || DEF_SUB_TIMEOUT) * SECOND
|
342
|
+
, KEEPALIVE = (+setup['keepalive'] || DEF_KEEPALIVE) * SECOND
|
343
|
+
, NOLEAVE = setup['noleave'] || 0
|
344
|
+
, PUBLISH_KEY = setup['publish_key'] || ''
|
345
|
+
, SUBSCRIBE_KEY = setup['subscribe_key'] || ''
|
346
|
+
, AUTH_KEY = setup['auth_key'] || ''
|
347
|
+
, SSL = setup['ssl'] ? 's' : ''
|
348
|
+
, ORIGIN = 'http'+SSL+'://'+(setup['origin']||'pubsub.pubnub.com')
|
349
|
+
, STD_ORIGIN = nextorigin(ORIGIN)
|
350
|
+
, SUB_ORIGIN = nextorigin(ORIGIN)
|
351
|
+
, CONNECT = function(){}
|
352
|
+
, PUB_QUEUE = []
|
353
|
+
, SUB_CALLBACK = 0
|
354
|
+
, SUB_CHANNEL = 0
|
355
|
+
, SUB_RECEIVER = 0
|
356
|
+
, SUB_RESTORE = 0
|
357
|
+
, SUB_BUFF_WAIT = 0
|
358
|
+
, TIMETOKEN = 0
|
359
|
+
, CHANNELS = {}
|
360
|
+
, xdr = setup['xdr']
|
361
|
+
, error = setup['error'] || function() {}
|
362
|
+
, _is_online = setup['_is_online'] || function() { return 1 }
|
363
|
+
, jsonp_cb = setup['jsonp_cb'] || function() { return 0 }
|
364
|
+
, db = setup['db'] || {'get': function(){}, 'set': function(){}}
|
365
|
+
, UUID = setup['uuid'] || ( db && db['get'](SUBSCRIBE_KEY+'uuid') || '');
|
366
|
+
|
367
|
+
function publish(next) {
|
368
|
+
if (next) PUB_QUEUE.sending = 0;
|
369
|
+
if (PUB_QUEUE.sending || !PUB_QUEUE.length) return;
|
370
|
+
PUB_QUEUE.sending = 1;
|
371
|
+
xdr(PUB_QUEUE.shift());
|
372
|
+
}
|
373
|
+
|
374
|
+
function each_channel(callback) {
|
375
|
+
var count = 0;
|
376
|
+
|
377
|
+
each( generate_channel_list(CHANNELS), function(channel) {
|
378
|
+
var chan = CHANNELS[channel];
|
379
|
+
|
380
|
+
if (!chan) return;
|
381
|
+
|
382
|
+
count++;
|
383
|
+
(callback||function(){})(chan);
|
384
|
+
} );
|
385
|
+
|
386
|
+
return count;
|
387
|
+
}
|
388
|
+
|
389
|
+
// Announce Leave Event
|
390
|
+
var SELF = {
|
391
|
+
'LEAVE' : function( channel, blocking ) {
|
392
|
+
var data = { 'uuid' : UUID, 'auth' : AUTH_KEY }
|
393
|
+
, origin = nextorigin(ORIGIN)
|
394
|
+
, jsonp = jsonp_cb();
|
395
|
+
|
396
|
+
// Prevent Leaving a Presence Channel
|
397
|
+
if (channel.indexOf(PRESENCE_SUFFIX) > 0) return;
|
398
|
+
|
399
|
+
// No Leave Patch (Prevent Blocking Leave if Desired)
|
400
|
+
if (NOLEAVE) return;
|
401
|
+
|
402
|
+
if (jsonp != '0') data['callback'] = jsonp;
|
403
|
+
|
404
|
+
xdr({
|
405
|
+
blocking : blocking || SSL,
|
406
|
+
timeout : 2000,
|
407
|
+
callback : jsonp,
|
408
|
+
data : data,
|
409
|
+
url : [
|
410
|
+
origin, 'v2', 'presence', 'sub_key',
|
411
|
+
SUBSCRIBE_KEY, 'channel', encode(channel), 'leave'
|
412
|
+
]
|
413
|
+
});
|
414
|
+
},
|
415
|
+
/*
|
416
|
+
PUBNUB.history({
|
417
|
+
channel : 'my_chat_channel',
|
418
|
+
limit : 100,
|
419
|
+
callback : function(history) { }
|
420
|
+
});
|
421
|
+
*/
|
422
|
+
'history' : function( args, callback ) {
|
423
|
+
var callback = args['callback'] || callback
|
424
|
+
, count = args['count'] || args['limit'] || 100
|
425
|
+
, reverse = args['reverse'] || "false"
|
426
|
+
, err = args['error'] || function(){}
|
427
|
+
, channel = args['channel']
|
428
|
+
, start = args['start']
|
429
|
+
, end = args['end']
|
430
|
+
, params = {}
|
431
|
+
, jsonp = jsonp_cb();
|
432
|
+
|
433
|
+
// Make sure we have a Channel
|
434
|
+
if (!channel) return error('Missing Channel');
|
435
|
+
if (!callback) return error('Missing Callback');
|
436
|
+
if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
|
437
|
+
|
438
|
+
params['stringtoken'] = 'true';
|
439
|
+
params['count'] = count;
|
440
|
+
params['reverse'] = reverse;
|
441
|
+
params['auth'] = AUTH_KEY;
|
442
|
+
|
443
|
+
if (jsonp) params['callback'] = jsonp;
|
444
|
+
if (start) params['start'] = start;
|
445
|
+
if (end) params['end'] = end;
|
446
|
+
|
447
|
+
// Send Message
|
448
|
+
xdr({
|
449
|
+
callback : jsonp,
|
450
|
+
data : params,
|
451
|
+
success : function(response) { callback(response) },
|
452
|
+
fail : err,
|
453
|
+
url : [
|
454
|
+
STD_ORIGIN, 'v2', 'history', 'sub-key',
|
455
|
+
SUBSCRIBE_KEY, 'channel', encode(channel)
|
456
|
+
]
|
457
|
+
});
|
458
|
+
},
|
459
|
+
|
460
|
+
/*
|
461
|
+
PUBNUB.replay({
|
462
|
+
source : 'my_channel',
|
463
|
+
destination : 'new_channel'
|
464
|
+
});
|
465
|
+
*/
|
466
|
+
'replay' : function(args) {
|
467
|
+
var callback = callback || args['callback'] || function(){}
|
468
|
+
, source = args['source']
|
469
|
+
, destination = args['destination']
|
470
|
+
, stop = args['stop']
|
471
|
+
, start = args['start']
|
472
|
+
, end = args['end']
|
473
|
+
, reverse = args['reverse']
|
474
|
+
, limit = args['limit']
|
475
|
+
, jsonp = jsonp_cb()
|
476
|
+
, data = {}
|
477
|
+
, url;
|
478
|
+
|
479
|
+
// Check User Input
|
480
|
+
if (!source) return error('Missing Source Channel');
|
481
|
+
if (!destination) return error('Missing Destination Channel');
|
482
|
+
if (!PUBLISH_KEY) return error('Missing Publish Key');
|
483
|
+
if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
|
484
|
+
|
485
|
+
// Setup URL Params
|
486
|
+
if (jsonp != '0') data['callback'] = jsonp;
|
487
|
+
if (stop) data['stop'] = 'all';
|
488
|
+
if (reverse) data['reverse'] = 'true';
|
489
|
+
if (start) data['start'] = start;
|
490
|
+
if (end) data['end'] = end;
|
491
|
+
if (limit) data['count'] = limit;
|
492
|
+
|
493
|
+
data['auth'] = AUTH_KEY;
|
494
|
+
|
495
|
+
// Compose URL Parts
|
496
|
+
url = [
|
497
|
+
STD_ORIGIN, 'v1', 'replay',
|
498
|
+
PUBLISH_KEY, SUBSCRIBE_KEY,
|
499
|
+
source, destination
|
500
|
+
];
|
501
|
+
|
502
|
+
// Start (or Stop) Replay!
|
503
|
+
xdr({
|
504
|
+
callback : jsonp,
|
505
|
+
success : function(response) { callback(response) },
|
506
|
+
fail : function() { callback([ 0, 'Disconnected' ]) },
|
507
|
+
url : url,
|
508
|
+
data : data
|
509
|
+
});
|
510
|
+
},
|
511
|
+
|
512
|
+
/*
|
513
|
+
PUBNUB.auth('AJFLKAJSDKLA');
|
514
|
+
*/
|
515
|
+
'auth' : function(auth) {
|
516
|
+
AUTH_KEY = auth;
|
517
|
+
CONNECT();
|
518
|
+
},
|
519
|
+
|
520
|
+
/*
|
521
|
+
PUBNUB.time(function(time){ });
|
522
|
+
*/
|
523
|
+
'time' : function(callback) {
|
524
|
+
var jsonp = jsonp_cb();
|
525
|
+
xdr({
|
526
|
+
callback : jsonp,
|
527
|
+
data : { 'uuid' : UUID, 'auth' : AUTH_KEY },
|
528
|
+
timeout : SECOND * 5,
|
529
|
+
url : [STD_ORIGIN, 'time', jsonp],
|
530
|
+
success : function(response) { callback(response[0]) },
|
531
|
+
fail : function() { callback(0) }
|
532
|
+
});
|
533
|
+
},
|
534
|
+
|
535
|
+
/*
|
536
|
+
PUBNUB.publish({
|
537
|
+
channel : 'my_chat_channel',
|
538
|
+
message : 'hello!'
|
539
|
+
});
|
540
|
+
*/
|
541
|
+
'publish' : function( args, callback ) {
|
542
|
+
var callback = callback || args['callback'] || function(){}
|
543
|
+
, msg = args['message']
|
544
|
+
, channel = args['channel']
|
545
|
+
, jsonp = jsonp_cb()
|
546
|
+
, url;
|
547
|
+
|
548
|
+
if (!msg) return error('Missing Message');
|
549
|
+
if (!channel) return error('Missing Channel');
|
550
|
+
if (!PUBLISH_KEY) return error('Missing Publish Key');
|
551
|
+
if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
|
552
|
+
|
553
|
+
// If trying to send Object
|
554
|
+
msg = JSON['stringify'](msg);
|
555
|
+
|
556
|
+
// Create URL
|
557
|
+
url = [
|
558
|
+
STD_ORIGIN, 'publish',
|
559
|
+
PUBLISH_KEY, SUBSCRIBE_KEY,
|
560
|
+
0, encode(channel),
|
561
|
+
jsonp, encode(msg)
|
562
|
+
];
|
563
|
+
|
564
|
+
// Queue Message Send
|
565
|
+
PUB_QUEUE.push({
|
566
|
+
callback : jsonp,
|
567
|
+
timeout : SECOND * 5,
|
568
|
+
url : url,
|
569
|
+
data : { 'uuid' : UUID, 'auth' : AUTH_KEY },
|
570
|
+
success : function(response){callback(response);publish(1)},
|
571
|
+
fail : function(){callback([0,'Failed',msg]);publish(1)}
|
572
|
+
});
|
573
|
+
|
574
|
+
// Send Message
|
575
|
+
publish();
|
576
|
+
},
|
577
|
+
|
578
|
+
/*
|
579
|
+
PUBNUB.unsubscribe({ channel : 'my_chat' });
|
580
|
+
*/
|
581
|
+
'unsubscribe' : function(args) {
|
582
|
+
var channel = args['channel'];
|
583
|
+
|
584
|
+
TIMETOKEN = 0;
|
585
|
+
SUB_RESTORE = 1;
|
586
|
+
|
587
|
+
// Prepare Channel(s)
|
588
|
+
channel = map( (
|
589
|
+
channel.join ? channel.join(',') : ''+channel
|
590
|
+
).split(','), function(channel) {
|
591
|
+
return channel + ',' + channel + PRESENCE_SUFFIX;
|
592
|
+
} ).join(',');
|
593
|
+
|
594
|
+
// Iterate over Channels
|
595
|
+
each( channel.split(','), function(channel) {
|
596
|
+
if (READY) SELF['LEAVE']( channel, 0 );
|
597
|
+
CHANNELS[channel] = 0;
|
598
|
+
} );
|
599
|
+
|
600
|
+
// Reset Connection if Count Less
|
601
|
+
//if (each_channel() < 2)
|
602
|
+
CONNECT();
|
603
|
+
},
|
604
|
+
|
605
|
+
/*
|
606
|
+
PUBNUB.subscribe({
|
607
|
+
channel : 'my_chat'
|
608
|
+
callback : function(message) { }
|
609
|
+
});
|
610
|
+
*/
|
611
|
+
'subscribe' : function( args, callback ) {
|
612
|
+
var channel = args['channel']
|
613
|
+
, callback = callback || args['callback']
|
614
|
+
, callback = callback || args['message']
|
615
|
+
, connect = args['connect'] || function(){}
|
616
|
+
, reconnect = args['reconnect'] || function(){}
|
617
|
+
, disconnect = args['disconnect'] || function(){}
|
618
|
+
, errcb = args['error'] || function(){}
|
619
|
+
, presence = args['presence'] || 0
|
620
|
+
, noheresync = args['noheresync'] || 0
|
621
|
+
, backfill = args['backfill'] || 0
|
622
|
+
, timetoken = args['timetoken'] || 0
|
623
|
+
, sub_timeout = args['timeout'] || SUB_TIMEOUT
|
624
|
+
, windowing = args['windowing'] || SUB_WINDOWING
|
625
|
+
, restore = args['restore'];
|
626
|
+
|
627
|
+
// Restore Enabled?
|
628
|
+
SUB_RESTORE = restore;
|
629
|
+
|
630
|
+
// Always Reset the TT
|
631
|
+
TIMETOKEN = timetoken;
|
632
|
+
|
633
|
+
// Make sure we have a Channel
|
634
|
+
if (!channel) return error('Missing Channel');
|
635
|
+
if (!callback) return error('Missing Callback');
|
636
|
+
if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
|
637
|
+
|
638
|
+
// Setup Channel(s)
|
639
|
+
each( (channel.join ? channel.join(',') : ''+channel).split(','),
|
640
|
+
function(channel) {
|
641
|
+
var settings = CHANNELS[channel] || {};
|
642
|
+
|
643
|
+
// Store Channel State
|
644
|
+
CHANNELS[SUB_CHANNEL = channel] = {
|
645
|
+
name : channel,
|
646
|
+
connected : settings.connected,
|
647
|
+
disconnected : settings.disconnected,
|
648
|
+
subscribed : 1,
|
649
|
+
callback : SUB_CALLBACK = callback,
|
650
|
+
connect : connect,
|
651
|
+
disconnect : disconnect,
|
652
|
+
reconnect : reconnect
|
653
|
+
};
|
654
|
+
|
655
|
+
// Presence Enabled?
|
656
|
+
if (!presence) return;
|
657
|
+
|
658
|
+
// Subscribe Presence Channel
|
659
|
+
SELF['subscribe']({
|
660
|
+
'channel' : channel + PRESENCE_SUFFIX,
|
661
|
+
'callback' : presence
|
662
|
+
});
|
663
|
+
|
664
|
+
// Presence Subscribed?
|
665
|
+
if (settings.subscribed) return;
|
666
|
+
|
667
|
+
// See Who's Here Now?
|
668
|
+
if (noheresync) return;
|
669
|
+
SELF['here_now']({
|
670
|
+
'channel' : channel,
|
671
|
+
'callback' : function(here) {
|
672
|
+
each( 'uuids' in here ? here['uuids'] : [],
|
673
|
+
function(uid) { presence( {
|
674
|
+
'action' : 'join',
|
675
|
+
'uuid' : uid,
|
676
|
+
'timestamp' : rnow(),
|
677
|
+
'occupancy' : here['occupancy'] || 1
|
678
|
+
}, here, channel ); } );
|
679
|
+
}
|
680
|
+
});
|
681
|
+
} );
|
682
|
+
|
683
|
+
// Test Network Connection
|
684
|
+
function _test_connection(success) {
|
685
|
+
if (success) {
|
686
|
+
// Begin Next Socket Connection
|
687
|
+
timeout( CONNECT, SECOND );
|
688
|
+
}
|
689
|
+
else {
|
690
|
+
// New Origin on Failed Connection
|
691
|
+
STD_ORIGIN = nextorigin( ORIGIN, 1 );
|
692
|
+
SUB_ORIGIN = nextorigin( ORIGIN, 1 );
|
693
|
+
|
694
|
+
// Re-test Connection
|
695
|
+
timeout( function() {
|
696
|
+
SELF['time'](_test_connection);
|
697
|
+
}, SECOND );
|
698
|
+
}
|
699
|
+
|
700
|
+
// Disconnect & Reconnect
|
701
|
+
each_channel(function(channel){
|
702
|
+
// Reconnect
|
703
|
+
if (success && channel.disconnected) {
|
704
|
+
channel.disconnected = 0;
|
705
|
+
return channel.reconnect(channel.name);
|
706
|
+
}
|
707
|
+
|
708
|
+
// Disconnect
|
709
|
+
if (!success && !channel.disconnected) {
|
710
|
+
channel.disconnected = 1;
|
711
|
+
channel.disconnect(channel.name);
|
712
|
+
}
|
713
|
+
});
|
714
|
+
}
|
715
|
+
|
716
|
+
// Evented Subscribe
|
717
|
+
function _connect() {
|
718
|
+
var jsonp = jsonp_cb()
|
719
|
+
, channels = generate_channel_list(CHANNELS).join(',');
|
720
|
+
|
721
|
+
// Stop Connection
|
722
|
+
if (!channels) return;
|
723
|
+
|
724
|
+
// Connect to PubNub Subscribe Servers
|
725
|
+
_reset_offline();
|
726
|
+
SUB_RECEIVER = xdr({
|
727
|
+
timeout : sub_timeout,
|
728
|
+
callback : jsonp,
|
729
|
+
fail : function() {
|
730
|
+
SUB_RECEIVER = null;
|
731
|
+
SELF['time'](_test_connection);
|
732
|
+
},
|
733
|
+
data : { 'uuid' : UUID, 'auth' : AUTH_KEY },
|
734
|
+
url : [
|
735
|
+
SUB_ORIGIN, 'subscribe',
|
736
|
+
SUBSCRIBE_KEY, encode(channels),
|
737
|
+
jsonp, TIMETOKEN
|
738
|
+
],
|
739
|
+
success : function(messages) {
|
740
|
+
SUB_RECEIVER = null;
|
741
|
+
|
742
|
+
// Check for Errors
|
743
|
+
if (!messages || (
|
744
|
+
typeof messages == 'object' &&
|
745
|
+
'error' in messages &&
|
746
|
+
!messages['error'])
|
747
|
+
) {
|
748
|
+
errcb(messages);
|
749
|
+
return timeout( CONNECT, windowing );
|
750
|
+
}
|
751
|
+
|
752
|
+
// Restore Previous Connection Point if Needed
|
753
|
+
TIMETOKEN = !TIMETOKEN &&
|
754
|
+
SUB_RESTORE &&
|
755
|
+
db['get'](SUBSCRIBE_KEY) || messages[1];
|
756
|
+
|
757
|
+
// Connect
|
758
|
+
each_channel(function(channel){
|
759
|
+
if (channel.connected) return;
|
760
|
+
channel.connected = 1;
|
761
|
+
channel.connect(channel.name);
|
762
|
+
});
|
763
|
+
|
764
|
+
// Invoke Memory Catchup and Receive Up to 100
|
765
|
+
// Previous Messages from the Queue.
|
766
|
+
if (backfill) {
|
767
|
+
TIMETOKEN = 10000;
|
768
|
+
backfill = 0;
|
769
|
+
}
|
770
|
+
|
771
|
+
// Update Saved Timetoken
|
772
|
+
db['set']( SUBSCRIBE_KEY, messages[1] );
|
773
|
+
|
774
|
+
// Route Channel <---> Callback for Message
|
775
|
+
var next_callback = (function() {
|
776
|
+
var channels = (messages.length>2?messages[2]:map(
|
777
|
+
CHANNELS, function(chan) { return map(
|
778
|
+
Array(messages[0].length)
|
779
|
+
.join(',').split(','),
|
780
|
+
function() { return chan; }
|
781
|
+
) }).join(','));
|
782
|
+
var list = channels.split(',');
|
783
|
+
|
784
|
+
return function() {
|
785
|
+
var channel = list.shift()||SUB_CHANNEL;
|
786
|
+
return [
|
787
|
+
(CHANNELS[channel]||{})
|
788
|
+
.callback||SUB_CALLBACK,
|
789
|
+
channel.split(PRESENCE_SUFFIX)[0]
|
790
|
+
];
|
791
|
+
};
|
792
|
+
})();
|
793
|
+
|
794
|
+
each( messages[0], function(msg) {
|
795
|
+
var next = next_callback();
|
796
|
+
next[0]( msg, messages, next[1] );
|
797
|
+
} );
|
798
|
+
|
799
|
+
timeout( _connect, windowing );
|
800
|
+
}
|
801
|
+
});
|
802
|
+
}
|
803
|
+
|
804
|
+
CONNECT = function() {
|
805
|
+
_reset_offline();
|
806
|
+
timeout( _connect, windowing );
|
807
|
+
};
|
808
|
+
|
809
|
+
// Reduce Status Flicker
|
810
|
+
if (!READY) return READY_BUFFER.push(CONNECT);
|
811
|
+
|
812
|
+
// Connect Now
|
813
|
+
CONNECT();
|
814
|
+
},
|
815
|
+
|
816
|
+
'here_now' : function( args, callback ) {
|
817
|
+
var callback = args['callback'] || callback
|
818
|
+
, err = args['error'] || function(){}
|
819
|
+
, channel = args['channel']
|
820
|
+
, jsonp = jsonp_cb()
|
821
|
+
, data = { 'uuid' : UUID, 'auth' : AUTH_KEY };
|
822
|
+
|
823
|
+
// Make sure we have a Channel
|
824
|
+
if (!channel) return error('Missing Channel');
|
825
|
+
if (!callback) return error('Missing Callback');
|
826
|
+
if (!SUBSCRIBE_KEY) return error('Missing Subscribe Key');
|
827
|
+
|
828
|
+
if (jsonp != '0') { data['callback'] = jsonp; }
|
829
|
+
|
830
|
+
xdr({
|
831
|
+
callback : jsonp,
|
832
|
+
data : data,
|
833
|
+
success : function(response) { callback(response,channel) },
|
834
|
+
fail : err,
|
835
|
+
url : [
|
836
|
+
STD_ORIGIN, 'v2', 'presence',
|
837
|
+
'sub_key', SUBSCRIBE_KEY,
|
838
|
+
'channel', encode(channel)
|
839
|
+
]
|
840
|
+
});
|
841
|
+
},
|
842
|
+
|
843
|
+
// Expose PUBNUB Functions
|
844
|
+
'xdr' : xdr,
|
845
|
+
'ready' : ready,
|
846
|
+
'db' : db,
|
847
|
+
'uuid' : uuid,
|
848
|
+
'map' : map,
|
849
|
+
'each' : each,
|
850
|
+
'each-channel' : each_channel,
|
851
|
+
'grep' : grep,
|
852
|
+
'offline' : function(){_reset_offline(1)},
|
853
|
+
'supplant' : supplant,
|
854
|
+
'now' : rnow,
|
855
|
+
'unique' : unique,
|
856
|
+
'updater' : updater
|
857
|
+
};
|
858
|
+
|
859
|
+
function _poll_online() {
|
860
|
+
_is_online() || _reset_offline(1);
|
861
|
+
timeout( _poll_online, SECOND );
|
862
|
+
}
|
863
|
+
|
864
|
+
function _poll_online2() {
|
865
|
+
SELF['time'](function(success){
|
866
|
+
success || _reset_offline(1);
|
867
|
+
timeout( _poll_online2, KEEPALIVE );
|
868
|
+
})
|
869
|
+
}
|
870
|
+
|
871
|
+
function _reset_offline(err) {
|
872
|
+
SUB_RECEIVER && SUB_RECEIVER(err);
|
873
|
+
SUB_RECEIVER = null;
|
874
|
+
}
|
875
|
+
|
876
|
+
if (!UUID) UUID = SELF['uuid']();
|
877
|
+
db['set']( SUBSCRIBE_KEY + 'uuid', UUID );
|
878
|
+
|
879
|
+
timeout( _poll_online, SECOND );
|
880
|
+
timeout( _poll_online2, KEEPALIVE );
|
881
|
+
|
882
|
+
SELF['time'](function() {});
|
883
|
+
|
884
|
+
return SELF;
|
885
|
+
}
|
886
|
+
/* =-====================================================================-= */
|
887
|
+
/* =-====================================================================-= */
|
888
|
+
/* =-========================= UTIL =============================-= */
|
889
|
+
/* =-====================================================================-= */
|
890
|
+
/* =-====================================================================-= */
|
891
|
+
|
892
|
+
window['PUBNUB'] || (function() {
|
893
|
+
|
894
|
+
/**
|
895
|
+
* UTIL LOCALS
|
896
|
+
*/
|
897
|
+
|
898
|
+
var SWF = 'https://pubnub.a.ssl.fastly.net/pubnub.swf'
|
899
|
+
, ASYNC = 'async'
|
900
|
+
, UA = navigator.userAgent
|
901
|
+
, PNSDK = 'PubNub-JS-' + 'Web' + '/' + '3.5.3.1'
|
902
|
+
, XORIGN = UA.indexOf('MSIE 6') == -1;
|
903
|
+
|
904
|
+
/**
|
905
|
+
* CONSOLE COMPATIBILITY
|
906
|
+
*/
|
907
|
+
window.console || (window.console=window.console||{});
|
908
|
+
console.log || (
|
909
|
+
console.log =
|
910
|
+
console.error =
|
911
|
+
((window.opera||{}).postError||function(){})
|
912
|
+
);
|
913
|
+
|
914
|
+
/**
|
915
|
+
* LOCAL STORAGE OR COOKIE
|
916
|
+
*/
|
917
|
+
var db = (function(){
|
918
|
+
var ls = window['localStorage'];
|
919
|
+
return {
|
920
|
+
'get' : function(key) {
|
921
|
+
try {
|
922
|
+
if (ls) return ls.getItem(key);
|
923
|
+
if (document.cookie.indexOf(key) == -1) return null;
|
924
|
+
return ((document.cookie||'').match(
|
925
|
+
RegExp(key+'=([^;]+)')
|
926
|
+
)||[])[1] || null;
|
927
|
+
} catch(e) { return }
|
928
|
+
},
|
929
|
+
'set' : function( key, value ) {
|
930
|
+
try {
|
931
|
+
if (ls) return ls.setItem( key, value ) && 0;
|
932
|
+
document.cookie = key + '=' + value +
|
933
|
+
'; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/';
|
934
|
+
} catch(e) { return }
|
935
|
+
}
|
936
|
+
};
|
937
|
+
})();
|
938
|
+
|
939
|
+
|
940
|
+
/**
|
941
|
+
* $
|
942
|
+
* =
|
943
|
+
* var div = $('divid');
|
944
|
+
*/
|
945
|
+
function $(id) { return document.getElementById(id) }
|
946
|
+
|
947
|
+
/**
|
948
|
+
* ERROR
|
949
|
+
* =====
|
950
|
+
* error('message');
|
951
|
+
*/
|
952
|
+
function error(message) { console['error'](message) }
|
953
|
+
|
954
|
+
/**
|
955
|
+
* SEARCH
|
956
|
+
* ======
|
957
|
+
* var elements = search('a div span');
|
958
|
+
*/
|
959
|
+
function search( elements, start ) {
|
960
|
+
var list = [];
|
961
|
+
each( elements.split(/\s+/), function(el) {
|
962
|
+
each( (start || document).getElementsByTagName(el), function(node) {
|
963
|
+
list.push(node);
|
964
|
+
} );
|
965
|
+
} );
|
966
|
+
return list;
|
967
|
+
}
|
968
|
+
|
969
|
+
/**
|
970
|
+
* BIND
|
971
|
+
* ====
|
972
|
+
* bind( 'keydown', search('a')[0], function(element) {
|
973
|
+
* ...
|
974
|
+
* } );
|
975
|
+
*/
|
976
|
+
function bind( type, el, fun ) {
|
977
|
+
each( type.split(','), function(etype) {
|
978
|
+
var rapfun = function(e) {
|
979
|
+
if (!e) e = window.event;
|
980
|
+
if (!fun(e)) {
|
981
|
+
e.cancelBubble = true;
|
982
|
+
e.returnValue = false;
|
983
|
+
e.preventDefault && e.preventDefault();
|
984
|
+
e.stopPropagation && e.stopPropagation();
|
985
|
+
}
|
986
|
+
};
|
987
|
+
|
988
|
+
if ( el.addEventListener ) el.addEventListener( etype, rapfun, false );
|
989
|
+
else if ( el.attachEvent ) el.attachEvent( 'on' + etype, rapfun );
|
990
|
+
else el[ 'on' + etype ] = rapfun;
|
991
|
+
} );
|
992
|
+
}
|
993
|
+
|
994
|
+
/**
|
995
|
+
* UNBIND
|
996
|
+
* ======
|
997
|
+
* unbind( 'keydown', search('a')[0] );
|
998
|
+
*/
|
999
|
+
function unbind( type, el, fun ) {
|
1000
|
+
if ( el.removeEventListener ) el.removeEventListener( type, false );
|
1001
|
+
else if ( el.detachEvent ) el.detachEvent( 'on' + type, false );
|
1002
|
+
else el[ 'on' + type ] = null;
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
/**
|
1006
|
+
* HEAD
|
1007
|
+
* ====
|
1008
|
+
* head().appendChild(elm);
|
1009
|
+
*/
|
1010
|
+
function head() { return search('head')[0] }
|
1011
|
+
|
1012
|
+
/**
|
1013
|
+
* ATTR
|
1014
|
+
* ====
|
1015
|
+
* var attribute = attr( node, 'attribute' );
|
1016
|
+
*/
|
1017
|
+
function attr( node, attribute, value ) {
|
1018
|
+
if (value) node.setAttribute( attribute, value );
|
1019
|
+
else return node && node.getAttribute && node.getAttribute(attribute);
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
/**
|
1023
|
+
* CSS
|
1024
|
+
* ===
|
1025
|
+
* var obj = create('div');
|
1026
|
+
*/
|
1027
|
+
function css( element, styles ) {
|
1028
|
+
for (var style in styles) if (styles.hasOwnProperty(style))
|
1029
|
+
try {element.style[style] = styles[style] + (
|
1030
|
+
'|width|height|top|left|'.indexOf(style) > 0 &&
|
1031
|
+
typeof styles[style] == 'number'
|
1032
|
+
? 'px' : ''
|
1033
|
+
)}catch(e){}
|
1034
|
+
}
|
1035
|
+
|
1036
|
+
/**
|
1037
|
+
* CREATE
|
1038
|
+
* ======
|
1039
|
+
* var obj = create('div');
|
1040
|
+
*/
|
1041
|
+
function create(element) { return document.createElement(element) }
|
1042
|
+
|
1043
|
+
|
1044
|
+
/**
|
1045
|
+
* jsonp_cb
|
1046
|
+
* ========
|
1047
|
+
* var callback = jsonp_cb();
|
1048
|
+
*/
|
1049
|
+
function jsonp_cb() { return XORIGN || FDomainRequest() ? 0 : unique() }
|
1050
|
+
|
1051
|
+
|
1052
|
+
|
1053
|
+
/**
|
1054
|
+
* EVENTS
|
1055
|
+
* ======
|
1056
|
+
* PUBNUB.events.bind( 'you-stepped-on-flower', function(message) {
|
1057
|
+
* // Do Stuff with message
|
1058
|
+
* } );
|
1059
|
+
*
|
1060
|
+
* PUBNUB.events.fire( 'you-stepped-on-flower', "message-data" );
|
1061
|
+
* PUBNUB.events.fire( 'you-stepped-on-flower', {message:"data"} );
|
1062
|
+
* PUBNUB.events.fire( 'you-stepped-on-flower', [1,2,3] );
|
1063
|
+
*
|
1064
|
+
*/
|
1065
|
+
var events = {
|
1066
|
+
'list' : {},
|
1067
|
+
'unbind' : function( name ) { events.list[name] = [] },
|
1068
|
+
'bind' : function( name, fun ) {
|
1069
|
+
(events.list[name] = events.list[name] || []).push(fun);
|
1070
|
+
},
|
1071
|
+
'fire' : function( name, data ) {
|
1072
|
+
each(
|
1073
|
+
events.list[name] || [],
|
1074
|
+
function(fun) { fun(data) }
|
1075
|
+
);
|
1076
|
+
}
|
1077
|
+
};
|
1078
|
+
|
1079
|
+
/**
|
1080
|
+
* XDR Cross Domain Request
|
1081
|
+
* ========================
|
1082
|
+
* xdr({
|
1083
|
+
* url : ['http://www.blah.com/url'],
|
1084
|
+
* success : function(response) {},
|
1085
|
+
* fail : function() {}
|
1086
|
+
* });
|
1087
|
+
*/
|
1088
|
+
function xdr( setup ) {
|
1089
|
+
if (XORIGN || FDomainRequest()) return ajax(setup);
|
1090
|
+
|
1091
|
+
var script = create('script')
|
1092
|
+
, callback = setup.callback
|
1093
|
+
, id = unique()
|
1094
|
+
, finished = 0
|
1095
|
+
, xhrtme = setup.timeout || DEF_TIMEOUT
|
1096
|
+
, timer = timeout( function(){done(1)}, xhrtme )
|
1097
|
+
, fail = setup.fail || function(){}
|
1098
|
+
, data = setup.data || {}
|
1099
|
+
, success = setup.success || function(){}
|
1100
|
+
, append = function() { head().appendChild(script) }
|
1101
|
+
, done = function( failed, response ) {
|
1102
|
+
if (finished) return;
|
1103
|
+
finished = 1;
|
1104
|
+
|
1105
|
+
script.onerror = null;
|
1106
|
+
clearTimeout(timer);
|
1107
|
+
|
1108
|
+
(failed || !response) || success(response);
|
1109
|
+
|
1110
|
+
timeout( function() {
|
1111
|
+
failed && fail();
|
1112
|
+
var s = $(id)
|
1113
|
+
, p = s && s.parentNode;
|
1114
|
+
p && p.removeChild(s);
|
1115
|
+
}, SECOND );
|
1116
|
+
};
|
1117
|
+
|
1118
|
+
window[callback] = function(response) {
|
1119
|
+
done( 0, response );
|
1120
|
+
};
|
1121
|
+
|
1122
|
+
if (!setup.blocking) script[ASYNC] = ASYNC;
|
1123
|
+
|
1124
|
+
script.onerror = function() { done(1) };
|
1125
|
+
data['pnsdk'] = PNSDK;
|
1126
|
+
script.src = build_url( setup.url, data );
|
1127
|
+
|
1128
|
+
attr( script, 'id', id );
|
1129
|
+
|
1130
|
+
append();
|
1131
|
+
return done;
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
/**
|
1135
|
+
* CORS XHR Request
|
1136
|
+
* ================
|
1137
|
+
* xdr({
|
1138
|
+
* url : ['http://www.blah.com/url'],
|
1139
|
+
* success : function(response) {},
|
1140
|
+
* fail : function() {}
|
1141
|
+
* });
|
1142
|
+
*/
|
1143
|
+
function ajax( setup ) {
|
1144
|
+
var xhr, response
|
1145
|
+
, finished = function() {
|
1146
|
+
if (loaded) return;
|
1147
|
+
loaded = 1;
|
1148
|
+
|
1149
|
+
clearTimeout(timer);
|
1150
|
+
|
1151
|
+
try { response = JSON['parse'](xhr.responseText); }
|
1152
|
+
catch (r) { return done(1); }
|
1153
|
+
|
1154
|
+
complete = 1;
|
1155
|
+
success(response);
|
1156
|
+
}
|
1157
|
+
, complete = 0
|
1158
|
+
, loaded = 0
|
1159
|
+
, xhrtme = setup.timeout || DEF_TIMEOUT
|
1160
|
+
, timer = timeout( function(){done(1)}, xhrtme )
|
1161
|
+
, fail = setup.fail || function(){}
|
1162
|
+
, data = setup.data || {}
|
1163
|
+
, success = setup.success || function(){}
|
1164
|
+
, async = ( typeof(setup.blocking) === 'undefined' )
|
1165
|
+
, done = function(failed) {
|
1166
|
+
if (complete) return;
|
1167
|
+
complete = 1;
|
1168
|
+
|
1169
|
+
clearTimeout(timer);
|
1170
|
+
|
1171
|
+
if (xhr) {
|
1172
|
+
xhr.onerror = xhr.onload = null;
|
1173
|
+
xhr.abort && xhr.abort();
|
1174
|
+
xhr = null;
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
failed && fail();
|
1178
|
+
};
|
1179
|
+
|
1180
|
+
// Send
|
1181
|
+
try {
|
1182
|
+
xhr = FDomainRequest() ||
|
1183
|
+
window.XDomainRequest &&
|
1184
|
+
new XDomainRequest() ||
|
1185
|
+
new XMLHttpRequest();
|
1186
|
+
|
1187
|
+
xhr.onerror = xhr.onabort = function(){ done(1) };
|
1188
|
+
xhr.onload = xhr.onloadend = finished;
|
1189
|
+
if (async) xhr.timeout = xhrtme;
|
1190
|
+
|
1191
|
+
data['pnsdk'] = PNSDK;
|
1192
|
+
var url = build_url(setup.url,data);
|
1193
|
+
|
1194
|
+
xhr.open( 'GET', url, async );
|
1195
|
+
xhr.send();
|
1196
|
+
}
|
1197
|
+
catch(eee) {
|
1198
|
+
done(0);
|
1199
|
+
XORIGN = 0;
|
1200
|
+
return xdr(setup);
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
// Return 'done'
|
1204
|
+
return done;
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
|
1208
|
+
|
1209
|
+
// Test Connection State
|
1210
|
+
function _is_online() {
|
1211
|
+
if (!('onLine' in navigator)) return 1;
|
1212
|
+
return navigator['onLine'];
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
|
1216
|
+
/* =-====================================================================-= */
|
1217
|
+
/* =-====================================================================-= */
|
1218
|
+
/* =-========================= PUBNUB ===========================-= */
|
1219
|
+
/* =-====================================================================-= */
|
1220
|
+
/* =-====================================================================-= */
|
1221
|
+
|
1222
|
+
var PDIV = $('pubnub') || 0
|
1223
|
+
, CREATE_PUBNUB = function(setup) {
|
1224
|
+
|
1225
|
+
// Force JSONP if requested from user.
|
1226
|
+
if (setup['jsonp']) XORIGN = 0;
|
1227
|
+
|
1228
|
+
var SUBSCRIBE_KEY = setup['subscribe_key'] || ''
|
1229
|
+
, KEEPALIVE = (+setup['keepalive'] || DEF_KEEPALIVE) * SECOND
|
1230
|
+
, UUID = setup['uuid'] || db['get'](SUBSCRIBE_KEY+'uuid')||'';
|
1231
|
+
|
1232
|
+
setup['xdr'] = xdr;
|
1233
|
+
setup['db'] = db;
|
1234
|
+
setup['error'] = error;
|
1235
|
+
setup['_is_online'] = _is_online;
|
1236
|
+
setup['jsonp_cb'] = jsonp_cb;
|
1237
|
+
|
1238
|
+
var SELF = PN_API(setup);
|
1239
|
+
SELF['css'] = css;
|
1240
|
+
SELF['$'] = $;
|
1241
|
+
SELF['create'] = create;
|
1242
|
+
SELF['bind'] = bind;
|
1243
|
+
SELF['head'] = head;
|
1244
|
+
SELF['search'] = search;
|
1245
|
+
SELF['attr'] = attr;
|
1246
|
+
SELF['events'] = events;
|
1247
|
+
SELF['init'] = CREATE_PUBNUB;
|
1248
|
+
|
1249
|
+
|
1250
|
+
// Add Leave Functions
|
1251
|
+
bind( 'beforeunload', window, function() {
|
1252
|
+
SELF['each-channel'](function(ch){ SELF['LEAVE']( ch.name, 0 ) });
|
1253
|
+
return true;
|
1254
|
+
} );
|
1255
|
+
|
1256
|
+
// Return without Testing
|
1257
|
+
if (setup['notest']) return SELF;
|
1258
|
+
|
1259
|
+
bind( 'offline', window, SELF['offline'] );
|
1260
|
+
bind( 'offline', document, SELF['offline'] );
|
1261
|
+
|
1262
|
+
// Return PUBNUB Socket Object
|
1263
|
+
return SELF;
|
1264
|
+
};
|
1265
|
+
|
1266
|
+
// Bind for PUBNUB Readiness to Subscribe
|
1267
|
+
bind( 'load', window, function(){ timeout( ready, 0 ) } );
|
1268
|
+
|
1269
|
+
var pdiv = PDIV || {};
|
1270
|
+
|
1271
|
+
// CREATE A PUBNUB GLOBAL OBJECT
|
1272
|
+
PUBNUB = CREATE_PUBNUB({
|
1273
|
+
'notest' : 1,
|
1274
|
+
'publish_key' : attr( pdiv, 'pub-key' ),
|
1275
|
+
'subscribe_key' : attr( pdiv, 'sub-key' ),
|
1276
|
+
'ssl' : !document.location.href.indexOf('https') ||
|
1277
|
+
attr( pdiv, 'ssl' ) == 'on',
|
1278
|
+
'origin' : attr( pdiv, 'origin' ),
|
1279
|
+
'uuid' : attr( pdiv, 'uuid' )
|
1280
|
+
});
|
1281
|
+
|
1282
|
+
// jQuery Interface
|
1283
|
+
window['jQuery'] && (window['jQuery']['PUBNUB'] = PUBNUB);
|
1284
|
+
|
1285
|
+
// For Modern JS + Testling.js - http://testling.com/
|
1286
|
+
typeof(module) !== 'undefined' && (module['exports'] = PUBNUB) && ready();
|
1287
|
+
|
1288
|
+
var pubnubs = $('pubnubs') || 0;
|
1289
|
+
|
1290
|
+
// LEAVE NOW IF NO PDIV.
|
1291
|
+
if (!PDIV) return;
|
1292
|
+
|
1293
|
+
// PUBNUB Flash Socket
|
1294
|
+
css( PDIV, { 'position' : 'absolute', 'top' : -SECOND } );
|
1295
|
+
|
1296
|
+
if ('opera' in window || attr( PDIV, 'flash' )) PDIV['innerHTML'] =
|
1297
|
+
'<object id=pubnubs data=' + SWF +
|
1298
|
+
'><param name=movie value=' + SWF +
|
1299
|
+
'><param name=allowscriptaccess value=always></object>';
|
1300
|
+
|
1301
|
+
// Create Interface for Opera Flash
|
1302
|
+
PUBNUB['rdx'] = function( id, data ) {
|
1303
|
+
if (!data) return FDomainRequest[id]['onerror']();
|
1304
|
+
FDomainRequest[id]['responseText'] = unescape(data);
|
1305
|
+
FDomainRequest[id]['onload']();
|
1306
|
+
};
|
1307
|
+
|
1308
|
+
function FDomainRequest() {
|
1309
|
+
if (!pubnubs || !pubnubs['get']) return 0;
|
1310
|
+
|
1311
|
+
var fdomainrequest = {
|
1312
|
+
'id' : FDomainRequest['id']++,
|
1313
|
+
'send' : function() {},
|
1314
|
+
'abort' : function() { fdomainrequest['id'] = {} },
|
1315
|
+
'open' : function( method, url ) {
|
1316
|
+
FDomainRequest[fdomainrequest['id']] = fdomainrequest;
|
1317
|
+
pubnubs['get']( fdomainrequest['id'], url );
|
1318
|
+
}
|
1319
|
+
};
|
1320
|
+
|
1321
|
+
return fdomainrequest;
|
1322
|
+
}
|
1323
|
+
FDomainRequest['id'] = SECOND;
|
1324
|
+
|
1325
|
+
})();
|
1326
|
+
(function(){
|
1327
|
+
|
1328
|
+
// ---------------------------------------------------------------------------
|
1329
|
+
// WEBSOCKET INTERFACE
|
1330
|
+
// ---------------------------------------------------------------------------
|
1331
|
+
var WS = PUBNUB['ws'] = function( url, protocols ) {
|
1332
|
+
if (!(this instanceof WS)) return new WS( url, protocols );
|
1333
|
+
|
1334
|
+
var self = this
|
1335
|
+
, url = self.url = url || ''
|
1336
|
+
, protocol = self.protocol = protocols || 'Sec-WebSocket-Protocol'
|
1337
|
+
, bits = url.split('/')
|
1338
|
+
, setup = {
|
1339
|
+
'ssl' : bits[0] === 'wss:'
|
1340
|
+
,'origin' : bits[2]
|
1341
|
+
,'publish_key' : bits[3]
|
1342
|
+
,'subscribe_key' : bits[4]
|
1343
|
+
,'channel' : bits[5]
|
1344
|
+
};
|
1345
|
+
|
1346
|
+
// READY STATES
|
1347
|
+
self['CONNECTING'] = 0; // The connection is not yet open.
|
1348
|
+
self['OPEN'] = 1; // The connection is open and ready to communicate.
|
1349
|
+
self['CLOSING'] = 2; // The connection is in the process of closing.
|
1350
|
+
self['CLOSED'] = 3; // The connection is closed or couldn't be opened.
|
1351
|
+
|
1352
|
+
// CLOSE STATES
|
1353
|
+
self['CLOSE_NORMAL'] = 1000; // Normal Intended Close; completed.
|
1354
|
+
self['CLOSE_GOING_AWAY'] = 1001; // Closed Unexpecttedly.
|
1355
|
+
self['CLOSE_PROTOCOL_ERROR'] = 1002; // Server: Not Supported.
|
1356
|
+
self['CLOSE_UNSUPPORTED'] = 1003; // Server: Unsupported Protocol.
|
1357
|
+
self['CLOSE_TOO_LARGE'] = 1004; // Server: Too Much Data.
|
1358
|
+
self['CLOSE_NO_STATUS'] = 1005; // Server: No reason.
|
1359
|
+
self['CLOSE_ABNORMAL'] = 1006; // Abnormal Disconnect.
|
1360
|
+
|
1361
|
+
// Events Default
|
1362
|
+
self['onclose'] = self['onerror'] =
|
1363
|
+
self['onmessage'] = self['onopen'] =
|
1364
|
+
self['onsend'] = function(){};
|
1365
|
+
|
1366
|
+
// Attributes
|
1367
|
+
self['binaryType'] = '';
|
1368
|
+
self['extensions'] = '';
|
1369
|
+
self['bufferedAmount'] = 0;
|
1370
|
+
self['trasnmitting'] = false;
|
1371
|
+
self['buffer'] = [];
|
1372
|
+
self['readyState'] = self['CONNECTING'];
|
1373
|
+
|
1374
|
+
// Close if no setup.
|
1375
|
+
if (!url) {
|
1376
|
+
self['readyState'] = self['CLOSED'];
|
1377
|
+
self['onclose']({
|
1378
|
+
'code' : self['CLOSE_ABNORMAL'],
|
1379
|
+
'reason' : 'Missing URL',
|
1380
|
+
'wasClean' : true
|
1381
|
+
});
|
1382
|
+
return self;
|
1383
|
+
}
|
1384
|
+
|
1385
|
+
// PubNub WebSocket Emulation
|
1386
|
+
self.pubnub = PUBNUB['init'](setup);
|
1387
|
+
self.pubnub.setup = setup;
|
1388
|
+
self.setup = setup;
|
1389
|
+
|
1390
|
+
self.pubnub['subscribe']({
|
1391
|
+
'restore' : false,
|
1392
|
+
'channel' : setup['channel'],
|
1393
|
+
'disconnect' : self['onerror'],
|
1394
|
+
'reconnect' : self['onopen'],
|
1395
|
+
'error' : function() {
|
1396
|
+
self['onclose']({
|
1397
|
+
'code' : self['CLOSE_ABNORMAL'],
|
1398
|
+
'reason' : 'Missing URL',
|
1399
|
+
'wasClean' : false
|
1400
|
+
});
|
1401
|
+
},
|
1402
|
+
'callback' : function(message) {
|
1403
|
+
self['onmessage']({ 'data' : message });
|
1404
|
+
},
|
1405
|
+
'connect' : function() {
|
1406
|
+
self['readyState'] = self['OPEN'];
|
1407
|
+
self['onopen']();
|
1408
|
+
}
|
1409
|
+
});
|
1410
|
+
};
|
1411
|
+
|
1412
|
+
// ---------------------------------------------------------------------------
|
1413
|
+
// WEBSOCKET SEND
|
1414
|
+
// ---------------------------------------------------------------------------
|
1415
|
+
WS.prototype.send = function(data) {
|
1416
|
+
var self = this;
|
1417
|
+
self.pubnub['publish']({
|
1418
|
+
'channel' : self.pubnub.setup['channel'],
|
1419
|
+
'message' : data,
|
1420
|
+
'callback' : function(response) {
|
1421
|
+
self['onsend']({ 'data' : response });
|
1422
|
+
}
|
1423
|
+
});
|
1424
|
+
};
|
1425
|
+
|
1426
|
+
// ---------------------------------------------------------------------------
|
1427
|
+
// WEBSOCKET CLOSE
|
1428
|
+
// ---------------------------------------------------------------------------
|
1429
|
+
WS.prototype.close = function() {
|
1430
|
+
var self = this;
|
1431
|
+
self.pubnub['unsubscribe']({ 'channel' : self.pubnub.setup['channel'] });
|
1432
|
+
self['readyState'] = self['CLOSED'];
|
1433
|
+
self['onclose']({});
|
1434
|
+
};
|
1435
|
+
|
1436
|
+
})();
|