Commit 08fac4c5ead63f002f53d9821aaf00d987caa64d

Authored by Andrew Buss

Merge branch 'master' of git.ucsd.edu:110swag/flashy-frontend

Showing 15 changed files Side-by-side Diff

cmg/README.md View file @ 08fac4c
1   -Push Messaging and Notification Sample
2   -===
3   -
4   -Learn more at http://www.chromestatus.com/feature/5416033485586432 and http://www.chromestatus.com/feature/5480344312610816
5   -
6   -To use this sample please do the following:
7   -
8   -1. Create a project in the [Google Developer Console](https://console.developers.google.com) (detailed instructions are availabl at https://developer.android.com/google/gcm/gs.html)
9   -1. Enable GCM support
10   -1. Create a copy of [config.sample.js](config.sample.js) called config.js
11   -1. Create a copy of [manifest.sample.json](manifest.sample.json) called manifest.json
12   -1. Replace `<Your Public API Key ...>` in your new `config.js` file with your own API key from the Google Developer Console project
13   -4. Replace `<Your Project Number ...>` in your new `manifest.json` with your own project number from the Google Developer Console project
14   -
15   -# Related Samples
16   - Push messaging and notifications are built on [service workers](https://github.com/GoogleChrome/samples/tree/gh-pages/service-worker).
cmg/analytics.js View file @ 08fac4c
1   -/*
2   -This is provided from the sample as well. Its suppose to be from a live link, but i copied and pasted the code over.
3   -*/
4   -
5   -(function(){var aa=encodeURIComponent,f=window,n=Math;function Pc(a,b){return a.href=b}
6   -var Qc="replace",q="data",m="match",ja="port",u="createElement",id="setAttribute",da="getTime",A="split",B="location",ra="hasOwnProperty",ma="hostname",ga="search",E="protocol",Ab="href",kd="action",G="apply",p="push",h="hash",pa="test",ha="slice",r="cookie",t="indexOf",ia="defaultValue",v="name",y="length",Ga="sendBeacon",z="prototype",la="clientWidth",jd="target",C="call",na="clientHeight",F="substring",oa="navigator",H="join",I="toLowerCase";var $c=function(a){this.w=a||[]};$c[z].set=function(a){this.w[a]=!0};$c[z].encode=function(){for(var a=[],b=0;b<this.w[y];b++)this.w[b]&&(a[n.floor(b/6)]=a[n.floor(b/6)]^1<<b%6);for(b=0;b<a[y];b++)a[b]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".charAt(a[b]||0);return a[H]("")+"~"};var vd=new $c;function J(a){vd.set(a)}var Nd=function(a,b){var c=new $c(Dd(a));c.set(b);a.set(Gd,c.w)},Td=function(a){a=Dd(a);a=new $c(a);for(var b=vd.w[ha](),c=0;c<a.w[y];c++)b[c]=b[c]||a.w[c];return(new $c(b)).encode()},Dd=function(a){a=a.get(Gd);ka(a)||(a=[]);return a};var ea=function(a){return"function"==typeof a},ka=function(a){return"[object Array]"==Object[z].toString[C](Object(a))},qa=function(a){return void 0!=a&&-1<(a.constructor+"")[t]("String")},D=function(a,b){return 0==a[t](b)},sa=function(a){return a?a[Qc](/^[\s\xa0]+|[\s\xa0]+$/g,""):""},ta=function(a){var b=M[u]("img");b.width=1;b.height=1;b.src=a;return b},ua=function(){},K=function(a){if(aa instanceof Function)return aa(a);J(28);return a},L=function(a,b,c,d){try{a.addEventListener?a.addEventListener(b,
7   -c,!!d):a.attachEvent&&a.attachEvent("on"+b,c)}catch(e){J(27)}},wa=function(a,b){if(a){var c=M[u]("script");c.type="text/javascript";c.async=!0;c.src=a;b&&(c.id=b);var d=M.getElementsByTagName("script")[0];d.parentNode.insertBefore(c,d)}},Ud=function(){return"https:"==M[B][E]},xa=function(){var a=""+M[B][ma];return 0==a[t]("www.")?a[F](4):a},ya=function(a){var b=M.referrer;if(/^https?:\/\//i[pa](b)){if(a)return b;a="//"+M[B][ma];var c=b[t](a);if(5==c||6==c)if(a=b.charAt(c+a[y]),"/"==a||"?"==a||""==
8   -a||":"==a)return;return b}},za=function(a,b){if(1==b[y]&&null!=b[0]&&"object"===typeof b[0])return b[0];for(var c={},d=n.min(a[y]+1,b[y]),e=0;e<d;e++)if("object"===typeof b[e]){for(var g in b[e])b[e][ra](g)&&(c[g]=b[e][g]);break}else e<a[y]&&(c[a[e]]=b[e]);return c};var ee=function(){this.keys=[];this.values={};this.m={}};ee[z].set=function(a,b,c){this.keys[p](a);c?this.m[":"+a]=b:this.values[":"+a]=b};ee[z].get=function(a){return this.m[ra](":"+a)?this.m[":"+a]:this.values[":"+a]};ee[z].map=function(a){for(var b=0;b<this.keys[y];b++){var c=this.keys[b],d=this.get(c);d&&a(c,d)}};var O=f,M=document,Mc=function(){for(var a=O[oa].userAgent+(M[r]?M[r]:"")+(M.referrer?M.referrer:""),b=a[y],c=O.history[y];0<c;)a+=c--^b++;return La(a)};var Aa=function(a){var b=O._gaUserPrefs;if(b&&b.ioo&&b.ioo()||a&&!0===O["ga-disable-"+a])return!0;try{var c=O.external;if(c&&c._gaUserPrefs&&"oo"==c._gaUserPrefs)return!0}catch(d){}return!1};var Ca=function(a){var b=[],c=M[r][A](";");a=new RegExp("^\\s*"+a+"=\\s*(.*?)\\s*$");for(var d=0;d<c[y];d++){var e=c[d][m](a);e&&b[p](e[1])}return b},zc=function(a,b,c,d,e,g){e=Aa(e)?!1:eb[pa](M[B][ma])||"/"==c&&vc[pa](d)?!1:!0;if(!e)return!1;b&&1200<b[y]&&(b=b[F](0,1200),J(24));c=a+"="+b+"; path="+c+"; ";g&&(c+="expires="+(new Date((new Date)[da]()+g)).toGMTString()+"; ");d&&"none"!=d&&(c+="domain="+d+";");d=M[r];M.cookie=c;if(!(d=d!=M[r]))a:{a=Ca(a);for(d=0;d<a[y];d++)if(b==a[d]){d=!0;break a}d=
9   -!1}return d},Cc=function(a){return K(a)[Qc](/\(/g,"%28")[Qc](/\)/g,"%29")},vc=/^(www\.)?google(\.com?)?(\.[a-z]{2})?$/,eb=/(^|\.)doubleclick\.net$/i;var oc=function(){return(Ba||Ud()?"https:":"http:")+"//www.google-analytics.com"},Da=function(a){this.name="len";this.message=a+"-8192"},ba=function(a,b,c){c=c||ua;if(2036>=b[y])wc(a,b,c);else if(8192>=b[y])x(a,b,c)||wd(a,b,c)||wc(a,b,c);else throw ge("len",b[y]),new Da(b[y]);},wc=function(a,b,c){var d=ta(a+"?"+b);d.onload=d.onerror=function(){d.onload=null;d.onerror=null;c()}},wd=function(a,b,c){var d=O.XMLHttpRequest;if(!d)return!1;var e=new d;if(!("withCredentials"in e))return!1;e.open("POST",
10   -a,!0);e.withCredentials=!0;e.setRequestHeader("Content-Type","text/plain");e.onreadystatechange=function(){4==e.readyState&&(c(),e=null)};e.send(b);return!0},x=function(a,b,c){if(!O[oa][Ga])return!1;2036>=b[y]&&(a+="?"+b,b="");return O[oa][Ga](a,b)?(c(),!0):!1},ge=function(a,b,c){1<=100*n.random()||Aa("?")||(a=["t=error","_e="+a,"_v=j36","sr=1"],b&&a[p]("_f="+b),c&&a[p]("_m="+K(c[F](0,100))),a[p]("aip=1"),a[p]("z="+fe()),wc(oc()+"/collect",a[H]("&"),ua))};var Ha=function(){this.t=[]};Ha[z].add=function(a){this.t[p](a)};Ha[z].D=function(a){try{for(var b=0;b<this.t[y];b++){var c=a.get(this.t[b]);c&&ea(c)&&c[C](O,a)}}catch(d){}b=a.get(Ia);b!=ua&&ea(b)&&(a.set(Ia,ua,!0),setTimeout(b,10))};function Ja(a){if(100!=a.get(Ka)&&La(P(a,Q))%1E4>=100*R(a,Ka))throw"abort";}function Ma(a){if(Aa(P(a,Na)))throw"abort";}function Oa(){var a=M[B][E];if("http:"!=a&&"https:"!=a)throw"abort";}
11   -function Pa(a){try{O[oa][Ga]?J(42):O.XMLHttpRequest&&"withCredentials"in new O.XMLHttpRequest&&J(40)}catch(b){}a.set(ld,Td(a),!0);a.set(Ac,R(a,Ac)+1);var c=[];Qa.map(function(b,e){if(e.p){var g=a.get(b);void 0!=g&&g!=e[ia]&&("boolean"==typeof g&&(g*=1),c[p](e.p+"="+K(""+g)))}});c[p]("z="+Bd());a.set(Ra,c[H]("&"),!0)}
12   -function Sa(a){var b=P(a,gd)||oc()+"/collect",c=P(a,fa);!c&&a.get(Vd)&&(c="beacon");if(c){var d=P(a,Ra),e=a.get(Ia),e=e||ua;"image"==c?wc(b,d,e):"xhr"==c&&wd(b,d,e)||"beacon"==c&&x(b,d,e)||ba(b,d,e)}else ba(b,P(a,Ra),a.get(Ia));a.set(Ia,ua,!0)}function Hc(a){var b=O.gaData;b&&(b.expId&&a.set(Nc,b.expId),b.expVar&&a.set(Oc,b.expVar))}function cd(){if(O[oa]&&"preview"==O[oa].loadPurpose)throw"abort";}function yd(a){var b=O.gaDevIds;ka(b)&&0!=b[y]&&a.set("&did",b[H](","),!0)}
13   -function vb(a){if(!a.get(Na))throw"abort";};var hd=function(){return n.round(2147483647*n.random())},Bd=function(){try{var a=new Uint32Array(1);O.crypto.getRandomValues(a);return a[0]&2147483647}catch(b){return hd()}},fe=hd;function Ta(a){var b=R(a,Ua);500<=b&&J(15);var c=P(a,Va);if("transaction"!=c&&"item"!=c){var c=R(a,Wa),d=(new Date)[da](),e=R(a,Xa);0==e&&a.set(Xa,d);e=n.round(2*(d-e)/1E3);0<e&&(c=n.min(c+e,20),a.set(Xa,d));if(0>=c)throw"abort";a.set(Wa,--c)}a.set(Ua,++b)};var Ya=function(){this.data=new ee},Qa=new ee,Za=[];Ya[z].get=function(a){var b=$a(a),c=this[q].get(a);b&&void 0==c&&(c=ea(b[ia])?b[ia]():b[ia]);return b&&b.n?b.n(this,a,c):c};var P=function(a,b){var c=a.get(b);return void 0==c?"":""+c},R=function(a,b){var c=a.get(b);return void 0==c||""===c?0:1*c};Ya[z].set=function(a,b,c){if(a)if("object"==typeof a)for(var d in a)a[ra](d)&&ab(this,d,a[d],c);else ab(this,a,b,c)};
14   -var ab=function(a,b,c,d){if(void 0!=c)switch(b){case Na:wb[pa](c)}var e=$a(b);e&&e.o?e.o(a,b,c,d):a[q].set(b,c,d)},bb=function(a,b,c,d,e){this.name=a;this.p=b;this.n=d;this.o=e;this.defaultValue=c},$a=function(a){var b=Qa.get(a);if(!b)for(var c=0;c<Za[y];c++){var d=Za[c],e=d[0].exec(a);if(e){b=d[1](e);Qa.set(b[v],b);break}}return b},yc=function(a){var b;Qa.map(function(c,d){d.p==a&&(b=d)});return b&&b[v]},S=function(a,b,c,d,e){a=new bb(a,b,c,d,e);Qa.set(a[v],a);return a[v]},cb=function(a,b){Za[p]([new RegExp("^"+
15   -a+"$"),b])},T=function(a,b,c){return S(a,b,c,void 0,db)},db=function(){};var gb=qa(f.GoogleAnalyticsObject)&&sa(f.GoogleAnalyticsObject)||"ga",Ba=!1,he=S("_br"),hb=T("apiVersion","v"),ib=T("clientVersion","_v");S("anonymizeIp","aip");var jb=S("adSenseId","a"),Va=S("hitType","t"),Ia=S("hitCallback"),Ra=S("hitPayload");S("nonInteraction","ni");S("currencyCode","cu");S("dataSource","ds");var Vd=S("useBeacon",void 0,!1),fa=S("transport");S("sessionControl","sc","");S("sessionGroup","sg");S("queueTime","qt");var Ac=S("_s","_s");S("screenName","cd");
16   -var kb=S("location","dl",""),lb=S("referrer","dr"),mb=S("page","dp","");S("hostname","dh");var nb=S("language","ul"),ob=S("encoding","de");S("title","dt",function(){return M.title||void 0});cb("contentGroup([0-9]+)",function(a){return new bb(a[0],"cg"+a[1])});var pb=S("screenColors","sd"),qb=S("screenResolution","sr"),rb=S("viewportSize","vp"),sb=S("javaEnabled","je"),tb=S("flashVersion","fl");S("campaignId","ci");S("campaignName","cn");S("campaignSource","cs");S("campaignMedium","cm");
17   -S("campaignKeyword","ck");S("campaignContent","cc");var ub=S("eventCategory","ec"),xb=S("eventAction","ea"),yb=S("eventLabel","el"),zb=S("eventValue","ev"),Bb=S("socialNetwork","sn"),Cb=S("socialAction","sa"),Db=S("socialTarget","st"),Eb=S("l1","plt"),Fb=S("l2","pdt"),Gb=S("l3","dns"),Hb=S("l4","rrt"),Ib=S("l5","srt"),Jb=S("l6","tcp"),Kb=S("l7","dit"),Lb=S("l8","clt"),Mb=S("timingCategory","utc"),Nb=S("timingVar","utv"),Ob=S("timingLabel","utl"),Pb=S("timingValue","utt");S("appName","an");
18   -S("appVersion","av","");S("appId","aid","");S("appInstallerId","aiid","");S("exDescription","exd");S("exFatal","exf");var Nc=S("expId","xid"),Oc=S("expVar","xvar"),Rc=S("_utma","_utma"),Sc=S("_utmz","_utmz"),Tc=S("_utmht","_utmht"),Ua=S("_hc",void 0,0),Xa=S("_ti",void 0,0),Wa=S("_to",void 0,20);cb("dimension([0-9]+)",function(a){return new bb(a[0],"cd"+a[1])});cb("metric([0-9]+)",function(a){return new bb(a[0],"cm"+a[1])});S("linkerParam",void 0,void 0,Bc,db);var ld=S("usage","_u"),Gd=S("_um");
19   -S("forceSSL",void 0,void 0,function(){return Ba},function(a,b,c){J(34);Ba=!!c});var ed=S("_j1","jid");cb("\\&(.*)",function(a){var b=new bb(a[0],a[1]),c=yc(a[0][F](1));c&&(b.n=function(a){return a.get(c)},b.o=function(a,b,g,ca){a.set(c,g,ca)},b.p=void 0);return b});
20   -var Qb=T("_oot"),dd=S("previewTask"),Rb=S("checkProtocolTask"),md=S("validationTask"),Sb=S("checkStorageTask"),Uc=S("historyImportTask"),Tb=S("samplerTask"),Vb=S("_rlt"),Wb=S("buildHitTask"),Xb=S("sendHitTask"),Vc=S("ceTask"),zd=S("devIdTask"),Cd=S("timingTask"),Ld=S("displayFeaturesTask"),V=T("name"),Q=T("clientId","cid"),Ad=S("userId","uid"),Na=T("trackingId","tid"),U=T("cookieName",void 0,"_ga"),W=T("cookieDomain"),Yb=T("cookiePath",void 0,"/"),Zb=T("cookieExpires",void 0,63072E3),$b=T("legacyCookieDomain"),
21   -Wc=T("legacyHistoryImport",void 0,!0),ac=T("storage",void 0,"cookie"),bc=T("allowLinker",void 0,!1),cc=T("allowAnchor",void 0,!0),Ka=T("sampleRate","sf",100),dc=T("siteSpeedSampleRate",void 0,1),ec=T("alwaysSendReferrer",void 0,!1),gd=S("transportUrl"),Md=S("_r","_r");function X(a,b,c,d){b[a]=function(){try{return d&&J(d),c[G](this,arguments)}catch(b){throw ge("exc",a,b&&b[v]),b;}}};var Od=function(a,b,c){this.V=1E4;this.fa=a;this.$=!1;this.B=b;this.ea=c||1},Ed=function(a,b){var c;if(a.fa&&a.$)return 0;a.$=!0;if(b){if(a.B&&R(b,a.B))return R(b,a.B);if(0==b.get(dc))return 0}if(0==a.V)return 0;void 0===c&&(c=Bd());return 0==c%a.V?n.floor(c/a.V)%a.ea+1:0};var ie=new Od(!0,he,7),je=function(a){if(!Ud()&&!Ba){var b=Ed(ie,a);if(b&&!(!O[oa][Ga]&&4<=b&&6>=b)){var c=(new Date).getHours(),d=[Bd(),Bd(),Bd()][H](".");a=(3==b||5==b?"https:":"http:")+"//www.google-analytics.com/collect?z=br.";a+=[b,"A",c,d][H](".");var e=1!=b%3?"https:":"http:",e=e+"//www.google-analytics.com/collect?z=br.",e=e+[b,"B",c,d][H](".");7==b&&(e=e[Qc]("//www.","//ssl."));c=function(){4<=b&&6>=b?O[oa][Ga](e,""):ta(e)};Bd()%2?(ta(a),c()):(c(),ta(a))}}};function fc(){var a,b,c;if((c=(c=O[oa])?c.plugins:null)&&c[y])for(var d=0;d<c[y]&&!b;d++){var e=c[d];-1<e[v][t]("Shockwave Flash")&&(b=e.description)}if(!b)try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"),b=a.GetVariable("$version")}catch(g){}if(!b)try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"),b="WIN 6,0,21,0",a.AllowScriptAccess="always",b=a.GetVariable("$version")}catch(ca){}if(!b)try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash"),b=a.GetVariable("$version")}catch(l){}b&&
22   -(a=b[m](/[\d]+/g))&&3<=a[y]&&(b=a[0]+"."+a[1]+" r"+a[2]);return b||void 0};var gc=function(a,b){var c=n.min(R(a,dc),100);if(!(La(P(a,Q))%100>=c)&&(c={},Ec(c)||Fc(c))){var d=c[Eb];void 0==d||Infinity==d||isNaN(d)||(0<d?(Y(c,Gb),Y(c,Jb),Y(c,Ib),Y(c,Fb),Y(c,Hb),Y(c,Kb),Y(c,Lb),b(c)):L(O,"load",function(){gc(a,b)},!1))}},Ec=function(a){var b=O.performance||O.webkitPerformance,b=b&&b.timing;if(!b)return!1;var c=b.navigationStart;if(0==c)return!1;a[Eb]=b.loadEventStart-c;a[Gb]=b.domainLookupEnd-b.domainLookupStart;a[Jb]=b.connectEnd-b.connectStart;a[Ib]=b.responseStart-b.requestStart;
23   -a[Fb]=b.responseEnd-b.responseStart;a[Hb]=b.fetchStart-c;a[Kb]=b.domInteractive-c;a[Lb]=b.domContentLoadedEventStart-c;return!0},Fc=function(a){if(O.top!=O)return!1;var b=O.external,c=b&&b.onloadT;b&&!b.isValidLoadTime&&(c=void 0);2147483648<c&&(c=void 0);0<c&&b.setPageReadyTime();if(void 0==c)return!1;a[Eb]=c;return!0},Y=function(a,b){var c=a[b];if(isNaN(c)||Infinity==c||0>c)a[b]=void 0},Fd=function(a){return function(b){"pageview"!=b.get(Va)||a.I||(a.I=!0,gc(b,function(b){a.send("timing",b)}))}};var hc=!1,mc=function(a){if("cookie"==P(a,ac)){var b=P(a,U),c=nd(a),d=kc(P(a,Yb)),e=lc(P(a,W)),g=1E3*R(a,Zb),ca=P(a,Na);if("auto"!=e)zc(b,c,d,e,ca,g)&&(hc=!0);else{J(32);var l;a:{c=[];e=xa()[A](".");if(4==e[y]&&(l=e[e[y]-1],parseInt(l,10)==l)){l=["none"];break a}for(l=e[y]-2;0<=l;l--)c[p](e[ha](l)[H]("."));c[p]("none");l=c}for(var k=0;k<l[y];k++)if(e=l[k],a[q].set(W,e),c=nd(a),zc(b,c,d,e,ca,g)){hc=!0;return}a[q].set(W,"auto")}}},nc=function(a){if("cookie"==P(a,ac)&&!hc&&(mc(a),!hc))throw"abort";},
24   -Yc=function(a){if(a.get(Wc)){var b=P(a,W),c=P(a,$b)||xa(),d=Xc("__utma",c,b);d&&(J(19),a.set(Tc,(new Date)[da](),!0),a.set(Rc,d.R),(b=Xc("__utmz",c,b))&&d[h]==b[h]&&a.set(Sc,b.R))}},nd=function(a){var b=Cc(P(a,Q)),c=ic(P(a,W));a=jc(P(a,Yb));1<a&&(c+="-"+a);return["GA1",c,b][H](".")},Gc=function(a,b,c){for(var d=[],e=[],g,ca=0;ca<a[y];ca++){var l=a[ca];if(l.r[c]==b)d[p](l);else void 0==g||l.r[c]<g?(e=[l],g=l.r[c]):l.r[c]==g&&e[p](l)}return 0<d[y]?d:e},lc=function(a){return 0==a[t](".")?a.substr(1):
25   -a},ic=function(a){return lc(a)[A](".")[y]},kc=function(a){if(!a)return"/";1<a[y]&&a.lastIndexOf("/")==a[y]-1&&(a=a.substr(0,a[y]-1));0!=a[t]("/")&&(a="/"+a);return a},jc=function(a){a=kc(a);return"/"==a?1:a[A]("/")[y]};function Xc(a,b,c){"none"==b&&(b="");var d=[],e=Ca(a);a="__utma"==a?6:2;for(var g=0;g<e[y];g++){var ca=(""+e[g])[A](".");ca[y]>=a&&d[p]({hash:ca[0],R:e[g],O:ca})}return 0==d[y]?void 0:1==d[y]?d[0]:Zc(b,d)||Zc(c,d)||Zc(null,d)||d[0]}function Zc(a,b){var c,d;null==a?c=d=1:(c=La(a),d=La(D(a,".")?a[F](1):"."+a));for(var e=0;e<b[y];e++)if(b[e][h]==c||b[e][h]==d)return b[e]};var od=new RegExp(/^https?:\/\/([^\/:]+)/),pd=/(.*)([?&#])(?:_ga=[^&#]*)(?:&?)(.*)/;function Bc(a){a=a.get(Q);var b=Ic(a,0);return"_ga=1."+K(b+"."+a)}function Ic(a,b){for(var c=new Date,d=O[oa],e=d.plugins||[],c=[a,d.userAgent,c.getTimezoneOffset(),c.getYear(),c.getDate(),c.getHours(),c.getMinutes()+b],d=0;d<e[y];++d)c[p](e[d].description);return La(c[H]("."))}var Dc=function(a){J(48);this.target=a;this.T=!1};
26   -Dc[z].Q=function(a,b){if(a.tagName){if("a"==a.tagName[I]()){a[Ab]&&Pc(a,qd(this,a[Ab],b));return}if("form"==a.tagName[I]())return rd(this,a)}if("string"==typeof a)return qd(this,a,b)};
27   -var qd=function(a,b,c){var d=pd.exec(b);d&&3<=d[y]&&(b=d[1]+(d[3]?d[2]+d[3]:""));a=a[jd].get("linkerParam");var e=b[t]("?"),d=b[t]("#");c?b+=(-1==d?"#":"&")+a:(c=-1==e?"?":"&",b=-1==d?b+(c+a):b[F](0,d)+c+a+b[F](d));return b},rd=function(a,b){if(b&&b[kd]){var c=a[jd].get("linkerParam")[A]("=")[1];if("get"==b.method[I]()){for(var d=b.childNodes||[],e=0;e<d[y];e++)if("_ga"==d[e][v]){d[e][id]("value",c);return}d=M[u]("input");d[id]("type","hidden");d[id]("name","_ga");d[id]("value",c);b.appendChild(d)}else"post"==
28   -b.method[I]()&&(b.action=qd(a,b[kd]))}};
29   -Dc[z].S=function(a,b,c){function d(c){try{c=c||O.event;var d;a:{var g=c[jd]||c.srcElement;for(c=100;g&&0<c;){if(g[Ab]&&g.nodeName[m](/^a(?:rea)?$/i)){d=g;break a}g=g.parentNode;c--}d={}}("http:"==d[E]||"https:"==d[E])&&sd(a,d[ma]||"")&&d[Ab]&&Pc(d,qd(e,d[Ab],b))}catch(w){J(26)}}var e=this;this.T||(this.T=!0,L(M,"mousedown",d,!1),L(M,"touchstart",d,!1),L(M,"keyup",d,!1));if(c){c=function(b){b=b||O.event;if((b=b[jd]||b.srcElement)&&b[kd]){var c=b[kd][m](od);c&&sd(a,c[1])&&rd(e,b)}};for(var g=0;g<M.forms[y];g++)L(M.forms[g],
30   -"submit",c)}};function sd(a,b){if(b==M[B][ma])return!1;for(var c=0;c<a[y];c++)if(a[c]instanceof RegExp){if(a[c][pa](b))return!0}else if(0<=b[t](a[c]))return!0;return!1};var Jd=function(a,b,c){this.U=ed;this.aa=b;(b=c)||(b=(b=P(a,V))&&"t0"!=b?Wd[pa](b)?"_gat_"+Cc(P(a,Na)):"_gat_"+Cc(b):"_gat");this.Y=b},Rd=function(a,b){var c=b.get(Wb);b.set(Wb,function(b){Pd(a,b);var d=c(b);Qd(a,b);return d});var d=b.get(Xb);b.set(Xb,function(b){var c=d(b);Id(a,b);return c})},Pd=function(a,b){b.get(a.U)||("1"==Ca(a.Y)[0]?b.set(a.U,"",!0):b.set(a.U,""+fe(),!0))},Qd=function(a,b){b.get(a.U)&&zc(a.Y,"1",b.get(Yb),b.get(W),b.get(Na),6E5)},Id=function(a,b){if(b.get(a.U)){var c=new ee,
31   -d=function(a){$a(a).p&&c.set($a(a).p,b.get(a))};d(hb);d(ib);d(Na);d(Q);d(a.U);c.set($a(ld).p,Td(b));var e=a.aa;c.map(function(a,b){e+=K(a)+"=";e+=K(""+b)+"&"});e+="z="+fe();ta(e);b.set(a.U,"",!0)}},Wd=/^gtm\d+$/;var fd=function(a,b){var c=a.b;if(!c.get("dcLoaded")){Nd(c,29);b=b||{};var d;b[U]&&(d=Cc(b[U]));d=new Jd(c,"https://stats.g.doubleclick.net/r/collect?t=dc&aip=1&_r=3&",d);Rd(d,c);c.set("dcLoaded",!0)}};var Sd=function(a){var b;b=a.get("dcLoaded")?!1:"cookie"!=a.get(ac)?!1:!0;b&&(Nd(a,51),b=new Jd(a),Pd(b,a),Qd(b,a),a.get(b.U)&&(a.set(Md,1,!0),a.set(gd,oc()+"/r/collect",!0)))};var Lc=function(){var a=O.gaGlobal=O.gaGlobal||{};return a.hid=a.hid||fe()};var ad,bd=function(a,b,c){if(!ad){var d;d=M[B][h];var e=O[v],g=/^#?gaso=([^&]*)/;if(e=(d=(d=d&&d[m](g)||e&&e[m](g))?d[1]:Ca("GASO")[0]||"")&&d[m](/^(?:!([-0-9a-z.]{1,40})!)?([-.\w]{10,1200})$/i))zc("GASO",""+d,c,b,a,0),f._udo||(f._udo=b),f._utcp||(f._utcp=c),a=e[1],wa("https://www.google.com/analytics/web/inpage/pub/inpage.js?"+(a?"prefix="+a+"&":"")+fe(),"_gasojs");ad=!0}};var wb=/^(UA|YT|MO|GP)-(\d+)-(\d+)$/,pc=function(a){function b(a,b){d.b[q].set(a,b)}function c(a,c){b(a,c);d.filters.add(a)}var d=this;this.b=new Ya;this.filters=new Ha;b(V,a[V]);b(Na,sa(a[Na]));b(U,a[U]);b(W,a[W]||xa());b(Yb,a[Yb]);b(Zb,a[Zb]);b($b,a[$b]);b(Wc,a[Wc]);b(bc,a[bc]);b(cc,a[cc]);b(Ka,a[Ka]);b(dc,a[dc]);b(ec,a[ec]);b(ac,a[ac]);b(Ad,a[Ad]);b(hb,1);b(ib,"j36");c(Qb,Ma);c(dd,cd);c(Rb,Oa);c(md,vb);c(Sb,nc);c(Uc,Yc);c(Tb,Ja);c(Vb,Ta);c(Vc,Hc);c(zd,yd);c(Ld,Sd);c(Wb,Pa);c(Xb,Sa);c(Cd,Fd(this));
32   -Jc(this.b,a[Q]);Kc(this.b);this.b.set(jb,Lc());bd(this.b.get(Na),this.b.get(W),this.b.get(Yb))},Jc=function(a,b){if("cookie"==P(a,ac)){hc=!1;var c;b:{var d=Ca(P(a,U));if(d&&!(1>d[y])){c=[];for(var e=0;e<d[y];e++){var g;g=d[e][A](".");var ca=g.shift();("GA1"==ca||"1"==ca)&&1<g[y]?(ca=g.shift()[A]("-"),1==ca[y]&&(ca[1]="1"),ca[0]*=1,ca[1]*=1,g={r:ca,s:g[H](".")}):g=void 0;g&&c[p](g)}if(1==c[y]){J(13);c=c[0].s;break b}if(0==c[y])J(12);else{J(14);d=ic(P(a,W));c=Gc(c,d,0);if(1==c[y]){c=c[0].s;break b}d=
33   -jc(P(a,Yb));c=Gc(c,d,1);c=c[0]&&c[0].s;break b}}c=void 0}c||(c=P(a,W),d=P(a,$b)||xa(),c=Xc("__utma",d,c),void 0!=c?(J(10),c=c.O[1]+"."+c.O[2]):c=void 0);c&&(a[q].set(Q,c),hc=!0)}c=a.get(cc);if(e=(c=M[B][c?"href":"search"][m]("(?:&|#|\\?)"+K("_ga")[Qc](/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")+"=([^&#]*)"))&&2==c[y]?c[1]:"")a.get(bc)?(c=e[t]("."),-1==c?J(22):(d=e[F](c+1),"1"!=e[F](0,c)?J(22):(c=d[t]("."),-1==c?J(22):(e=d[F](0,c),c=d[F](c+1),e!=Ic(c,0)&&e!=Ic(c,-1)&&e!=Ic(c,-2)?J(23):(J(11),a[q].set(Q,
34   -c)))))):J(21);b&&(J(9),a[q].set(Q,K(b)));a.get(Q)||((c=(c=O.gaGlobal&&O.gaGlobal.vid)&&-1!=c[ga](/^(?:utma\.)?\d+\.\d+$/)?c:void 0)?(J(17),a[q].set(Q,c)):(J(8),a[q].set(Q,[fe()^Mc()&2147483647,n.round((new Date)[da]()/1E3)][H]("."))));mc(a)},Kc=function(a){var b=O[oa],c=O.screen,d=M[B];a.set(lb,ya(a.get(ec)));if(d){var e=d.pathname||"";"/"!=e.charAt(0)&&(J(31),e="/"+e);a.set(kb,d[E]+"//"+d[ma]+e+d[ga])}c&&a.set(qb,c.width+"x"+c.height);c&&a.set(pb,c.colorDepth+"-bit");var c=M.documentElement,g=(e=
35   -M.body)&&e[la]&&e[na],ca=[];c&&c[la]&&c[na]&&("CSS1Compat"===M.compatMode||!g)?ca=[c[la],c[na]]:g&&(ca=[e[la],e[na]]);c=0>=ca[0]||0>=ca[1]?"":ca[H]("x");a.set(rb,c);a.set(tb,fc());a.set(ob,M.characterSet||M.charset);a.set(sb,b&&"function"===typeof b.javaEnabled&&b.javaEnabled()||!1);a.set(nb,(b&&(b.language||b.browserLanguage)||"")[I]());if(d&&a.get(cc)&&(b=M[B][h])){b=b[A](/[?&#]+/);d=[];for(c=0;c<b[y];++c)(D(b[c],"utm_id")||D(b[c],"utm_campaign")||D(b[c],"utm_source")||D(b[c],"utm_medium")||D(b[c],
36   -"utm_term")||D(b[c],"utm_content")||D(b[c],"gclid")||D(b[c],"dclid")||D(b[c],"gclsrc"))&&d[p](b[c]);0<d[y]&&(b="#"+d[H]("&"),a.set(kb,a.get(kb)+b))}};pc[z].get=function(a){return this.b.get(a)};pc[z].set=function(a,b){this.b.set(a,b)};var qc={pageview:[mb],event:[ub,xb,yb,zb],social:[Bb,Cb,Db],timing:[Mb,Nb,Pb,Ob]};
37   -pc[z].send=function(a){if(!(1>arguments[y])){var b,c;"string"===typeof arguments[0]?(b=arguments[0],c=[][ha][C](arguments,1)):(b=arguments[0]&&arguments[0][Va],c=arguments);b&&(c=za(qc[b]||[],c),c[Va]=b,this.b.set(c,void 0,!0),this.filters.D(this.b),this.b[q].m={},je(this.b))}};var rc=function(a){if("prerender"==M.visibilityState)return!1;a();return!0};var td=/^(?:(\w+)\.)?(?:(\w+):)?(\w+)$/,sc=function(a){if(ea(a[0]))this.u=a[0];else{var b=td.exec(a[0]);null!=b&&4==b[y]&&(this.c=b[1]||"t0",this.e=b[2]||"",this.d=b[3],this.a=[][ha][C](a,1),this.e||(this.A="create"==this.d,this.i="require"==this.d,this.g="provide"==this.d,this.ba="remove"==this.d),this.i&&(3<=this.a[y]?(this.X=this.a[1],this.W=this.a[2]):this.a[1]&&(qa(this.a[1])?this.X=this.a[1]:this.W=this.a[1])));b=a[1];a=a[2];if(!this.d)throw"abort";if(this.i&&(!qa(b)||""==b))throw"abort";if(this.g&&
38   -(!qa(b)||""==b||!ea(a)))throw"abort";if(ud(this.c)||ud(this.e))throw"abort";if(this.g&&"t0"!=this.c)throw"abort";}};function ud(a){return 0<=a[t](".")||0<=a[t](":")};var Yd,Zd,$d;Yd=new ee;$d=new ee;Zd={ec:45,ecommerce:46,linkid:47};
39   -var ae=function(a){function b(a){var b=(a[ma]||"")[A](":")[0][I](),c=(a[E]||"")[I](),c=1*a[ja]||("http:"==c?80:"https:"==c?443:"");a=a.pathname||"";D(a,"/")||(a="/"+a);return[b,""+c,a]}var c=M[u]("a");Pc(c,M[B][Ab]);var d=(c[E]||"")[I](),e=b(c),g=c[ga]||"",ca=d+"//"+e[0]+(e[1]?":"+e[1]:"");D(a,"//")?a=d+a:D(a,"/")?a=ca+a:!a||D(a,"?")?a=ca+e[2]+(a||g):0>a[A]("/")[0][t](":")&&(a=ca+e[2][F](0,e[2].lastIndexOf("/"))+"/"+a);Pc(c,a);d=b(c);return{protocol:(c[E]||"")[I](),host:d[0],port:d[1],path:d[2],G:c[ga]||
40   -"",url:a||""}};var Z={ga:function(){Z.f=[]}};Z.ga();Z.D=function(a){var b=Z.J[G](Z,arguments),b=Z.f.concat(b);for(Z.f=[];0<b[y]&&!Z.v(b[0])&&!(b.shift(),0<Z.f[y]););Z.f=Z.f.concat(b)};
41   -Z.J=function(a){for(var b=[],c=0;c<arguments[y];c++)try{var d=new sc(arguments[c]);if(d.g)Yd.set(d.a[0],d.a[1]);else{if(d.i){var e=d,g=e.a[0];if(!ea(Yd.get(g))&&!$d.get(g)){Zd[ra](g)&&J(Zd[g]);var ca=e.X;!ca&&Zd[ra](g)?(J(39),ca=g+".js"):J(43);if(ca){ca&&0<=ca[t]("/")||(ca=(Ba||Ud()?"https:":"http:")+"//www.google-analytics.com/plugins/ua/"+ca);var l=ae(ca),e=void 0;var k=l[E],w=M[B][E],e="https:"==k||k==w?!0:"http:"!=k?!1:"http:"==w;var Xd;if(Xd=e){var e=l,be=ae(M[B][Ab]);if(e.G||0<=e.url[t]("?")||
42   -0<=e.path[t]("://"))Xd=!1;else if(e.host==be.host&&e[ja]==be[ja])Xd=!0;else{var ce="http:"==e[E]?80:443;Xd="www.google-analytics.com"==e.host&&(e[ja]||ce)==ce&&D(e.path,"/plugins/")?!0:!1}}Xd&&(wa(l.url),$d.set(g,!0))}}}b[p](d)}}catch(de){}return b};
43   -Z.v=function(a){try{if(a.u)a.u[C](O,N.j("t0"));else{var b=a.c==gb?N:N.j(a.c);if(a.A)"t0"==a.c&&N.create[G](N,a.a);else if(a.ba)N.remove(a.c);else if(b)if(a.i){var c;var d=a.a[0],e=a.W;b==N||b.get(V);var g=Yd.get(d);ea(g)?(b.plugins_=b.plugins_||new ee,b.plugins_.get(d)||b.plugins_.set(d,new g(b,e||{})),c=!0):c=!1;if(!c)return!0}else if(a.e){var ca=a.d,l=a.a,k=b.plugins_.get(a.e);k[ca][G](k,l)}else b[a.d][G](b,a.a)}}catch(w){}};var N=function(a){J(1);Z.D[G](Z,[arguments])};N.h={};N.P=[];N.L=0;N.answer=42;var uc=[Na,W,V];N.create=function(a){var b=za(uc,[][ha][C](arguments));b[V]||(b[V]="t0");var c=""+b[V];if(N.h[c])return N.h[c];b=new pc(b);N.h[c]=b;N.P[p](b);return b};N.remove=function(a){for(var b=0;b<N.P[y];b++)if(N.P[b].get(V)==a){N.P.splice(b,1);N.h[a]=null;break}};N.j=function(a){return N.h[a]};N.getAll=function(){return N.P[ha](0)};
44   -N.N=function(){"ga"!=gb&&J(49);var a=O[gb];if(!a||42!=a.answer){N.L=a&&a.l;N.loaded=!0;var b=O[gb]=N;X("create",b,b.create);X("remove",b,b.remove);X("getByName",b,b.j,5);X("getAll",b,b.getAll,6);b=pc[z];X("get",b,b.get,7);X("set",b,b.set,4);X("send",b,b.send);b=Ya[z];X("get",b,b.get);X("set",b,b.set);if(!Ud()&&!Ba){a:{for(var b=M.getElementsByTagName("script"),c=0;c<b[y]&&100>c;c++){var d=b[c].src;if(d&&0==d[t]("https://www.google-analytics.com/analytics")){J(33);b=!0;break a}}b=!1}b&&(Ba=!0)}Ud()||
45   -Ba||!Ed(new Od)||(J(36),Ba=!0);(O.gaplugins=O.gaplugins||{}).Linker=Dc;b=Dc[z];Yd.set("linker",Dc);X("decorate",b,b.Q,20);X("autoLink",b,b.S,25);Yd.set("displayfeatures",fd);Yd.set("adfeatures",fd);a=a&&a.q;ka(a)?Z.D[G](N,a):J(50)}};N.k=function(){for(var a=N.getAll(),b=0;b<a[y];b++)a[b].get(V)};
46   -(function(){var a=N.N;if(!rc(a)){J(16);var b=!1,c=function(){if(!b&&rc(a)){b=!0;var d=c,e=M;e.removeEventListener?e.removeEventListener("visibilitychange",d,!1):e.detachEvent&&e.detachEvent("onvisibilitychange",d)}};L(M,"visibilitychange",c)}})();function La(a){var b=1,c=0,d;if(a)for(b=0,d=a[y]-1;0<=d;d--)c=a.charCodeAt(d),b=(b<<6&268435455)+c+(c<<14),c=b&266338304,b=0!=c?b^c>>21:b;return b};})(window);
cmg/config.js View file @ 08fac4c
1   -/*
2   -This file sets up a global variable gcmAPIKey, which contains our key.
3   -*/
4   -
5   -window.GoogleSamples = window.GoogleSamples || {};
6   -window.GoogleSamples.Config = window.GoogleSamples.Config || {
7   - gcmAPIKey: 'AIzaSyCPjkgseoVp8shXOMwFnGBeEijizpLDXOs'
8   -};
1   -/*
2   -This demo provides functionality that output debug messages.
3   -*/
4   -
5   -'use strict';
6   -
7   -function Debug() {
8   -
9   -}
10   -
11   -Debug.prototype.log = function() {
12   - var paragraphElement = document.createElement('p');
13   - paragraphElement.textContent = Array.prototype.join.call(arguments, '');
14   - document.querySelector('.js-log').appendChild(paragraphElement);
15   -}
16   -
17   -window.addEventListener('load', function() {
18   - var logDiv = document.createElement('div');
19   - logDiv.classList.add('js-log');
20   -
21   - var heading = document.createElement('h2');
22   - heading.textContent = 'Log';
23   - logDiv.appendChild(heading);
24   -
25   - document.body.appendChild(logDiv);
26   -
27   - window.Demo = window.Demo || {};
28   - window.Demo.debug = window.Demo.debug || new Debug();
29   -});
cmg/images/icon-192x192.png View file @ 08fac4c

1.63 KB

cmg/images/indexwrapper.js View file @ 08fac4c
1   -'use strict';
2   -
3   -function promisifyRequest(obj) {
4   - return new Promise(function(resolve, reject) {
5   - function onsuccess(event) {
6   - resolve(obj.result);
7   - unlisten();
8   - }
9   - function onerror(event) {
10   - reject(obj.error);
11   - unlisten();
12   - }
13   - function unlisten() {
14   - obj.removeEventListener('complete', onsuccess);
15   - obj.removeEventListener('success', onsuccess);
16   - obj.removeEventListener('error', onerror);
17   - obj.removeEventListener('abort', onerror);
18   - }
19   - obj.addEventListener('complete', onsuccess);
20   - obj.addEventListener('success', onsuccess);
21   - obj.addEventListener('error', onerror);
22   - obj.addEventListener('abort', onerror);
23   - });
24   -}
25   -
26   -function IndexDBWrapper(name, version, upgradeCallback) {
27   - var request = indexedDB.open(name, version);
28   - this.ready = promisifyRequest(request);
29   - request.onupgradeneeded = function(event) {
30   - upgradeCallback(request.result, event.oldVersion);
31   - };
32   -}
33   -
34   -IndexDBWrapper.supported = 'indexedDB' in self;
35   -
36   -var IndexDBWrapperProto = IndexDBWrapper.prototype;
37   -
38   -IndexDBWrapperProto.transaction = function(stores, modeOrCallback, callback) {
39   - return this.ready.then(function(db) {
40   - var mode = 'readonly';
41   -
42   - if (modeOrCallback.apply) {
43   - callback = modeOrCallback;
44   - }
45   - else if (modeOrCallback) {
46   - mode = modeOrCallback;
47   - }
48   -
49   - var tx = db.transaction(stores, mode);
50   - var val = callback(tx, db);
51   - var promise = promisifyRequest(tx);
52   - var readPromise;
53   -
54   - if (!val) {
55   - return promise;
56   - }
57   -
58   - if (val[0] && 'result' in val[0]) {
59   - readPromise = Promise.all(val.map(promisifyRequest));
60   - }
61   - else {
62   - readPromise = promisifyRequest(val);
63   - }
64   -
65   - return promise.then(function() {
66   - return readPromise;
67   - });
68   - });
69   -};
70   -
71   -IndexDBWrapperProto.get = function(store, key) {
72   - return this.transaction(store, function(tx) {
73   - return tx.objectStore(store).get(key);
74   - });
75   -};
76   -
77   -IndexDBWrapperProto.put = function(store, key, value) {
78   - return this.transaction(store, 'readwrite', function(tx) {
79   - tx.objectStore(store).put(value, key);
80   - });
81   -};
82   -
83   -IndexDBWrapperProto.delete = function(store, key) {
84   - return this.transaction(store, 'readwrite', function(tx) {
85   - tx.objectStore(store).delete(key);
86   - });
87   -};
cmg/images/sample-serviceworker.js View file @ 08fac4c
1   -'use strict';
2   -
3   -importScripts('/scripts/indexdbwrapper.js');
4   -
5   -var YAHOO_WEATHER_API_ENDPOINT = 'https://query.yahooapis.com/' +
6   - 'v1/public/yql?q=select%20*%20from%20weather.forecast%20where%' +
7   - '20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where' +
8   - '%20text%3D%22london%2C%20uk%22)&format=json&env=store%3A%2F%2' +
9   - 'Fdatatables.org%2Falltableswithkeys';
10   -var KEY_VALUE_STORE_NAME = 'key-value-store';
11   -
12   -var idb;
13   -
14   -// avoid opening idb until first call
15   -function getIdb() {
16   - if (!idb) {
17   - idb = new IndexDBWrapper('key-value-store', 1, function(db) {
18   - db.createObjectStore(KEY_VALUE_STORE_NAME);
19   - });
20   - }
21   - return idb;
22   -}
23   -
24   -function showNotification(title, body, icon, data) {
25   - var notificationOptions = {
26   - body: body,
27   - icon: icon ? icon : 'images/touch/chrome-touch-icon-192x192.png',
28   - tag: 'simple-push-demo-notification',
29   - data: data
30   - };
31   - if (self.registration.showNotification) {
32   - self.registration.showNotification(title, notificationOptions);
33   - return;
34   - } else {
35   - new Notification(title, notificationOptions);
36   - }
37   -}
38   -
39   -self.addEventListener('push', function(event) {
40   - console.log('Received a push message', event);
41   -
42   - // Since this is no payload data with the first version
43   - // of Push notifications, here we'll grab some data from
44   - // an API and use it to populate a notification
45   - event.waitUntil(
46   - fetch(YAHOO_WEATHER_API_ENDPOINT).then(function(response) {
47   - if (response.status !== 200) {
48   - console.log('Looks like there was a problem. Status Code: ' +
49   - response.status);
50   - // Throw an error so the promise is rejected and catch() is executed
51   - throw new Error();
52   - }
53   -
54   - // Examine the text in the response
55   - return response.json().then(function(data) {
56   - // console.log('Data = ', JSON.stringify(data));
57   - if (data.query.count === 0) {
58   - // Throw an error so the promise is rejected and catch() is executed
59   - throw new Error();
60   - }
61   -
62   - var title = 'What\'s the weather like in London?';
63   - var message = data.query.results.channel.item.condition.text;
64   - var icon = data.query.results.channel.image.url ||
65   - 'images/touch/chrome-touch-icon-192x192.png';
66   - var notificationTag = 'simple-push-demo-notification';
67   -
68   - // Add this to the data of the notification
69   - var urlToOpen = data.query.results.channel.link;
70   -
71   - if (!Notification.prototype.hasOwnProperty('data')) {
72   - // Since Chrome doesn't support data at the moment
73   - // Store the URL in IndexDB
74   - getIdb().put(KEY_VALUE_STORE_NAME, notificationTag, urlToOpen);
75   - }
76   -
77   - var notificationFilter = {
78   - tag: 'simple-push-demo-notification'
79   - };
80   -
81   - var notificationData = {
82   - url: urlToOpen
83   - };
84   -
85   - if (self.registration.getNotifications) {
86   - return self.registration.getNotifications(notificationFilter)
87   - .then(function(notifications) {
88   - if (notifications && notifications.length > 0) {
89   - // Start with one to account for the new notification
90   - // we are adding
91   - var notificationCount = 1;
92   - for (var i = 0; i < notifications.length; i++) {
93   - var existingNotification = notifications[i];
94   - if (existingNotification.data &&
95   - existingNotification.data.notoficationCount) {
96   - notificationCount += existingNotification.data.notoficationCount;
97   - } else {
98   - notificationCount++;
99   - }
100   - }
101   - message = 'You have ' + notificationCount +
102   - ' weather updates.';
103   - notificationData.notificationCount = notificationCount;
104   - }
105   -
106   - return showNotification(title, message, icon, notificationData);
107   - });
108   - } else {
109   - return showNotification(title, message, icon, notificationData);
110   - }
111   - });
112   - }).catch(function(err) {
113   - console.error('Unable to retrieve data', err);
114   -
115   - var title = 'An error occured';
116   - var message = 'We were unable to get the information for this ' +
117   - 'push message';
118   -
119   - return showNotification(title, message);
120   - })
121   - );
122   -});
123   -
124   -self.addEventListener('notificationclick', function(event) {
125   - console.log('On notification click: ', event);
126   -
127   - if (Notification.prototype.hasOwnProperty('data')) {
128   - console.log('Using Data');
129   - var url = event.notification.data.url;
130   - event.waitUntil(clients.openWindow(url));
131   - } else {
132   - event.waitUntil(getIdb().get(KEY_VALUE_STORE_NAME, event.notification.tag).then(function(url) {
133   - // At the moment you cannot open third party URL's, a simple trick
134   - // is to redirect to the desired URL from a URL on your domain
135   - var redirectUrl = '/redirect.html?redirect=' +
136   - url;
137   - return clients.openWindow(redirectUrl);
138   - }));
139   - }
140   -});
cmg/images/sampleindex.html View file @ 08fac4c
1   -<!doctype html>
2   -<html>
3   -<head>
4   - <meta charset=utf-8>
5   - <meta http-equiv=X-UA-Compatible content="IE=edge">
6   - <meta name=description content="A front-end template that helps you build fast, modern mobile web apps.">
7   - <meta name=viewport content="width=device-width, initial-scale=1">
8   - <title>Simple Push Demo</title>
9   - <link rel=manifest href=manifest.json>
10   - <meta name=mobile-web-app-capable content=yes>
11   - <meta name=application-name content="Web Starter Kit">
12   - <link rel=icon sizes=192x192 href=images/touch/chrome-touch-icon-192x192.png>
13   - <meta name=apple-mobile-web-app-capable content=yes>
14   - <meta name=apple-mobile-web-app-status-bar-style content=black>
15   - <meta name=apple-mobile-web-app-title content="Web Starter Kit">
16   - <link rel=apple-touch-icon href=images/touch/apple-touch-icon.png>
17   - <meta name=msapplication-TileImage content=images/touch/ms-touch-icon-144x144-precomposed.png>
18   - <meta name=msapplication-TileColor content=#3372DF>
19   - <meta name=theme-color content=#3372DF>
20   - <link rel=stylesheet href=styles/main.css>
21   -</head>
22   -<body>
23   -<header><h1>Push Demo</h1></header>
24   -<main>
25   - <div class=js-push-switch-container><label class="wsk-switch wsk-js-switch wsk-js-ripple-effect"
26   - for=enable-push><input type=checkbox id=enable-push
27   - class="wsk-switch__input js-enable-push" disabled>
28   - <span class=wsk-switch__label>Enable Push Notifications</span></label></div>
29   - <div class=content-overlap-wrapper>
30   - <div class="send-push-options js-send-push-options">
31   - <p class=center>
32   - <button class="xhr-button js-xhr-button wsk-button wsk-js-button wsk-button--colored wsk-js-ripple-effect">
33   - Send a Push to GCM via XHR
34   - </button>
35   - </p>
36   - <p class=center>OR</p>
37   -
38   - <p>Copy and paste the following CURL command into your terminal to send a push message to your browser.</p>
39   -
40   - <p class=center>
41   - <button class="copy-curl-button js-copy-curl-button wsk-button wsk-js-button wsk-button--colored wsk-js-ripple-effect">
42   - Copy CURL Command to Clipboard
43   - </button>
44   - </p>
45   - <code class="curl-code-example js-curl-code"></code></div>
46   - <div class="error-message-container js-error-message-container"><h1 class="error-title js-error-title"></h1>
47   -
48   - <p class="error-message js-error-message"></p></div>
49   - </div>
50   - <p class=center>The Weather API is<br><a href="https://www.yahoo.com/?ilc=401" target=_blank><img
51   - src=https://poweredby.yahoo.com/purple.png width=134 height=29></a></p></main>
52   -<script src=../../scripts/main.min.js></script>
53   -</body>
54   -</html>
cmg/images/samplejs.js View file @ 08fac4c
1   -'use strict';
2   -
3   -function promisifyRequest(obj) {
4   - return new Promise(function(resolve, reject) {
5   - function onsuccess(event) {
6   - resolve(obj.result);
7   - unlisten();
8   - }
9   - function onerror(event) {
10   - reject(obj.error);
11   - unlisten();
12   - }
13   - function unlisten() {
14   - obj.removeEventListener('complete', onsuccess);
15   - obj.removeEventListener('success', onsuccess);
16   - obj.removeEventListener('error', onerror);
17   - obj.removeEventListener('abort', onerror);
18   - }
19   - obj.addEventListener('complete', onsuccess);
20   - obj.addEventListener('success', onsuccess);
21   - obj.addEventListener('error', onerror);
22   - obj.addEventListener('abort', onerror);
23   - });
24   -}
25   -
26   -function IndexDBWrapper(name, version, upgradeCallback) {
27   - var request = indexedDB.open(name, version);
28   - this.ready = promisifyRequest(request);
29   - request.onupgradeneeded = function(event) {
30   - upgradeCallback(request.result, event.oldVersion);
31   - };
32   -}
33   -
34   -IndexDBWrapper.supported = 'indexedDB' in self;
35   -
36   -var IndexDBWrapperProto = IndexDBWrapper.prototype;
37   -
38   -IndexDBWrapperProto.transaction = function(stores, modeOrCallback, callback) {
39   - return this.ready.then(function(db) {
40   - var mode = 'readonly';
41   -
42   - if (modeOrCallback.apply) {
43   - callback = modeOrCallback;
44   - }
45   - else if (modeOrCallback) {
46   - mode = modeOrCallback;
47   - }
48   -
49   - var tx = db.transaction(stores, mode);
50   - var val = callback(tx, db);
51   - var promise = promisifyRequest(tx);
52   - var readPromise;
53   -
54   - if (!val) {
55   - return promise;
56   - }
57   -
58   - if (val[0] && 'result' in val[0]) {
59   - readPromise = Promise.all(val.map(promisifyRequest));
60   - }
61   - else {
62   - readPromise = promisifyRequest(val);
63   - }
64   -
65   - return promise.then(function() {
66   - return readPromise;
67   - });
68   - });
69   -};
70   -
71   -IndexDBWrapperProto.get = function(store, key) {
72   - return this.transaction(store, function(tx) {
73   - return tx.objectStore(store).get(key);
74   - });
75   -};
76   -
77   -IndexDBWrapperProto.put = function(store, key, value) {
78   - return this.transaction(store, 'readwrite', function(tx) {
79   - tx.objectStore(store).put(value, key);
80   - });
81   -};
82   -
83   -IndexDBWrapperProto.delete = function(store, key) {
84   - return this.transaction(store, 'readwrite', function(tx) {
85   - tx.objectStore(store).delete(key);
86   - });
87   -};
cmg/index.html View file @ 08fac4c
1   -<!doctype html>
2   -<!--
3   -This is the sample html provided.
4   -It has a button that enable push notification.
5   -If the user's browser supports serviceworker, is chrome 4.2 and above,
6   -and has not accepted the notification before, it should be enabled.
7   --->
8   -<html lang="en">
9   - <head>
10   - <meta charset="utf-8">
11   - <meta http-equiv="X-UA-Compatible" content="IE=edge">
12   -
13   - <meta name="description" content="Sample illustrating the use of Push Messaing and Notifications.">
14   -
15   - <meta name="viewport" content="width=device-width, initial-scale=1">
16   -
17   - <title>Push Messaging &amp; Notifications</title>
18   -
19   - <!-- Add to homescreen for Chrome on Android -->
20   - <!--
21   - <meta name="mobile-web-app-capable" content="yes">
22   - <link rel="icon" sizes="192x192" href="../images/touch/chrome-touch-icon-192x192.png">
23   -
24   - <!-- Add to homescreen for Safari on iOS -->
25   - <!--
26   - <meta name="apple-mobile-web-app-title" content="Push Messaging and Notifications Sample">
27   -
28   - <meta name="apple-mobile-web-app-capable" content="yes">
29   - <meta name="apple-mobile-web-app-status-bar-style" content="black">
30   - <link rel="apple-touch-icon-precomposed" href="../images/apple-touch-icon-precomposed.png">
31   -
32   - <!-- Tile icon for Win8 (144x144 + tile color) -->
33   - <!--
34   - <meta name="msapplication-TileImage" content="images/touch/ms-touch-icon-144x144-precomposed.png">
35   - <meta name="msapplication-TileColor" content="#3372DF">
36   - <!-- Include manifest file in the page -->
37   -
38   - <!-- This provides the icon when push notification appears, I think.-->
39   - <link rel="manifest" href="manifest.json">
40   -
41   - </head>
42   -
43   - <body>
44   - <h1>Push Messaging &amp; Notifications</h1>
45   -
46   - <p>Available in <a href="http://www.chromestatus.com/feature/5416033485586432">Chrome 42+</a> &amp; <a href="http://www.chromestatus.com/feature/5480344312610816">Chrome 42+</a></p>
47   -
48   - <p>To use this sample please do the following:</p>
49   -
50   - <ol>
51   - <li>Refer to <a href="https://console.developers.google.com" target="_blank">Google Developer Console</a>.</li>
52   - <li>For API reference and our key and project numbers.</li>
53   - </ol>
54   -
55   -
56   - <p>
57   - <button class="js-push-button" disabled>
58   - Enable Push Messages
59   - </button>
60   - </p>
61   -
62   - <br />
63   - <br />
64   -
65   - <h2>cURL Command to Send Push</h2>
66   - <div class="js-curl-command"></div>
67   -
68   - <script src="config.js"></script>
69   - <script src="demo.js"></script>
70   - <script src="main.js"></script>
71   - <script>
72   - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
73   - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
74   - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
75   - })(window,document,'script','analytics.js','ga');
76   - ga('create', 'UA-53563471-1', 'auto');
77   - ga('send', 'pageview');
78   - </script>
79   - <!-- Built with love using Web Starter Kit -->
80   - </body>
81   -</html>
1   -/*
2   -This page contains subscribing user's ip to our system.
3   -sendSubscriptionToServer is not implemented yet.
4   -All methods have comments from the sample.
5   -*/
6   -
7   -'use strict';
8   -
9   -var API_KEY = window.GoogleSamples.Config.gcmAPIKey;
10   -var GCM_ENDPOINT = 'https://android.googleapis.com/gcm/send';
11   -
12   -var curlCommandDiv = document.querySelector('.js-curl-command');
13   -var isPushEnabled = false;
14   -
15   -// This method handles the removal of subscriptionId
16   -// in Chrome 44 by concatenating the subscription Id
17   -// to the subscription endpoint
18   -function endpointWorkaround(pushSubscription) {
19   - // Make sure we only mess with GCM
20   - if (pushSubscription.endpoint.indexOf('https://android.googleapis.com/gcm/send') !== 0) {
21   - return pushSubscription.endpoint;
22   - }
23   -
24   - var mergedEndpoint = pushSubscription.endpoint;
25   - // Chrome 42 + 43 will not have the subscriptionId attached
26   - // to the endpoint.
27   - if (pushSubscription.subscriptionId &&
28   - pushSubscription.endpoint.indexOf(pushSubscription.subscriptionId) === -1) {
29   - // Handle version 42 where you have separate subId and Endpoint
30   - mergedEndpoint = pushSubscription.endpoint + '/' +
31   - pushSubscription.subscriptionId;
32   - }
33   - return mergedEndpoint;
34   -}
35   -
36   -function sendSubscriptionToServer(subscription) {
37   - // TODO: Send the subscription.endpoint
38   - // to your server and save it to send a
39   - // push message at a later date
40   - //
41   - // For compatibly of Chrome 43, get the endpoint via
42   - // endpointWorkaround(subscription)
43   - console.log('TODO: Implement sendSubscriptionToServer()');
44   -
45   - var mergedEndpoint = endpointWorkaround(subscription);
46   -
47   - // This is just for demo purposes / an easy to test by
48   - // generating the appropriate cURL command
49   - showCurlCommand(mergedEndpoint);
50   -}
51   -
52   -// NOTE: This code is only suitable for GCM endpoints,
53   -// When another browser has a working version, alter
54   -// this to send a PUSH request directly to the endpoint
55   -function showCurlCommand(mergedEndpoint) {
56   - // The curl command to trigger a push message straight from GCM
57   - if (mergedEndpoint.indexOf(GCM_ENDPOINT) !== 0) {
58   - window.Demo.debug.log('This browser isn\'t currently ' +
59   - 'supported for this demo');
60   - return;
61   - }
62   -
63   - var endpointSections = mergedEndpoint.split('/');
64   - var subscriptionId = endpointSections[endpointSections.length - 1];
65   -
66   - var curlCommand = 'curl --header "Authorization: key=' + API_KEY +
67   - '" --header Content-Type:"application/json" ' + GCM_ENDPOINT +
68   - ' -d "{\\"registration_ids\\":[\\"' + subscriptionId + '\\"]}"';
69   -
70   - curlCommandDiv.textContent = curlCommand;
71   -}
72   -
73   -function unsubscribe() {
74   - var pushButton = document.querySelector('.js-push-button');
75   - pushButton.disabled = true;
76   - curlCommandDiv.textContent = '';
77   -
78   - navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
79   - // To unsubscribe from push messaging, you need get the
80   - // subcription object, which you can call unsubscribe() on.
81   - serviceWorkerRegistration.pushManager.getSubscription().then(
82   - function(pushSubscription) {
83   - // Check we have a subscription to unsubscribe
84   - if (!pushSubscription) {
85   - // No subscription object, so set the state
86   - // to allow the user to subscribe to push
87   - isPushEnabled = false;
88   - pushButton.disabled = false;
89   - pushButton.textContent = 'Enable Push Messages';
90   - return;
91   - }
92   -
93   - // TODO: Make a request to your server to remove
94   - // the users data from your data store so you
95   - // don't attempt to send them push messages anymore
96   -
97   - // We have a subcription, so call unsubscribe on it
98   - pushSubscription.unsubscribe().then(function(successful) {
99   - pushButton.disabled = false;
100   - pushButton.textContent = 'Enable Push Messages';
101   - isPushEnabled = false;
102   - }).catch(function(e) {
103   - // We failed to unsubscribe, this can lead to
104   - // an unusual state, so may be best to remove
105   - // the subscription id from your data store and
106   - // inform the user that you disabled push
107   -
108   - window.Demo.debug.log('Unsubscription error: ', e);
109   - pushButton.disabled = false;
110   - });
111   - }).catch(function(e) {
112   - window.Demo.debug.log('Error thrown while unsubscribing from ' +
113   - 'push messaging.', e);
114   - });
115   - });
116   -}
117   -
118   -function subscribe() {
119   - // Disable the button so it can't be changed while
120   - // we process the permission request
121   - var pushButton = document.querySelector('.js-push-button');
122   - pushButton.disabled = true;
123   -
124   - navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
125   - serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly: true})
126   - .then(function(subscription) {
127   - // The subscription was successful
128   - isPushEnabled = true;
129   - pushButton.textContent = 'Disable Push Messages';
130   - pushButton.disabled = false;
131   -
132   - // TODO: Send the subscription subscription.endpoint
133   - // to your server and save it to send a push message
134   - // at a later date
135   - return sendSubscriptionToServer(subscription);
136   - })
137   - .catch(function(e) {
138   - if (Notification.permission === 'denied') {
139   - // The user denied the notification permission which
140   - // means we failed to subscribe and the user will need
141   - // to manually change the notification permission to
142   - // subscribe to push messages
143   - window.Demo.debug.log('Permission for Notifications was denied');
144   - pushButton.disabled = true;
145   - } else {
146   - // A problem occurred with the subscription, this can
147   - // often be down to an issue or lack of the gcm_sender_id
148   - // and / or gcm_user_visible_only
149   - window.Demo.debug.log('Unable to subscribe to push.', e);
150   - pushButton.disabled = false;
151   - pushButton.textContent = 'Enable Push Messages';
152   - }
153   - });
154   - });
155   -}
156   -
157   -// Once the service worker is registered set the initial state
158   -function initialiseState() {
159   - // Are Notifications supported in the service worker?
160   - if (!('showNotification' in ServiceWorkerRegistration.prototype)) {
161   - window.Demo.debug.log('Notifications aren\'t supported.');
162   - return;
163   - }
164   -
165   - // Check the current Notification permission.
166   - // If its denied, it's a permanent block until the
167   - // user changes the permission
168   - if (Notification.permission === 'denied') {
169   - window.Demo.debug.log('The user has blocked notifications.');
170   - return;
171   - }
172   -
173   - // Check if push messaging is supported
174   - if (!('PushManager' in window)) {
175   - window.Demo.debug.log('Push messaging isn\'t supported.');
176   - return;
177   - }
178   -
179   - // We need the service worker registration to check for a subscription
180   - navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
181   - // Do we already have a push message subscription?
182   - serviceWorkerRegistration.pushManager.getSubscription()
183   - .then(function(subscription) {
184   - // Enable any UI which subscribes / unsubscribes from
185   - // push messages.
186   - var pushButton = document.querySelector('.js-push-button');
187   - pushButton.disabled = false;
188   -
189   - if (!subscription) {
190   - // We arenโ€™t subscribed to push, so set UI
191   - // to allow the user to enable push
192   - return;
193   - }
194   -
195   - // Keep your server in sync with the latest subscription
196   - sendSubscriptionToServer(subscription);
197   -
198   - // Set your UI to show they have subscribed for
199   - // push messages
200   - pushButton.textContent = 'Disable Push Messages';
201   - isPushEnabled = true;
202   - })
203   - .catch(function(err) {
204   - window.Demo.debug.log('Error during getSubscription()', err);
205   - });
206   - });
207   -}
208   -
209   -window.addEventListener('load', function() {
210   - var pushButton = document.querySelector('.js-push-button');
211   - pushButton.addEventListener('click', function() {
212   - if (isPushEnabled) {
213   - unsubscribe();
214   - } else {
215   - subscribe();
216   - }
217   - });
218   -
219   - // Check that service workers are supported, if so, progressively
220   - // enhance and add push messaging support, otherwise continue without it.
221   - if ('serviceWorker' in navigator) {
222   - navigator.serviceWorker.register('./service-worker.js')
223   - .then(initialiseState);
224   - } else {
225   - window.Demo.debug.log('Service workers aren\'t supported in this browser.');
226   - }
227   -});
cmg/manifest.json View file @ 08fac4c
1   -{
2   - "name": "Push Demo",
3   - "short_name": "Push Demo",
4   - "icons": [{
5   - "src": "images/icon-192x192.png",
6   - "sizes": "192x192"
7   - }],
8   - "start_url": "./index.html?homescreen=1",
9   - "display": "standalone",
10   - "gcm_sender_id": "45066531702",
11   -
12   - "//": "gcm_user_visible_only is only needed until Chrome 44 is in stable ",
13   - "gcm_user_visible_only": true
14   -}
cmg/service-worker.js View file @ 08fac4c
1   -/*
2   -Still not sure what this does, but i think it handles the event
3   -in the background.
4   -*/
5   -
6   -'use strict';
7   -
8   -self.addEventListener('push', function(event) {
9   - console.log('Received a push message', event);
10   -
11   - var title = 'Yay a message.';
12   - var body = 'We have received a push message.';
13   - var icon = '/images/icon-192x192.png';
14   - var tag = 'simple-push-demo-notification-tag';
15   -
16   - event.waitUntil(
17   - self.registration.showNotification(title, {
18   - body: body,
19   - icon: icon,
20   - tag: tag
21   - })
22   - );
23   -});
24   -
25   -
26   -self.addEventListener('notificationclick', function(event) {
27   - console.log('On notification click: ', event.notification.tag);
28   - // Android doesnโ€™t close the notification when you click on it
29   - // See: http://crbug.com/463146
30   - event.notification.close();
31   -
32   - // This looks to see if the current is already open and
33   - // focuses if it is
34   - event.waitUntil(clients.matchAll({
35   - type: "window"
36   - }).then(function(clientList) {
37   - for (var i = 0; i < clientList.length; i++) {
38   - var client = clientList[i];
39   - if (client.url == '/' && 'focus' in client)
40   - return client.focus();
41   - }
42   - if (clients.openWindow)
43   - return clients.openWindow('/');
44   - }));
45   -
46   -});
manifest.json View file @ 08fac4c
... ... @@ -9,6 +9,7 @@
9 9 "start_url": "/index.html",
10 10 "display": "standalone",
11 11 "gcm_sender_id": "45066531702",
12   - "gcm_user_visible_only": true
  12 + "gcm_user_visible_only": true
  13 + "permissions": ["gcm"]
13 14 }
scripts/SettingsController.js View file @ 08fac4c
1 1 angular.module('flashy.SettingsController', ['ui.router']).
2 2  
3   - controller('SettingsController', function($scope) {
  3 + controller('SettingsController', function($scope, $http) {
  4 + $scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) {
4 5  
  6 + };
  7 + console.log("checking to see if chrome");
  8 + if (!chrome) { return; }
  9 + console.log("chrome");
  10 + $scope.registerCallback = function(registrationId) {
  11 + if (chrome.runtime.lastError) {
  12 + console.log("Registration failed")
  13 + }
5 14  
6   - $scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) {
  15 + sendRegistrationId(registrationId, function(succeed) {
  16 + if (succeed) {
  17 + chrome.storage.local.set({registered: true});
  18 + }
  19 + });
  20 + };
7 21  
  22 + function sendRegistrationId(registrationId, callback) {
  23 + console.log("registration id: "+registrationId);
  24 + $http.post('/api/subscribe/', JSON.stringify({
  25 + 'registration_id': registrationId
  26 + }));
  27 + callback(true);
  28 + }
8 29  
  30 + console.log(chrome.runtime.onStartup);
  31 + chrome.runtime.onStartup.addListener(function() {
  32 + chrome.storage.local.get("registered", function(result) {
  33 + // If already registered, bail out.
  34 + if (result["registered"])
  35 + return;
9 36  
10   -
11   - };
12   -
13   - });
  37 + // Up to 100 senders are allowed.
  38 + var senderIds = ["45066531702"];
  39 + chrome.gcm.register(senderIds, registerCallback);
  40 + });
  41 + });
  42 + });