Commit 08fac4c5ead63f002f53d9821aaf00d987caa64d

Authored by Andrew Buss

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

Showing 15 changed files Inline Diff

cmg/README.md View file @ 08fac4c
Push Messaging and Notification Sample 1 File was deleted
=== 2
3
Learn more at http://www.chromestatus.com/feature/5416033485586432 and http://www.chromestatus.com/feature/5480344312610816 4
5
To use this sample please do the following: 6
7
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) 8
1. Enable GCM support 9
1. Create a copy of [config.sample.js](config.sample.js) called config.js 10
1. Create a copy of [manifest.sample.json](manifest.sample.json) called manifest.json 11
1. Replace `<Your Public API Key ...>` in your new `config.js` file with your own API key from the Google Developer Console project 12
cmg/analytics.js View file @ 08fac4c
/* 1 File was deleted
This is provided from the sample as well. Its suppose to be from a live link, but i copied and pasted the code over. 2
*/ 3
4
(function(){var aa=encodeURIComponent,f=window,n=Math;function Pc(a,b){return a.href=b} 5
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, 6
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||""== 7
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= 8
!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", 9
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";} 10
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)} 11
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)} 12
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)}; 13
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("^"+ 14
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"); 15
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"); 16
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"); 17
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"); 18
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}); 19
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"), 20
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&& 21
(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; 22
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";}, 23
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): 24
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}; 25
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)}; 26
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"== 27
b.method[I]()&&(b.action=qd(a,b[kd]))}}; 28
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], 29
"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, 30
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)); 31
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= 32
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, 33
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= 34
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], 35
"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]}; 36
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&& 37
(!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}; 38
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]|| 39
"",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)}; 40
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]("?")|| 41
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}; 42
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)}; 43
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()|| 44
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)}; 45
cmg/config.js View file @ 08fac4c
/* 1 File was deleted
This file sets up a global variable gcmAPIKey, which contains our key. 2
*/ 3
4
window.GoogleSamples = window.GoogleSamples || {}; 5
window.GoogleSamples.Config = window.GoogleSamples.Config || { 6
gcmAPIKey: 'AIzaSyCPjkgseoVp8shXOMwFnGBeEijizpLDXOs' 7
/* 1 File was deleted
This demo provides functionality that output debug messages. 2
*/ 3
4
'use strict'; 5
6
function Debug() { 7
8
} 9
10
Debug.prototype.log = function() { 11
var paragraphElement = document.createElement('p'); 12
paragraphElement.textContent = Array.prototype.join.call(arguments, ''); 13
document.querySelector('.js-log').appendChild(paragraphElement); 14
} 15
16
window.addEventListener('load', function() { 17
var logDiv = document.createElement('div'); 18
logDiv.classList.add('js-log'); 19
20
var heading = document.createElement('h2'); 21
cmg/images/icon-192x192.png View file @ 08fac4c

1.63 KB

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