Add BookOwl's geolocation block to httpBlocks library

dev
Brian Harvey 2016-08-16 17:06:09 -07:00 zatwierdzone przez GitHub
rodzic 21abf24cba
commit 60942484e6
1 zmienionych plików z 1 dodań i 1 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="%&apos;method&apos; url: %&apos;url&apos; send: %&apos;payload&apos; headers: %&apos;headers&apos;" type="reporter" category="sensing"><header></header><code></code><inputs><input type="%s" readonly="true">GET<options>GET
POST
PUT
DELETE</options></input><input type="%s">http://snap.berkeley.edu</input><input type="%s"></input><input type="%mult%l" readonly="true"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>method</l><l>url</l><l>data</l><l>headers</l><l>proc</l></list><l>var response, i, header;&#xD;if (!proc.httpRequest) {&#xD; proc.httpRequest = new XMLHttpRequest();&#xD; proc.httpRequest.open(method, url, true);&#xD; proc.assertType(headers, &apos;list&apos;);&#xD; for (i = 1; i &lt;= headers.length(); i += 1) {&#xD; header = headers.at(i);&#xD; proc.assertType(header, &apos;list&apos;);&#xD; proc.httpRequest.setRequestHeader(&#xD; header.at(1),&#xD; header.at(2)&#xD; );&#xD; }&#xD; proc.httpRequest.send(data || null);&#xD;} else if (proc.httpRequest.readyState === 4) {&#xD; response = proc.httpRequest.responseText;&#xD; proc.httpRequest = null;&#xD; return response;&#xD;}&#xD;proc.pushContext(&apos;doYield&apos;);&#xD;proc.pushContext();</l></block><list><block var="method"/><block var="url"/><block var="payload"/><block var="headers"/></list></block></block></script></block-definition><block-definition s="key: %&apos;key&apos; value: %&apos;value&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%s"></input><input type="%s"></input></inputs><script><block s="doReport"><block s="reportNewList"><list><block var="key"/><block var="value"/></list></block></block></script></block-definition></blocks>
DELETE</options></input><input type="%s">http://snap.berkeley.edu</input><input type="%s"></input><input type="%mult%l" readonly="true"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>method</l><l>url</l><l>data</l><l>headers</l><l>proc</l></list><l>var response, i, header;&#xD;if (!proc.httpRequest) {&#xD; proc.httpRequest = new XMLHttpRequest();&#xD; proc.httpRequest.open(method, url, true);&#xD; proc.assertType(headers, &apos;list&apos;);&#xD; for (i = 1; i &lt;= headers.length(); i += 1) {&#xD; header = headers.at(i);&#xD; proc.assertType(header, &apos;list&apos;);&#xD; proc.httpRequest.setRequestHeader(&#xD; header.at(1),&#xD; header.at(2)&#xD; );&#xD; }&#xD; proc.httpRequest.send(data || null);&#xD;} else if (proc.httpRequest.readyState === 4) {&#xD; response = proc.httpRequest.responseText;&#xD; proc.httpRequest = null;&#xD; return response;&#xD;}&#xD;proc.pushContext(&apos;doYield&apos;);&#xD;proc.pushContext();</l></block><list><block var="method"/><block var="url"/><block var="payload"/><block var="headers"/></list></block></block></script></block-definition><block-definition s="key: %&apos;key&apos; value: %&apos;value&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%s"></input><input type="%s"></input></inputs><script><block s="doReport"><block s="reportNewList"><list><block var="key"/><block var="value"/></list></block></block></script></block-definition><block-definition s="curent location" type="reporter" category="sensing"><comment x="0" y="0" w="200" collapsed="false">Reports a three-item list containing the latitude and longitude of the user, and the precision of the measurements. Works only if the user allows snap.berkeley.edu access to location data. Some browsers also require an HTTPS connection to Snap!.</comment><header></header><code></code><inputs></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>proc</l></list><l>if (!proc.geostarted) {&#xD; var geo = navigator.geolocation;&#xD; var cords = [];&#xD; var options = {&#xD; enableHighAccuracy: false,&#xD; };&#xD;&#xD; function success(pos) {&#xD; console.log(pos);&#xD; proc.geocords = [pos.coords.latitude,&#xD; pos.coords.longitude,&#xD; pos.coords.accuracy];&#xD; }&#xD;&#xD; function error(err) {&#xD; alert("ERROR " + err.code + ": " + err.message);&#xD; }&#xD; proc.geostarted = true;&#xD; proc.geocords = null;&#xD; console.log("starting geolocation")&#xD; geo.getCurrentPosition(success, error, options);&#xD;} else if (proc.geocords) {&#xD; var cords = proc.geocords;&#xD; proc.geostarted = null;&#xD; proc.geocords = null;&#xD; console.log("returning");&#xD; return new List(cords);&#xD;} else {&#xD; console.log("yielding");&#xD; proc.pushContext(&apos;doYield&apos;);&#xD; proc.pushContext();&#xD;}</l></block><list></list></block></block></script></block-definition></blocks>