diff --git a/build/header b/build/header index a671586e..bcc5a493 100644 --- a/build/header +++ b/build/header @@ -12,9 +12,6 @@ // Include RSVP if this is being run in node if (typeof module !== "undefined" && typeof process !== "undefined") { - // We need this `Firebase || require("firebase")` hack to get GeoFire to work properly in Node.js - // since otherwise, checking for `instanceof Firebase` fails. - var Firebase = Firebase || require("firebase"); var RSVP = require("rsvp"); } diff --git a/changelog.txt b/changelog.txt index e69de29b..d0d0a892 100644 --- a/changelog.txt +++ b/changelog.txt @@ -0,0 +1 @@ +fixed - Fixed typo in 3.0.1 release which caused it to be unusable. \ No newline at end of file diff --git a/examples/fish1/js/vendor/geofire.min.js b/examples/fish1/js/vendor/geofire.min.js index 8d5bd298..62ac1195 100644 --- a/examples/fish1/js/vendor/geofire.min.js +++ b/examples/fish1/js/vendor/geofire.min.js @@ -9,4 +9,4 @@ * https://github.com/firebase/geofire-js/ * License: MIT */ -if("undefined"!=typeof module&&"undefined"!=typeof process)var Firebase=require("firebase"),RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var r=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},t=function(r){if(this.ref=function(){return t},this.set=function(n,r){return d(n),null!==r&&y(r),new RSVP.Promise(function(i,a){function o(e){e?a("Error: Firebase synchronization failed: "+e):i()}if(null===r)t.child(n).remove(o);else{var u=w(r);t.child(n).setWithPriority(e(r,u),u,o)}})},this.get=function(e){return d(e),new RSVP.Promise(function(r,i){t.child(e).once("value",function(e){r(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new O(t,e)},r instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var t=r};t.distance=function(e,n){y(e),y(n);var r=6371,t=b(n[0]-e[0]),i=b(n[1]-e[1]),a=Math.sin(t/2)*Math.sin(t/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),o=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return r*o};var i=10,a="0123456789bcdefghjkmnpqrstuvwxyz",o=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var r=e[0],t=e[1];"number"!=typeof r||isNaN(r)?n="latitude must be a number":-90>r||r>90?n="latitude must be within the range [-90, 90]":"number"!=typeof t||isNaN(t)?n="longitude must be a number":(-180>t||t>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var r=0,t=e.length;t>r;++r)-1===a.indexOf(e[r])&&(n='geohash cannot contain "'+e[r]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var r in e)if(e.hasOwnProperty(r)&&"center"!==r&&"radius"!==r)throw new Error("Unexpected attribute '"+r+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},w=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var r={min:-90,max:90},t={min:-180,max:180},o="",u=0,f=0,c=1;o.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,o+=a[u],u=0)}return o},p=function(e,n){var r=b(n),t=Math.cos(r)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(r)*Math.sin(r)),a=t*i;return h>a?e>0?360:0:Math.min(360,e/a)},g=function(e,n){var r=p(e,n);return Math.abs(r)>1e-6?Math.max(1,Math.log2(360/r)):1},M=function(e){return Math.min(Math.log2(o/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=2*Math.floor(M(n)),o=2*Math.floor(g(n,t))-1,f=2*Math.floor(g(n,i))-1;return Math.min(a,o,f,c)},x=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=p(n,t),o=p(n,i),f=Math.max(a,o);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[t,e[1]],[t,k(e[1]-f)],[t,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},_=function(e,n){v(e);var r=Math.ceil(n/f);if(e.length>u<31?[t+a[c],t+"~"]:[t+a[c],t+a[l]]},F=function(e,n){y(e);var r=Math.max(1,E(e,n)),t=Math.ceil(r/f),i=x(e,n),a=i.map(function(e){return _(w(e,t),r)});return a.filter(function(e,n){return!a.some(function(r,t){return n>t&&e[0]===r[0]&&e[1]===r[1]})})},O=function(e,a){function o(e,n,r,t){_[e].forEach(function(e){"undefined"==typeof r||null===r?e(n,null,null):e(n,r,t)})}function u(){_.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var r=x.startAt(e[0]).endAt(e[1]);r.off("child_added",n.childAddedCallback),r.off("child_removed",n.childRemovedCallback),r.off("child_changed",n.childChangedCallback),r.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var r=f(e);l(r,n),delete I[e]}}for(var t in P)if(P.hasOwnProperty(t)&&!d(P[t].geohash)){if(P[t].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete P[t]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var r,a,u=P.hasOwnProperty(e)?P[e].isInQuery:!1,f=P.hasOwnProperty(e)?P[e].location:null;r=t.distance(n,A),a=Q>=r,P[e]={location:n,distanceFromCenter:r,isInQuery:a,geohash:w(n,i)},a&&!u?o("key_entered",e,n,r):!a||null===f||n[0]===f[0]&&n[1]===f[1]?!a&&u&&o("key_exited",e,n,r):o("key_moved",e,n,r)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var r=f(n);if(e>=r[0]&&e<=r[1])return!0}return!1}function v(e,n){var r=P[e];if(delete P[e],"undefined"!=typeof r&&r.isInQuery){var i=n?t.distance(n,A):null;o("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function p(e){h(e.name(),n(e.val()))}function g(e){var r=e.name();P.hasOwnProperty(r)&&x.child(r).once("value",function(e){var t=null===e.val()?null:n(e.val()),i=null!==t?w(t):null;d(i)||v(r,t)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),O=0===E.length,O&&u()}function k(){var e=F(A,1e3*Q).map(c);e=e.filter(function(n,r){return e.indexOf(n)===r});for(var n in I)if(I.hasOwnProperty(n)){var r=e.indexOf(n);-1===r?I[n].active=!1:(I[n].active=!0,e.splice(r,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),r=x.startAt(n[0]).endAt(n[1]),t=r.on("child_added",b),i=r.on("child_removed",g),a=r.on("child_changed",p),o=r.on("value",function(){r.off("value",o),M(e)});I[e]={active:!0,childAddedCallback:t,childRemovedCallback:i,childChangedCallback:a,valueCallback:o}}),0===e.length&&M()}if(this.center=function(){return A},this.radius=function(){return Q},this.updateCriteria=function(e){m(e),A=e.center||A,Q=e.radius||Q;for(var n in P)if(P.hasOwnProperty(n)){var r=P[n],i=r.isInQuery;r.distanceFromCenter=t.distance(r.location,A),r.isInQuery=r.distanceFromCenter<=Q,i&&!r.isInQuery?o("key_exited",n,r.location,r.distanceFromCenter):!i&&r.isInQuery&&o("key_entered",n,r.location,r.distanceFromCenter)}O=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(_[e].push(n),"key_entered"===e)for(var t in P)if(P.hasOwnProperty(t)){var i=P[t];i.isInQuery&&n(t,i.location,i.distanceFromCenter)}return"ready"===e&&O&&n(),new r(function(){_[e].splice(_[e].indexOf(n),1)})},this.cancel=function(){_={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}P={},clearInterval(N)},e instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,_={ready:[],key_entered:[],key_exited:[],key_moved:[]},O=!1,P={},I={},C=!1,q=null,N=setInterval(function(){C===!1&&s()},1e4);m(a,!0);var A=a.center,Q=a.radius;k()};return t}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file +if("undefined"!=typeof module&&"undefined"!=typeof process)var RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var t=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},r=function(t){if(this.ref=function(){return r},this.set=function(n,t){return d(n),null!==t&&y(t),new RSVP.Promise(function(i,o){function a(e){e?o("Error: Firebase synchronization failed: "+e):i()}if(null===t)r.child(n).remove(a);else{var u=p(t);r.child(n).setWithPriority(e(t,u),u,a)}})},this.get=function(e){return d(e),new RSVP.Promise(function(t,i){r.child(e).once("value",function(e){t(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new P(r,e)},"[object Object]"!==Object.prototype.toString.call(t))throw new Error("firebaseRef must be an instance of Firebase");var r=t};r.distance=function(e,n){y(e),y(n);var t=6371,r=b(n[0]-e[0]),i=b(n[1]-e[1]),o=Math.sin(r/2)*Math.sin(r/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),a=2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o));return t*a};var i=10,o="0123456789bcdefghjkmnpqrstuvwxyz",a=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var t=e[0],r=e[1];"number"!=typeof t||isNaN(t)?n="latitude must be a number":-90>t||t>90?n="latitude must be within the range [-90, 90]":"number"!=typeof r||isNaN(r)?n="longitude must be a number":(-180>r||r>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var t=0,r=e.length;r>t;++t)-1===o.indexOf(e[t])&&(n='geohash cannot contain "'+e[t]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var t in e)if(e.hasOwnProperty(t)&&"center"!==t&&"radius"!==t)throw new Error("Unexpected attribute '"+t+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},p=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var t={min:-90,max:90},r={min:-180,max:180},a="",u=0,f=0,c=1;a.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,a+=o[u],u=0)}return a},w=function(e,n){var t=b(n),r=Math.cos(t)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(t)*Math.sin(t)),o=r*i;return h>o?e>0?360:0:Math.min(360,e/o)},g=function(e,n){var t=w(e,n);return Math.abs(t)>1e-6?Math.max(1,Math.log2(360/t)):1},M=function(e){return Math.min(Math.log2(a/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=2*Math.floor(M(n)),a=2*Math.floor(g(n,r))-1,f=2*Math.floor(g(n,i))-1;return Math.min(o,a,f,c)},x=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=w(n,r),a=w(n,i),f=Math.max(o,a);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[r,e[1]],[r,k(e[1]-f)],[r,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},O=function(e,n){v(e);var t=Math.ceil(n/f);if(e.length>u<31?[r+o[c],r+"~"]:[r+o[c],r+o[l]]},_=function(e,n){y(e);var t=Math.max(1,E(e,n)),r=Math.ceil(t/f),i=x(e,n),o=i.map(function(e){return O(p(e,r),t)});return o.filter(function(e,n){return!o.some(function(t,r){return n>r&&e[0]===t[0]&&e[1]===t[1]})})},P=function(e,o){function a(e,n,t,r){O[e].forEach(function(e){"undefined"==typeof t||null===t?e(n,null,null):e(n,t,r)})}function u(){O.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var t=x.startAt(e[0]).endAt(e[1]);t.off("child_added",n.childAddedCallback),t.off("child_removed",n.childRemovedCallback),t.off("child_changed",n.childChangedCallback),t.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var t=f(e);l(t,n),delete I[e]}}for(var r in F)if(F.hasOwnProperty(r)&&!d(F[r].geohash)){if(F[r].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete F[r]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var t,o,u=F.hasOwnProperty(e)?F[e].isInQuery:!1,f=F.hasOwnProperty(e)?F[e].location:null;t=r.distance(n,N),o=A>=t,F[e]={location:n,distanceFromCenter:t,isInQuery:o,geohash:p(n,i)},o&&!u?a("key_entered",e,n,t):!o||null===f||n[0]===f[0]&&n[1]===f[1]?!o&&u&&a("key_exited",e,n,t):a("key_moved",e,n,t)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var t=f(n);if(e>=t[0]&&e<=t[1])return!0}return!1}function v(e,n){var t=F[e];if(delete F[e],"undefined"!=typeof t&&t.isInQuery){var i=n?r.distance(n,N):null;a("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function w(e){h(e.name(),n(e.val()))}function g(e){var t=e.name();F.hasOwnProperty(t)&&x.child(t).once("value",function(e){var r=null===e.val()?null:n(e.val()),i=null!==r?p(r):null;d(i)||v(t,r)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),P=0===E.length,P&&u()}function k(){var e=_(N,1e3*A).map(c);e=e.filter(function(n,t){return e.indexOf(n)===t});for(var n in I)if(I.hasOwnProperty(n)){var t=e.indexOf(n);-1===t?I[n].active=!1:(I[n].active=!0,e.splice(t,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),t=x.startAt(n[0]).endAt(n[1]),r=t.on("child_added",b),i=t.on("child_removed",g),o=t.on("child_changed",w),a=t.on("value",function(){t.off("value",a),M(e)});I[e]={active:!0,childAddedCallback:r,childRemovedCallback:i,childChangedCallback:o,valueCallback:a}}),0===e.length&&M()}if(this.center=function(){return N},this.radius=function(){return A},this.updateCriteria=function(e){m(e),N=e.center||N,A=e.radius||A;for(var n in F)if(F.hasOwnProperty(n)){var t=F[n],i=t.isInQuery;t.distanceFromCenter=r.distance(t.location,N),t.isInQuery=t.distanceFromCenter<=A,i&&!t.isInQuery?a("key_exited",n,t.location,t.distanceFromCenter):!i&&t.isInQuery&&a("key_entered",n,t.location,t.distanceFromCenter)}P=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(O[e].push(n),"key_entered"===e)for(var r in F)if(F.hasOwnProperty(r)){var i=F[r];i.isInQuery&&n(r,i.location,i.distanceFromCenter)}return"ready"===e&&P&&n(),new t(function(){O[e].splice(O[e].indexOf(n),1)})},this.cancel=function(){O={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}F={},clearInterval(j)},"[object Object]"!==Object.prototype.toString.call(e))throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,O={ready:[],key_entered:[],key_exited:[],key_moved:[]},P=!1,F={},I={},C=!1,q=null,j=setInterval(function(){C===!1&&s()},1e4);m(o,!0);var N=o.center,A=o.radius;k()};return r}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file diff --git a/examples/fish2/js/vendor/geofire.min.js b/examples/fish2/js/vendor/geofire.min.js index 8d5bd298..62ac1195 100644 --- a/examples/fish2/js/vendor/geofire.min.js +++ b/examples/fish2/js/vendor/geofire.min.js @@ -9,4 +9,4 @@ * https://github.com/firebase/geofire-js/ * License: MIT */ -if("undefined"!=typeof module&&"undefined"!=typeof process)var Firebase=require("firebase"),RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var r=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},t=function(r){if(this.ref=function(){return t},this.set=function(n,r){return d(n),null!==r&&y(r),new RSVP.Promise(function(i,a){function o(e){e?a("Error: Firebase synchronization failed: "+e):i()}if(null===r)t.child(n).remove(o);else{var u=w(r);t.child(n).setWithPriority(e(r,u),u,o)}})},this.get=function(e){return d(e),new RSVP.Promise(function(r,i){t.child(e).once("value",function(e){r(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new O(t,e)},r instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var t=r};t.distance=function(e,n){y(e),y(n);var r=6371,t=b(n[0]-e[0]),i=b(n[1]-e[1]),a=Math.sin(t/2)*Math.sin(t/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),o=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return r*o};var i=10,a="0123456789bcdefghjkmnpqrstuvwxyz",o=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var r=e[0],t=e[1];"number"!=typeof r||isNaN(r)?n="latitude must be a number":-90>r||r>90?n="latitude must be within the range [-90, 90]":"number"!=typeof t||isNaN(t)?n="longitude must be a number":(-180>t||t>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var r=0,t=e.length;t>r;++r)-1===a.indexOf(e[r])&&(n='geohash cannot contain "'+e[r]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var r in e)if(e.hasOwnProperty(r)&&"center"!==r&&"radius"!==r)throw new Error("Unexpected attribute '"+r+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},w=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var r={min:-90,max:90},t={min:-180,max:180},o="",u=0,f=0,c=1;o.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,o+=a[u],u=0)}return o},p=function(e,n){var r=b(n),t=Math.cos(r)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(r)*Math.sin(r)),a=t*i;return h>a?e>0?360:0:Math.min(360,e/a)},g=function(e,n){var r=p(e,n);return Math.abs(r)>1e-6?Math.max(1,Math.log2(360/r)):1},M=function(e){return Math.min(Math.log2(o/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=2*Math.floor(M(n)),o=2*Math.floor(g(n,t))-1,f=2*Math.floor(g(n,i))-1;return Math.min(a,o,f,c)},x=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=p(n,t),o=p(n,i),f=Math.max(a,o);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[t,e[1]],[t,k(e[1]-f)],[t,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},_=function(e,n){v(e);var r=Math.ceil(n/f);if(e.length>u<31?[t+a[c],t+"~"]:[t+a[c],t+a[l]]},F=function(e,n){y(e);var r=Math.max(1,E(e,n)),t=Math.ceil(r/f),i=x(e,n),a=i.map(function(e){return _(w(e,t),r)});return a.filter(function(e,n){return!a.some(function(r,t){return n>t&&e[0]===r[0]&&e[1]===r[1]})})},O=function(e,a){function o(e,n,r,t){_[e].forEach(function(e){"undefined"==typeof r||null===r?e(n,null,null):e(n,r,t)})}function u(){_.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var r=x.startAt(e[0]).endAt(e[1]);r.off("child_added",n.childAddedCallback),r.off("child_removed",n.childRemovedCallback),r.off("child_changed",n.childChangedCallback),r.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var r=f(e);l(r,n),delete I[e]}}for(var t in P)if(P.hasOwnProperty(t)&&!d(P[t].geohash)){if(P[t].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete P[t]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var r,a,u=P.hasOwnProperty(e)?P[e].isInQuery:!1,f=P.hasOwnProperty(e)?P[e].location:null;r=t.distance(n,A),a=Q>=r,P[e]={location:n,distanceFromCenter:r,isInQuery:a,geohash:w(n,i)},a&&!u?o("key_entered",e,n,r):!a||null===f||n[0]===f[0]&&n[1]===f[1]?!a&&u&&o("key_exited",e,n,r):o("key_moved",e,n,r)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var r=f(n);if(e>=r[0]&&e<=r[1])return!0}return!1}function v(e,n){var r=P[e];if(delete P[e],"undefined"!=typeof r&&r.isInQuery){var i=n?t.distance(n,A):null;o("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function p(e){h(e.name(),n(e.val()))}function g(e){var r=e.name();P.hasOwnProperty(r)&&x.child(r).once("value",function(e){var t=null===e.val()?null:n(e.val()),i=null!==t?w(t):null;d(i)||v(r,t)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),O=0===E.length,O&&u()}function k(){var e=F(A,1e3*Q).map(c);e=e.filter(function(n,r){return e.indexOf(n)===r});for(var n in I)if(I.hasOwnProperty(n)){var r=e.indexOf(n);-1===r?I[n].active=!1:(I[n].active=!0,e.splice(r,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),r=x.startAt(n[0]).endAt(n[1]),t=r.on("child_added",b),i=r.on("child_removed",g),a=r.on("child_changed",p),o=r.on("value",function(){r.off("value",o),M(e)});I[e]={active:!0,childAddedCallback:t,childRemovedCallback:i,childChangedCallback:a,valueCallback:o}}),0===e.length&&M()}if(this.center=function(){return A},this.radius=function(){return Q},this.updateCriteria=function(e){m(e),A=e.center||A,Q=e.radius||Q;for(var n in P)if(P.hasOwnProperty(n)){var r=P[n],i=r.isInQuery;r.distanceFromCenter=t.distance(r.location,A),r.isInQuery=r.distanceFromCenter<=Q,i&&!r.isInQuery?o("key_exited",n,r.location,r.distanceFromCenter):!i&&r.isInQuery&&o("key_entered",n,r.location,r.distanceFromCenter)}O=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(_[e].push(n),"key_entered"===e)for(var t in P)if(P.hasOwnProperty(t)){var i=P[t];i.isInQuery&&n(t,i.location,i.distanceFromCenter)}return"ready"===e&&O&&n(),new r(function(){_[e].splice(_[e].indexOf(n),1)})},this.cancel=function(){_={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}P={},clearInterval(N)},e instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,_={ready:[],key_entered:[],key_exited:[],key_moved:[]},O=!1,P={},I={},C=!1,q=null,N=setInterval(function(){C===!1&&s()},1e4);m(a,!0);var A=a.center,Q=a.radius;k()};return t}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file +if("undefined"!=typeof module&&"undefined"!=typeof process)var RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var t=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},r=function(t){if(this.ref=function(){return r},this.set=function(n,t){return d(n),null!==t&&y(t),new RSVP.Promise(function(i,o){function a(e){e?o("Error: Firebase synchronization failed: "+e):i()}if(null===t)r.child(n).remove(a);else{var u=p(t);r.child(n).setWithPriority(e(t,u),u,a)}})},this.get=function(e){return d(e),new RSVP.Promise(function(t,i){r.child(e).once("value",function(e){t(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new P(r,e)},"[object Object]"!==Object.prototype.toString.call(t))throw new Error("firebaseRef must be an instance of Firebase");var r=t};r.distance=function(e,n){y(e),y(n);var t=6371,r=b(n[0]-e[0]),i=b(n[1]-e[1]),o=Math.sin(r/2)*Math.sin(r/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),a=2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o));return t*a};var i=10,o="0123456789bcdefghjkmnpqrstuvwxyz",a=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var t=e[0],r=e[1];"number"!=typeof t||isNaN(t)?n="latitude must be a number":-90>t||t>90?n="latitude must be within the range [-90, 90]":"number"!=typeof r||isNaN(r)?n="longitude must be a number":(-180>r||r>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var t=0,r=e.length;r>t;++t)-1===o.indexOf(e[t])&&(n='geohash cannot contain "'+e[t]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var t in e)if(e.hasOwnProperty(t)&&"center"!==t&&"radius"!==t)throw new Error("Unexpected attribute '"+t+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},p=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var t={min:-90,max:90},r={min:-180,max:180},a="",u=0,f=0,c=1;a.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,a+=o[u],u=0)}return a},w=function(e,n){var t=b(n),r=Math.cos(t)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(t)*Math.sin(t)),o=r*i;return h>o?e>0?360:0:Math.min(360,e/o)},g=function(e,n){var t=w(e,n);return Math.abs(t)>1e-6?Math.max(1,Math.log2(360/t)):1},M=function(e){return Math.min(Math.log2(a/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=2*Math.floor(M(n)),a=2*Math.floor(g(n,r))-1,f=2*Math.floor(g(n,i))-1;return Math.min(o,a,f,c)},x=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=w(n,r),a=w(n,i),f=Math.max(o,a);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[r,e[1]],[r,k(e[1]-f)],[r,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},O=function(e,n){v(e);var t=Math.ceil(n/f);if(e.length>u<31?[r+o[c],r+"~"]:[r+o[c],r+o[l]]},_=function(e,n){y(e);var t=Math.max(1,E(e,n)),r=Math.ceil(t/f),i=x(e,n),o=i.map(function(e){return O(p(e,r),t)});return o.filter(function(e,n){return!o.some(function(t,r){return n>r&&e[0]===t[0]&&e[1]===t[1]})})},P=function(e,o){function a(e,n,t,r){O[e].forEach(function(e){"undefined"==typeof t||null===t?e(n,null,null):e(n,t,r)})}function u(){O.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var t=x.startAt(e[0]).endAt(e[1]);t.off("child_added",n.childAddedCallback),t.off("child_removed",n.childRemovedCallback),t.off("child_changed",n.childChangedCallback),t.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var t=f(e);l(t,n),delete I[e]}}for(var r in F)if(F.hasOwnProperty(r)&&!d(F[r].geohash)){if(F[r].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete F[r]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var t,o,u=F.hasOwnProperty(e)?F[e].isInQuery:!1,f=F.hasOwnProperty(e)?F[e].location:null;t=r.distance(n,N),o=A>=t,F[e]={location:n,distanceFromCenter:t,isInQuery:o,geohash:p(n,i)},o&&!u?a("key_entered",e,n,t):!o||null===f||n[0]===f[0]&&n[1]===f[1]?!o&&u&&a("key_exited",e,n,t):a("key_moved",e,n,t)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var t=f(n);if(e>=t[0]&&e<=t[1])return!0}return!1}function v(e,n){var t=F[e];if(delete F[e],"undefined"!=typeof t&&t.isInQuery){var i=n?r.distance(n,N):null;a("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function w(e){h(e.name(),n(e.val()))}function g(e){var t=e.name();F.hasOwnProperty(t)&&x.child(t).once("value",function(e){var r=null===e.val()?null:n(e.val()),i=null!==r?p(r):null;d(i)||v(t,r)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),P=0===E.length,P&&u()}function k(){var e=_(N,1e3*A).map(c);e=e.filter(function(n,t){return e.indexOf(n)===t});for(var n in I)if(I.hasOwnProperty(n)){var t=e.indexOf(n);-1===t?I[n].active=!1:(I[n].active=!0,e.splice(t,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),t=x.startAt(n[0]).endAt(n[1]),r=t.on("child_added",b),i=t.on("child_removed",g),o=t.on("child_changed",w),a=t.on("value",function(){t.off("value",a),M(e)});I[e]={active:!0,childAddedCallback:r,childRemovedCallback:i,childChangedCallback:o,valueCallback:a}}),0===e.length&&M()}if(this.center=function(){return N},this.radius=function(){return A},this.updateCriteria=function(e){m(e),N=e.center||N,A=e.radius||A;for(var n in F)if(F.hasOwnProperty(n)){var t=F[n],i=t.isInQuery;t.distanceFromCenter=r.distance(t.location,N),t.isInQuery=t.distanceFromCenter<=A,i&&!t.isInQuery?a("key_exited",n,t.location,t.distanceFromCenter):!i&&t.isInQuery&&a("key_entered",n,t.location,t.distanceFromCenter)}P=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(O[e].push(n),"key_entered"===e)for(var r in F)if(F.hasOwnProperty(r)){var i=F[r];i.isInQuery&&n(r,i.location,i.distanceFromCenter)}return"ready"===e&&P&&n(),new t(function(){O[e].splice(O[e].indexOf(n),1)})},this.cancel=function(){O={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}F={},clearInterval(j)},"[object Object]"!==Object.prototype.toString.call(e))throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,O={ready:[],key_entered:[],key_exited:[],key_moved:[]},P=!1,F={},I={},C=!1,q=null,j=setInterval(function(){C===!1&&s()},1e4);m(o,!0);var N=o.center,A=o.radius;k()};return r}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file diff --git a/examples/fish3/js/vendor/geofire.min.js b/examples/fish3/js/vendor/geofire.min.js index 8d5bd298..62ac1195 100644 --- a/examples/fish3/js/vendor/geofire.min.js +++ b/examples/fish3/js/vendor/geofire.min.js @@ -9,4 +9,4 @@ * https://github.com/firebase/geofire-js/ * License: MIT */ -if("undefined"!=typeof module&&"undefined"!=typeof process)var Firebase=require("firebase"),RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var r=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},t=function(r){if(this.ref=function(){return t},this.set=function(n,r){return d(n),null!==r&&y(r),new RSVP.Promise(function(i,a){function o(e){e?a("Error: Firebase synchronization failed: "+e):i()}if(null===r)t.child(n).remove(o);else{var u=w(r);t.child(n).setWithPriority(e(r,u),u,o)}})},this.get=function(e){return d(e),new RSVP.Promise(function(r,i){t.child(e).once("value",function(e){r(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new O(t,e)},r instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var t=r};t.distance=function(e,n){y(e),y(n);var r=6371,t=b(n[0]-e[0]),i=b(n[1]-e[1]),a=Math.sin(t/2)*Math.sin(t/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),o=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return r*o};var i=10,a="0123456789bcdefghjkmnpqrstuvwxyz",o=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var r=e[0],t=e[1];"number"!=typeof r||isNaN(r)?n="latitude must be a number":-90>r||r>90?n="latitude must be within the range [-90, 90]":"number"!=typeof t||isNaN(t)?n="longitude must be a number":(-180>t||t>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var r=0,t=e.length;t>r;++r)-1===a.indexOf(e[r])&&(n='geohash cannot contain "'+e[r]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var r in e)if(e.hasOwnProperty(r)&&"center"!==r&&"radius"!==r)throw new Error("Unexpected attribute '"+r+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},w=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var r={min:-90,max:90},t={min:-180,max:180},o="",u=0,f=0,c=1;o.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,o+=a[u],u=0)}return o},p=function(e,n){var r=b(n),t=Math.cos(r)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(r)*Math.sin(r)),a=t*i;return h>a?e>0?360:0:Math.min(360,e/a)},g=function(e,n){var r=p(e,n);return Math.abs(r)>1e-6?Math.max(1,Math.log2(360/r)):1},M=function(e){return Math.min(Math.log2(o/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=2*Math.floor(M(n)),o=2*Math.floor(g(n,t))-1,f=2*Math.floor(g(n,i))-1;return Math.min(a,o,f,c)},x=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=p(n,t),o=p(n,i),f=Math.max(a,o);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[t,e[1]],[t,k(e[1]-f)],[t,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},_=function(e,n){v(e);var r=Math.ceil(n/f);if(e.length>u<31?[t+a[c],t+"~"]:[t+a[c],t+a[l]]},F=function(e,n){y(e);var r=Math.max(1,E(e,n)),t=Math.ceil(r/f),i=x(e,n),a=i.map(function(e){return _(w(e,t),r)});return a.filter(function(e,n){return!a.some(function(r,t){return n>t&&e[0]===r[0]&&e[1]===r[1]})})},O=function(e,a){function o(e,n,r,t){_[e].forEach(function(e){"undefined"==typeof r||null===r?e(n,null,null):e(n,r,t)})}function u(){_.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var r=x.startAt(e[0]).endAt(e[1]);r.off("child_added",n.childAddedCallback),r.off("child_removed",n.childRemovedCallback),r.off("child_changed",n.childChangedCallback),r.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var r=f(e);l(r,n),delete I[e]}}for(var t in P)if(P.hasOwnProperty(t)&&!d(P[t].geohash)){if(P[t].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete P[t]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var r,a,u=P.hasOwnProperty(e)?P[e].isInQuery:!1,f=P.hasOwnProperty(e)?P[e].location:null;r=t.distance(n,A),a=Q>=r,P[e]={location:n,distanceFromCenter:r,isInQuery:a,geohash:w(n,i)},a&&!u?o("key_entered",e,n,r):!a||null===f||n[0]===f[0]&&n[1]===f[1]?!a&&u&&o("key_exited",e,n,r):o("key_moved",e,n,r)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var r=f(n);if(e>=r[0]&&e<=r[1])return!0}return!1}function v(e,n){var r=P[e];if(delete P[e],"undefined"!=typeof r&&r.isInQuery){var i=n?t.distance(n,A):null;o("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function p(e){h(e.name(),n(e.val()))}function g(e){var r=e.name();P.hasOwnProperty(r)&&x.child(r).once("value",function(e){var t=null===e.val()?null:n(e.val()),i=null!==t?w(t):null;d(i)||v(r,t)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),O=0===E.length,O&&u()}function k(){var e=F(A,1e3*Q).map(c);e=e.filter(function(n,r){return e.indexOf(n)===r});for(var n in I)if(I.hasOwnProperty(n)){var r=e.indexOf(n);-1===r?I[n].active=!1:(I[n].active=!0,e.splice(r,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),r=x.startAt(n[0]).endAt(n[1]),t=r.on("child_added",b),i=r.on("child_removed",g),a=r.on("child_changed",p),o=r.on("value",function(){r.off("value",o),M(e)});I[e]={active:!0,childAddedCallback:t,childRemovedCallback:i,childChangedCallback:a,valueCallback:o}}),0===e.length&&M()}if(this.center=function(){return A},this.radius=function(){return Q},this.updateCriteria=function(e){m(e),A=e.center||A,Q=e.radius||Q;for(var n in P)if(P.hasOwnProperty(n)){var r=P[n],i=r.isInQuery;r.distanceFromCenter=t.distance(r.location,A),r.isInQuery=r.distanceFromCenter<=Q,i&&!r.isInQuery?o("key_exited",n,r.location,r.distanceFromCenter):!i&&r.isInQuery&&o("key_entered",n,r.location,r.distanceFromCenter)}O=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(_[e].push(n),"key_entered"===e)for(var t in P)if(P.hasOwnProperty(t)){var i=P[t];i.isInQuery&&n(t,i.location,i.distanceFromCenter)}return"ready"===e&&O&&n(),new r(function(){_[e].splice(_[e].indexOf(n),1)})},this.cancel=function(){_={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}P={},clearInterval(N)},e instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,_={ready:[],key_entered:[],key_exited:[],key_moved:[]},O=!1,P={},I={},C=!1,q=null,N=setInterval(function(){C===!1&&s()},1e4);m(a,!0);var A=a.center,Q=a.radius;k()};return t}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file +if("undefined"!=typeof module&&"undefined"!=typeof process)var RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var t=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},r=function(t){if(this.ref=function(){return r},this.set=function(n,t){return d(n),null!==t&&y(t),new RSVP.Promise(function(i,o){function a(e){e?o("Error: Firebase synchronization failed: "+e):i()}if(null===t)r.child(n).remove(a);else{var u=p(t);r.child(n).setWithPriority(e(t,u),u,a)}})},this.get=function(e){return d(e),new RSVP.Promise(function(t,i){r.child(e).once("value",function(e){t(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new P(r,e)},"[object Object]"!==Object.prototype.toString.call(t))throw new Error("firebaseRef must be an instance of Firebase");var r=t};r.distance=function(e,n){y(e),y(n);var t=6371,r=b(n[0]-e[0]),i=b(n[1]-e[1]),o=Math.sin(r/2)*Math.sin(r/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),a=2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o));return t*a};var i=10,o="0123456789bcdefghjkmnpqrstuvwxyz",a=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var t=e[0],r=e[1];"number"!=typeof t||isNaN(t)?n="latitude must be a number":-90>t||t>90?n="latitude must be within the range [-90, 90]":"number"!=typeof r||isNaN(r)?n="longitude must be a number":(-180>r||r>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var t=0,r=e.length;r>t;++t)-1===o.indexOf(e[t])&&(n='geohash cannot contain "'+e[t]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var t in e)if(e.hasOwnProperty(t)&&"center"!==t&&"radius"!==t)throw new Error("Unexpected attribute '"+t+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},p=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var t={min:-90,max:90},r={min:-180,max:180},a="",u=0,f=0,c=1;a.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,a+=o[u],u=0)}return a},w=function(e,n){var t=b(n),r=Math.cos(t)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(t)*Math.sin(t)),o=r*i;return h>o?e>0?360:0:Math.min(360,e/o)},g=function(e,n){var t=w(e,n);return Math.abs(t)>1e-6?Math.max(1,Math.log2(360/t)):1},M=function(e){return Math.min(Math.log2(a/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=2*Math.floor(M(n)),a=2*Math.floor(g(n,r))-1,f=2*Math.floor(g(n,i))-1;return Math.min(o,a,f,c)},x=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=w(n,r),a=w(n,i),f=Math.max(o,a);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[r,e[1]],[r,k(e[1]-f)],[r,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},O=function(e,n){v(e);var t=Math.ceil(n/f);if(e.length>u<31?[r+o[c],r+"~"]:[r+o[c],r+o[l]]},_=function(e,n){y(e);var t=Math.max(1,E(e,n)),r=Math.ceil(t/f),i=x(e,n),o=i.map(function(e){return O(p(e,r),t)});return o.filter(function(e,n){return!o.some(function(t,r){return n>r&&e[0]===t[0]&&e[1]===t[1]})})},P=function(e,o){function a(e,n,t,r){O[e].forEach(function(e){"undefined"==typeof t||null===t?e(n,null,null):e(n,t,r)})}function u(){O.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var t=x.startAt(e[0]).endAt(e[1]);t.off("child_added",n.childAddedCallback),t.off("child_removed",n.childRemovedCallback),t.off("child_changed",n.childChangedCallback),t.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var t=f(e);l(t,n),delete I[e]}}for(var r in F)if(F.hasOwnProperty(r)&&!d(F[r].geohash)){if(F[r].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete F[r]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var t,o,u=F.hasOwnProperty(e)?F[e].isInQuery:!1,f=F.hasOwnProperty(e)?F[e].location:null;t=r.distance(n,N),o=A>=t,F[e]={location:n,distanceFromCenter:t,isInQuery:o,geohash:p(n,i)},o&&!u?a("key_entered",e,n,t):!o||null===f||n[0]===f[0]&&n[1]===f[1]?!o&&u&&a("key_exited",e,n,t):a("key_moved",e,n,t)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var t=f(n);if(e>=t[0]&&e<=t[1])return!0}return!1}function v(e,n){var t=F[e];if(delete F[e],"undefined"!=typeof t&&t.isInQuery){var i=n?r.distance(n,N):null;a("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function w(e){h(e.name(),n(e.val()))}function g(e){var t=e.name();F.hasOwnProperty(t)&&x.child(t).once("value",function(e){var r=null===e.val()?null:n(e.val()),i=null!==r?p(r):null;d(i)||v(t,r)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),P=0===E.length,P&&u()}function k(){var e=_(N,1e3*A).map(c);e=e.filter(function(n,t){return e.indexOf(n)===t});for(var n in I)if(I.hasOwnProperty(n)){var t=e.indexOf(n);-1===t?I[n].active=!1:(I[n].active=!0,e.splice(t,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),t=x.startAt(n[0]).endAt(n[1]),r=t.on("child_added",b),i=t.on("child_removed",g),o=t.on("child_changed",w),a=t.on("value",function(){t.off("value",a),M(e)});I[e]={active:!0,childAddedCallback:r,childRemovedCallback:i,childChangedCallback:o,valueCallback:a}}),0===e.length&&M()}if(this.center=function(){return N},this.radius=function(){return A},this.updateCriteria=function(e){m(e),N=e.center||N,A=e.radius||A;for(var n in F)if(F.hasOwnProperty(n)){var t=F[n],i=t.isInQuery;t.distanceFromCenter=r.distance(t.location,N),t.isInQuery=t.distanceFromCenter<=A,i&&!t.isInQuery?a("key_exited",n,t.location,t.distanceFromCenter):!i&&t.isInQuery&&a("key_entered",n,t.location,t.distanceFromCenter)}P=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(O[e].push(n),"key_entered"===e)for(var r in F)if(F.hasOwnProperty(r)){var i=F[r];i.isInQuery&&n(r,i.location,i.distanceFromCenter)}return"ready"===e&&P&&n(),new t(function(){O[e].splice(O[e].indexOf(n),1)})},this.cancel=function(){O={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}F={},clearInterval(j)},"[object Object]"!==Object.prototype.toString.call(e))throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,O={ready:[],key_entered:[],key_exited:[],key_moved:[]},P=!1,F={},I={},C=!1,q=null,j=setInterval(function(){C===!1&&s()},1e4);m(o,!0);var N=o.center,A=o.radius;k()};return r}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file diff --git a/examples/html5Geolocation/js/vendor/geofire.min.js b/examples/html5Geolocation/js/vendor/geofire.min.js index 8d5bd298..62ac1195 100755 --- a/examples/html5Geolocation/js/vendor/geofire.min.js +++ b/examples/html5Geolocation/js/vendor/geofire.min.js @@ -9,4 +9,4 @@ * https://github.com/firebase/geofire-js/ * License: MIT */ -if("undefined"!=typeof module&&"undefined"!=typeof process)var Firebase=require("firebase"),RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var r=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},t=function(r){if(this.ref=function(){return t},this.set=function(n,r){return d(n),null!==r&&y(r),new RSVP.Promise(function(i,a){function o(e){e?a("Error: Firebase synchronization failed: "+e):i()}if(null===r)t.child(n).remove(o);else{var u=w(r);t.child(n).setWithPriority(e(r,u),u,o)}})},this.get=function(e){return d(e),new RSVP.Promise(function(r,i){t.child(e).once("value",function(e){r(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new O(t,e)},r instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var t=r};t.distance=function(e,n){y(e),y(n);var r=6371,t=b(n[0]-e[0]),i=b(n[1]-e[1]),a=Math.sin(t/2)*Math.sin(t/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),o=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return r*o};var i=10,a="0123456789bcdefghjkmnpqrstuvwxyz",o=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var r=e[0],t=e[1];"number"!=typeof r||isNaN(r)?n="latitude must be a number":-90>r||r>90?n="latitude must be within the range [-90, 90]":"number"!=typeof t||isNaN(t)?n="longitude must be a number":(-180>t||t>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var r=0,t=e.length;t>r;++r)-1===a.indexOf(e[r])&&(n='geohash cannot contain "'+e[r]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var r in e)if(e.hasOwnProperty(r)&&"center"!==r&&"radius"!==r)throw new Error("Unexpected attribute '"+r+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},w=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var r={min:-90,max:90},t={min:-180,max:180},o="",u=0,f=0,c=1;o.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,o+=a[u],u=0)}return o},p=function(e,n){var r=b(n),t=Math.cos(r)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(r)*Math.sin(r)),a=t*i;return h>a?e>0?360:0:Math.min(360,e/a)},g=function(e,n){var r=p(e,n);return Math.abs(r)>1e-6?Math.max(1,Math.log2(360/r)):1},M=function(e){return Math.min(Math.log2(o/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=2*Math.floor(M(n)),o=2*Math.floor(g(n,t))-1,f=2*Math.floor(g(n,i))-1;return Math.min(a,o,f,c)},x=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=p(n,t),o=p(n,i),f=Math.max(a,o);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[t,e[1]],[t,k(e[1]-f)],[t,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},_=function(e,n){v(e);var r=Math.ceil(n/f);if(e.length>u<31?[t+a[c],t+"~"]:[t+a[c],t+a[l]]},F=function(e,n){y(e);var r=Math.max(1,E(e,n)),t=Math.ceil(r/f),i=x(e,n),a=i.map(function(e){return _(w(e,t),r)});return a.filter(function(e,n){return!a.some(function(r,t){return n>t&&e[0]===r[0]&&e[1]===r[1]})})},O=function(e,a){function o(e,n,r,t){_[e].forEach(function(e){"undefined"==typeof r||null===r?e(n,null,null):e(n,r,t)})}function u(){_.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var r=x.startAt(e[0]).endAt(e[1]);r.off("child_added",n.childAddedCallback),r.off("child_removed",n.childRemovedCallback),r.off("child_changed",n.childChangedCallback),r.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var r=f(e);l(r,n),delete I[e]}}for(var t in P)if(P.hasOwnProperty(t)&&!d(P[t].geohash)){if(P[t].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete P[t]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var r,a,u=P.hasOwnProperty(e)?P[e].isInQuery:!1,f=P.hasOwnProperty(e)?P[e].location:null;r=t.distance(n,A),a=Q>=r,P[e]={location:n,distanceFromCenter:r,isInQuery:a,geohash:w(n,i)},a&&!u?o("key_entered",e,n,r):!a||null===f||n[0]===f[0]&&n[1]===f[1]?!a&&u&&o("key_exited",e,n,r):o("key_moved",e,n,r)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var r=f(n);if(e>=r[0]&&e<=r[1])return!0}return!1}function v(e,n){var r=P[e];if(delete P[e],"undefined"!=typeof r&&r.isInQuery){var i=n?t.distance(n,A):null;o("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function p(e){h(e.name(),n(e.val()))}function g(e){var r=e.name();P.hasOwnProperty(r)&&x.child(r).once("value",function(e){var t=null===e.val()?null:n(e.val()),i=null!==t?w(t):null;d(i)||v(r,t)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),O=0===E.length,O&&u()}function k(){var e=F(A,1e3*Q).map(c);e=e.filter(function(n,r){return e.indexOf(n)===r});for(var n in I)if(I.hasOwnProperty(n)){var r=e.indexOf(n);-1===r?I[n].active=!1:(I[n].active=!0,e.splice(r,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),r=x.startAt(n[0]).endAt(n[1]),t=r.on("child_added",b),i=r.on("child_removed",g),a=r.on("child_changed",p),o=r.on("value",function(){r.off("value",o),M(e)});I[e]={active:!0,childAddedCallback:t,childRemovedCallback:i,childChangedCallback:a,valueCallback:o}}),0===e.length&&M()}if(this.center=function(){return A},this.radius=function(){return Q},this.updateCriteria=function(e){m(e),A=e.center||A,Q=e.radius||Q;for(var n in P)if(P.hasOwnProperty(n)){var r=P[n],i=r.isInQuery;r.distanceFromCenter=t.distance(r.location,A),r.isInQuery=r.distanceFromCenter<=Q,i&&!r.isInQuery?o("key_exited",n,r.location,r.distanceFromCenter):!i&&r.isInQuery&&o("key_entered",n,r.location,r.distanceFromCenter)}O=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(_[e].push(n),"key_entered"===e)for(var t in P)if(P.hasOwnProperty(t)){var i=P[t];i.isInQuery&&n(t,i.location,i.distanceFromCenter)}return"ready"===e&&O&&n(),new r(function(){_[e].splice(_[e].indexOf(n),1)})},this.cancel=function(){_={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}P={},clearInterval(N)},e instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,_={ready:[],key_entered:[],key_exited:[],key_moved:[]},O=!1,P={},I={},C=!1,q=null,N=setInterval(function(){C===!1&&s()},1e4);m(a,!0);var A=a.center,Q=a.radius;k()};return t}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file +if("undefined"!=typeof module&&"undefined"!=typeof process)var RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var t=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},r=function(t){if(this.ref=function(){return r},this.set=function(n,t){return d(n),null!==t&&y(t),new RSVP.Promise(function(i,o){function a(e){e?o("Error: Firebase synchronization failed: "+e):i()}if(null===t)r.child(n).remove(a);else{var u=p(t);r.child(n).setWithPriority(e(t,u),u,a)}})},this.get=function(e){return d(e),new RSVP.Promise(function(t,i){r.child(e).once("value",function(e){t(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new P(r,e)},"[object Object]"!==Object.prototype.toString.call(t))throw new Error("firebaseRef must be an instance of Firebase");var r=t};r.distance=function(e,n){y(e),y(n);var t=6371,r=b(n[0]-e[0]),i=b(n[1]-e[1]),o=Math.sin(r/2)*Math.sin(r/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),a=2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o));return t*a};var i=10,o="0123456789bcdefghjkmnpqrstuvwxyz",a=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var t=e[0],r=e[1];"number"!=typeof t||isNaN(t)?n="latitude must be a number":-90>t||t>90?n="latitude must be within the range [-90, 90]":"number"!=typeof r||isNaN(r)?n="longitude must be a number":(-180>r||r>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var t=0,r=e.length;r>t;++t)-1===o.indexOf(e[t])&&(n='geohash cannot contain "'+e[t]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var t in e)if(e.hasOwnProperty(t)&&"center"!==t&&"radius"!==t)throw new Error("Unexpected attribute '"+t+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},p=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var t={min:-90,max:90},r={min:-180,max:180},a="",u=0,f=0,c=1;a.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,a+=o[u],u=0)}return a},w=function(e,n){var t=b(n),r=Math.cos(t)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(t)*Math.sin(t)),o=r*i;return h>o?e>0?360:0:Math.min(360,e/o)},g=function(e,n){var t=w(e,n);return Math.abs(t)>1e-6?Math.max(1,Math.log2(360/t)):1},M=function(e){return Math.min(Math.log2(a/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=2*Math.floor(M(n)),a=2*Math.floor(g(n,r))-1,f=2*Math.floor(g(n,i))-1;return Math.min(o,a,f,c)},x=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=w(n,r),a=w(n,i),f=Math.max(o,a);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[r,e[1]],[r,k(e[1]-f)],[r,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},O=function(e,n){v(e);var t=Math.ceil(n/f);if(e.length>u<31?[r+o[c],r+"~"]:[r+o[c],r+o[l]]},_=function(e,n){y(e);var t=Math.max(1,E(e,n)),r=Math.ceil(t/f),i=x(e,n),o=i.map(function(e){return O(p(e,r),t)});return o.filter(function(e,n){return!o.some(function(t,r){return n>r&&e[0]===t[0]&&e[1]===t[1]})})},P=function(e,o){function a(e,n,t,r){O[e].forEach(function(e){"undefined"==typeof t||null===t?e(n,null,null):e(n,t,r)})}function u(){O.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var t=x.startAt(e[0]).endAt(e[1]);t.off("child_added",n.childAddedCallback),t.off("child_removed",n.childRemovedCallback),t.off("child_changed",n.childChangedCallback),t.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var t=f(e);l(t,n),delete I[e]}}for(var r in F)if(F.hasOwnProperty(r)&&!d(F[r].geohash)){if(F[r].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete F[r]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var t,o,u=F.hasOwnProperty(e)?F[e].isInQuery:!1,f=F.hasOwnProperty(e)?F[e].location:null;t=r.distance(n,N),o=A>=t,F[e]={location:n,distanceFromCenter:t,isInQuery:o,geohash:p(n,i)},o&&!u?a("key_entered",e,n,t):!o||null===f||n[0]===f[0]&&n[1]===f[1]?!o&&u&&a("key_exited",e,n,t):a("key_moved",e,n,t)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var t=f(n);if(e>=t[0]&&e<=t[1])return!0}return!1}function v(e,n){var t=F[e];if(delete F[e],"undefined"!=typeof t&&t.isInQuery){var i=n?r.distance(n,N):null;a("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function w(e){h(e.name(),n(e.val()))}function g(e){var t=e.name();F.hasOwnProperty(t)&&x.child(t).once("value",function(e){var r=null===e.val()?null:n(e.val()),i=null!==r?p(r):null;d(i)||v(t,r)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),P=0===E.length,P&&u()}function k(){var e=_(N,1e3*A).map(c);e=e.filter(function(n,t){return e.indexOf(n)===t});for(var n in I)if(I.hasOwnProperty(n)){var t=e.indexOf(n);-1===t?I[n].active=!1:(I[n].active=!0,e.splice(t,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),t=x.startAt(n[0]).endAt(n[1]),r=t.on("child_added",b),i=t.on("child_removed",g),o=t.on("child_changed",w),a=t.on("value",function(){t.off("value",a),M(e)});I[e]={active:!0,childAddedCallback:r,childRemovedCallback:i,childChangedCallback:o,valueCallback:a}}),0===e.length&&M()}if(this.center=function(){return N},this.radius=function(){return A},this.updateCriteria=function(e){m(e),N=e.center||N,A=e.radius||A;for(var n in F)if(F.hasOwnProperty(n)){var t=F[n],i=t.isInQuery;t.distanceFromCenter=r.distance(t.location,N),t.isInQuery=t.distanceFromCenter<=A,i&&!t.isInQuery?a("key_exited",n,t.location,t.distanceFromCenter):!i&&t.isInQuery&&a("key_entered",n,t.location,t.distanceFromCenter)}P=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(O[e].push(n),"key_entered"===e)for(var r in F)if(F.hasOwnProperty(r)){var i=F[r];i.isInQuery&&n(r,i.location,i.distanceFromCenter)}return"ready"===e&&P&&n(),new t(function(){O[e].splice(O[e].indexOf(n),1)})},this.cancel=function(){O={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}F={},clearInterval(j)},"[object Object]"!==Object.prototype.toString.call(e))throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,O={ready:[],key_entered:[],key_exited:[],key_moved:[]},P=!1,F={},I={},C=!1,q=null,j=setInterval(function(){C===!1&&s()},1e4);m(o,!0);var N=o.center,A=o.radius;k()};return r}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file diff --git a/examples/queryBuilder/js/vendor/geofire.min.js b/examples/queryBuilder/js/vendor/geofire.min.js index 8d5bd298..62ac1195 100644 --- a/examples/queryBuilder/js/vendor/geofire.min.js +++ b/examples/queryBuilder/js/vendor/geofire.min.js @@ -9,4 +9,4 @@ * https://github.com/firebase/geofire-js/ * License: MIT */ -if("undefined"!=typeof module&&"undefined"!=typeof process)var Firebase=require("firebase"),RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var r=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},t=function(r){if(this.ref=function(){return t},this.set=function(n,r){return d(n),null!==r&&y(r),new RSVP.Promise(function(i,a){function o(e){e?a("Error: Firebase synchronization failed: "+e):i()}if(null===r)t.child(n).remove(o);else{var u=w(r);t.child(n).setWithPriority(e(r,u),u,o)}})},this.get=function(e){return d(e),new RSVP.Promise(function(r,i){t.child(e).once("value",function(e){r(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new O(t,e)},r instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var t=r};t.distance=function(e,n){y(e),y(n);var r=6371,t=b(n[0]-e[0]),i=b(n[1]-e[1]),a=Math.sin(t/2)*Math.sin(t/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),o=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return r*o};var i=10,a="0123456789bcdefghjkmnpqrstuvwxyz",o=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var r=e[0],t=e[1];"number"!=typeof r||isNaN(r)?n="latitude must be a number":-90>r||r>90?n="latitude must be within the range [-90, 90]":"number"!=typeof t||isNaN(t)?n="longitude must be a number":(-180>t||t>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var r=0,t=e.length;t>r;++r)-1===a.indexOf(e[r])&&(n='geohash cannot contain "'+e[r]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var r in e)if(e.hasOwnProperty(r)&&"center"!==r&&"radius"!==r)throw new Error("Unexpected attribute '"+r+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},w=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var r={min:-90,max:90},t={min:-180,max:180},o="",u=0,f=0,c=1;o.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,o+=a[u],u=0)}return o},p=function(e,n){var r=b(n),t=Math.cos(r)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(r)*Math.sin(r)),a=t*i;return h>a?e>0?360:0:Math.min(360,e/a)},g=function(e,n){var r=p(e,n);return Math.abs(r)>1e-6?Math.max(1,Math.log2(360/r)):1},M=function(e){return Math.min(Math.log2(o/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=2*Math.floor(M(n)),o=2*Math.floor(g(n,t))-1,f=2*Math.floor(g(n,i))-1;return Math.min(a,o,f,c)},x=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=p(n,t),o=p(n,i),f=Math.max(a,o);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[t,e[1]],[t,k(e[1]-f)],[t,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},_=function(e,n){v(e);var r=Math.ceil(n/f);if(e.length>u<31?[t+a[c],t+"~"]:[t+a[c],t+a[l]]},F=function(e,n){y(e);var r=Math.max(1,E(e,n)),t=Math.ceil(r/f),i=x(e,n),a=i.map(function(e){return _(w(e,t),r)});return a.filter(function(e,n){return!a.some(function(r,t){return n>t&&e[0]===r[0]&&e[1]===r[1]})})},O=function(e,a){function o(e,n,r,t){_[e].forEach(function(e){"undefined"==typeof r||null===r?e(n,null,null):e(n,r,t)})}function u(){_.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var r=x.startAt(e[0]).endAt(e[1]);r.off("child_added",n.childAddedCallback),r.off("child_removed",n.childRemovedCallback),r.off("child_changed",n.childChangedCallback),r.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var r=f(e);l(r,n),delete I[e]}}for(var t in P)if(P.hasOwnProperty(t)&&!d(P[t].geohash)){if(P[t].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete P[t]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var r,a,u=P.hasOwnProperty(e)?P[e].isInQuery:!1,f=P.hasOwnProperty(e)?P[e].location:null;r=t.distance(n,A),a=Q>=r,P[e]={location:n,distanceFromCenter:r,isInQuery:a,geohash:w(n,i)},a&&!u?o("key_entered",e,n,r):!a||null===f||n[0]===f[0]&&n[1]===f[1]?!a&&u&&o("key_exited",e,n,r):o("key_moved",e,n,r)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var r=f(n);if(e>=r[0]&&e<=r[1])return!0}return!1}function v(e,n){var r=P[e];if(delete P[e],"undefined"!=typeof r&&r.isInQuery){var i=n?t.distance(n,A):null;o("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function p(e){h(e.name(),n(e.val()))}function g(e){var r=e.name();P.hasOwnProperty(r)&&x.child(r).once("value",function(e){var t=null===e.val()?null:n(e.val()),i=null!==t?w(t):null;d(i)||v(r,t)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),O=0===E.length,O&&u()}function k(){var e=F(A,1e3*Q).map(c);e=e.filter(function(n,r){return e.indexOf(n)===r});for(var n in I)if(I.hasOwnProperty(n)){var r=e.indexOf(n);-1===r?I[n].active=!1:(I[n].active=!0,e.splice(r,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),r=x.startAt(n[0]).endAt(n[1]),t=r.on("child_added",b),i=r.on("child_removed",g),a=r.on("child_changed",p),o=r.on("value",function(){r.off("value",o),M(e)});I[e]={active:!0,childAddedCallback:t,childRemovedCallback:i,childChangedCallback:a,valueCallback:o}}),0===e.length&&M()}if(this.center=function(){return A},this.radius=function(){return Q},this.updateCriteria=function(e){m(e),A=e.center||A,Q=e.radius||Q;for(var n in P)if(P.hasOwnProperty(n)){var r=P[n],i=r.isInQuery;r.distanceFromCenter=t.distance(r.location,A),r.isInQuery=r.distanceFromCenter<=Q,i&&!r.isInQuery?o("key_exited",n,r.location,r.distanceFromCenter):!i&&r.isInQuery&&o("key_entered",n,r.location,r.distanceFromCenter)}O=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(_[e].push(n),"key_entered"===e)for(var t in P)if(P.hasOwnProperty(t)){var i=P[t];i.isInQuery&&n(t,i.location,i.distanceFromCenter)}return"ready"===e&&O&&n(),new r(function(){_[e].splice(_[e].indexOf(n),1)})},this.cancel=function(){_={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}P={},clearInterval(N)},e instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,_={ready:[],key_entered:[],key_exited:[],key_moved:[]},O=!1,P={},I={},C=!1,q=null,N=setInterval(function(){C===!1&&s()},1e4);m(a,!0);var A=a.center,Q=a.radius;k()};return t}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file +if("undefined"!=typeof module&&"undefined"!=typeof process)var RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var t=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},r=function(t){if(this.ref=function(){return r},this.set=function(n,t){return d(n),null!==t&&y(t),new RSVP.Promise(function(i,o){function a(e){e?o("Error: Firebase synchronization failed: "+e):i()}if(null===t)r.child(n).remove(a);else{var u=p(t);r.child(n).setWithPriority(e(t,u),u,a)}})},this.get=function(e){return d(e),new RSVP.Promise(function(t,i){r.child(e).once("value",function(e){t(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new P(r,e)},"[object Object]"!==Object.prototype.toString.call(t))throw new Error("firebaseRef must be an instance of Firebase");var r=t};r.distance=function(e,n){y(e),y(n);var t=6371,r=b(n[0]-e[0]),i=b(n[1]-e[1]),o=Math.sin(r/2)*Math.sin(r/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),a=2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o));return t*a};var i=10,o="0123456789bcdefghjkmnpqrstuvwxyz",a=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var t=e[0],r=e[1];"number"!=typeof t||isNaN(t)?n="latitude must be a number":-90>t||t>90?n="latitude must be within the range [-90, 90]":"number"!=typeof r||isNaN(r)?n="longitude must be a number":(-180>r||r>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var t=0,r=e.length;r>t;++t)-1===o.indexOf(e[t])&&(n='geohash cannot contain "'+e[t]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var t in e)if(e.hasOwnProperty(t)&&"center"!==t&&"radius"!==t)throw new Error("Unexpected attribute '"+t+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},p=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var t={min:-90,max:90},r={min:-180,max:180},a="",u=0,f=0,c=1;a.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,a+=o[u],u=0)}return a},w=function(e,n){var t=b(n),r=Math.cos(t)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(t)*Math.sin(t)),o=r*i;return h>o?e>0?360:0:Math.min(360,e/o)},g=function(e,n){var t=w(e,n);return Math.abs(t)>1e-6?Math.max(1,Math.log2(360/t)):1},M=function(e){return Math.min(Math.log2(a/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=2*Math.floor(M(n)),a=2*Math.floor(g(n,r))-1,f=2*Math.floor(g(n,i))-1;return Math.min(o,a,f,c)},x=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=w(n,r),a=w(n,i),f=Math.max(o,a);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[r,e[1]],[r,k(e[1]-f)],[r,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},O=function(e,n){v(e);var t=Math.ceil(n/f);if(e.length>u<31?[r+o[c],r+"~"]:[r+o[c],r+o[l]]},_=function(e,n){y(e);var t=Math.max(1,E(e,n)),r=Math.ceil(t/f),i=x(e,n),o=i.map(function(e){return O(p(e,r),t)});return o.filter(function(e,n){return!o.some(function(t,r){return n>r&&e[0]===t[0]&&e[1]===t[1]})})},P=function(e,o){function a(e,n,t,r){O[e].forEach(function(e){"undefined"==typeof t||null===t?e(n,null,null):e(n,t,r)})}function u(){O.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var t=x.startAt(e[0]).endAt(e[1]);t.off("child_added",n.childAddedCallback),t.off("child_removed",n.childRemovedCallback),t.off("child_changed",n.childChangedCallback),t.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var t=f(e);l(t,n),delete I[e]}}for(var r in F)if(F.hasOwnProperty(r)&&!d(F[r].geohash)){if(F[r].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete F[r]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var t,o,u=F.hasOwnProperty(e)?F[e].isInQuery:!1,f=F.hasOwnProperty(e)?F[e].location:null;t=r.distance(n,N),o=A>=t,F[e]={location:n,distanceFromCenter:t,isInQuery:o,geohash:p(n,i)},o&&!u?a("key_entered",e,n,t):!o||null===f||n[0]===f[0]&&n[1]===f[1]?!o&&u&&a("key_exited",e,n,t):a("key_moved",e,n,t)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var t=f(n);if(e>=t[0]&&e<=t[1])return!0}return!1}function v(e,n){var t=F[e];if(delete F[e],"undefined"!=typeof t&&t.isInQuery){var i=n?r.distance(n,N):null;a("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function w(e){h(e.name(),n(e.val()))}function g(e){var t=e.name();F.hasOwnProperty(t)&&x.child(t).once("value",function(e){var r=null===e.val()?null:n(e.val()),i=null!==r?p(r):null;d(i)||v(t,r)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),P=0===E.length,P&&u()}function k(){var e=_(N,1e3*A).map(c);e=e.filter(function(n,t){return e.indexOf(n)===t});for(var n in I)if(I.hasOwnProperty(n)){var t=e.indexOf(n);-1===t?I[n].active=!1:(I[n].active=!0,e.splice(t,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),t=x.startAt(n[0]).endAt(n[1]),r=t.on("child_added",b),i=t.on("child_removed",g),o=t.on("child_changed",w),a=t.on("value",function(){t.off("value",a),M(e)});I[e]={active:!0,childAddedCallback:r,childRemovedCallback:i,childChangedCallback:o,valueCallback:a}}),0===e.length&&M()}if(this.center=function(){return N},this.radius=function(){return A},this.updateCriteria=function(e){m(e),N=e.center||N,A=e.radius||A;for(var n in F)if(F.hasOwnProperty(n)){var t=F[n],i=t.isInQuery;t.distanceFromCenter=r.distance(t.location,N),t.isInQuery=t.distanceFromCenter<=A,i&&!t.isInQuery?a("key_exited",n,t.location,t.distanceFromCenter):!i&&t.isInQuery&&a("key_entered",n,t.location,t.distanceFromCenter)}P=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(O[e].push(n),"key_entered"===e)for(var r in F)if(F.hasOwnProperty(r)){var i=F[r];i.isInQuery&&n(r,i.location,i.distanceFromCenter)}return"ready"===e&&P&&n(),new t(function(){O[e].splice(O[e].indexOf(n),1)})},this.cancel=function(){O={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}F={},clearInterval(j)},"[object Object]"!==Object.prototype.toString.call(e))throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,O={ready:[],key_entered:[],key_exited:[],key_moved:[]},P=!1,F={},I={},C=!1,q=null,j=setInterval(function(){C===!1&&s()},1e4);m(o,!0);var N=o.center,A=o.radius;k()};return r}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file diff --git a/examples/sfVehicles/js/vendor/geofire.min.js b/examples/sfVehicles/js/vendor/geofire.min.js index 8d5bd298..62ac1195 100644 --- a/examples/sfVehicles/js/vendor/geofire.min.js +++ b/examples/sfVehicles/js/vendor/geofire.min.js @@ -9,4 +9,4 @@ * https://github.com/firebase/geofire-js/ * License: MIT */ -if("undefined"!=typeof module&&"undefined"!=typeof process)var Firebase=require("firebase"),RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var r=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},t=function(r){if(this.ref=function(){return t},this.set=function(n,r){return d(n),null!==r&&y(r),new RSVP.Promise(function(i,a){function o(e){e?a("Error: Firebase synchronization failed: "+e):i()}if(null===r)t.child(n).remove(o);else{var u=w(r);t.child(n).setWithPriority(e(r,u),u,o)}})},this.get=function(e){return d(e),new RSVP.Promise(function(r,i){t.child(e).once("value",function(e){r(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new O(t,e)},r instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var t=r};t.distance=function(e,n){y(e),y(n);var r=6371,t=b(n[0]-e[0]),i=b(n[1]-e[1]),a=Math.sin(t/2)*Math.sin(t/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),o=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return r*o};var i=10,a="0123456789bcdefghjkmnpqrstuvwxyz",o=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var r=e[0],t=e[1];"number"!=typeof r||isNaN(r)?n="latitude must be a number":-90>r||r>90?n="latitude must be within the range [-90, 90]":"number"!=typeof t||isNaN(t)?n="longitude must be a number":(-180>t||t>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var r=0,t=e.length;t>r;++r)-1===a.indexOf(e[r])&&(n='geohash cannot contain "'+e[r]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var r in e)if(e.hasOwnProperty(r)&&"center"!==r&&"radius"!==r)throw new Error("Unexpected attribute '"+r+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},w=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var r={min:-90,max:90},t={min:-180,max:180},o="",u=0,f=0,c=1;o.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,o+=a[u],u=0)}return o},p=function(e,n){var r=b(n),t=Math.cos(r)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(r)*Math.sin(r)),a=t*i;return h>a?e>0?360:0:Math.min(360,e/a)},g=function(e,n){var r=p(e,n);return Math.abs(r)>1e-6?Math.max(1,Math.log2(360/r)):1},M=function(e){return Math.min(Math.log2(o/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=2*Math.floor(M(n)),o=2*Math.floor(g(n,t))-1,f=2*Math.floor(g(n,i))-1;return Math.min(a,o,f,c)},x=function(e,n){var r=n/u,t=Math.min(90,e[0]+r),i=Math.max(-90,e[0]-r),a=p(n,t),o=p(n,i),f=Math.max(a,o);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[t,e[1]],[t,k(e[1]-f)],[t,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},_=function(e,n){v(e);var r=Math.ceil(n/f);if(e.length>u<31?[t+a[c],t+"~"]:[t+a[c],t+a[l]]},F=function(e,n){y(e);var r=Math.max(1,E(e,n)),t=Math.ceil(r/f),i=x(e,n),a=i.map(function(e){return _(w(e,t),r)});return a.filter(function(e,n){return!a.some(function(r,t){return n>t&&e[0]===r[0]&&e[1]===r[1]})})},O=function(e,a){function o(e,n,r,t){_[e].forEach(function(e){"undefined"==typeof r||null===r?e(n,null,null):e(n,r,t)})}function u(){_.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var r=x.startAt(e[0]).endAt(e[1]);r.off("child_added",n.childAddedCallback),r.off("child_removed",n.childRemovedCallback),r.off("child_changed",n.childChangedCallback),r.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var r=f(e);l(r,n),delete I[e]}}for(var t in P)if(P.hasOwnProperty(t)&&!d(P[t].geohash)){if(P[t].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete P[t]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var r,a,u=P.hasOwnProperty(e)?P[e].isInQuery:!1,f=P.hasOwnProperty(e)?P[e].location:null;r=t.distance(n,A),a=Q>=r,P[e]={location:n,distanceFromCenter:r,isInQuery:a,geohash:w(n,i)},a&&!u?o("key_entered",e,n,r):!a||null===f||n[0]===f[0]&&n[1]===f[1]?!a&&u&&o("key_exited",e,n,r):o("key_moved",e,n,r)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var r=f(n);if(e>=r[0]&&e<=r[1])return!0}return!1}function v(e,n){var r=P[e];if(delete P[e],"undefined"!=typeof r&&r.isInQuery){var i=n?t.distance(n,A):null;o("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function p(e){h(e.name(),n(e.val()))}function g(e){var r=e.name();P.hasOwnProperty(r)&&x.child(r).once("value",function(e){var t=null===e.val()?null:n(e.val()),i=null!==t?w(t):null;d(i)||v(r,t)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),O=0===E.length,O&&u()}function k(){var e=F(A,1e3*Q).map(c);e=e.filter(function(n,r){return e.indexOf(n)===r});for(var n in I)if(I.hasOwnProperty(n)){var r=e.indexOf(n);-1===r?I[n].active=!1:(I[n].active=!0,e.splice(r,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),r=x.startAt(n[0]).endAt(n[1]),t=r.on("child_added",b),i=r.on("child_removed",g),a=r.on("child_changed",p),o=r.on("value",function(){r.off("value",o),M(e)});I[e]={active:!0,childAddedCallback:t,childRemovedCallback:i,childChangedCallback:a,valueCallback:o}}),0===e.length&&M()}if(this.center=function(){return A},this.radius=function(){return Q},this.updateCriteria=function(e){m(e),A=e.center||A,Q=e.radius||Q;for(var n in P)if(P.hasOwnProperty(n)){var r=P[n],i=r.isInQuery;r.distanceFromCenter=t.distance(r.location,A),r.isInQuery=r.distanceFromCenter<=Q,i&&!r.isInQuery?o("key_exited",n,r.location,r.distanceFromCenter):!i&&r.isInQuery&&o("key_entered",n,r.location,r.distanceFromCenter)}O=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(_[e].push(n),"key_entered"===e)for(var t in P)if(P.hasOwnProperty(t)){var i=P[t];i.isInQuery&&n(t,i.location,i.distanceFromCenter)}return"ready"===e&&O&&n(),new r(function(){_[e].splice(_[e].indexOf(n),1)})},this.cancel=function(){_={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}P={},clearInterval(N)},e instanceof Firebase==!1)throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,_={ready:[],key_entered:[],key_exited:[],key_moved:[]},O=!1,P={},I={},C=!1,q=null,N=setInterval(function(){C===!1&&s()},1e4);m(a,!0);var A=a.center,Q=a.radius;k()};return t}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file +if("undefined"!=typeof module&&"undefined"!=typeof process)var RSVP=require("rsvp");var GeoFire=function(){"use strict";function e(e,n){return y(e),v(n),{g:n,l:e}}function n(e){if(null!==e&&e.hasOwnProperty("l")&&Array.isArray(e.l)&&2===e.l.length)return e.l;throw new Error("Unexpected GeoFire location object encountered: "+JSON.stringify(e))}var t=function(e){if(this.cancel=function(){"undefined"!=typeof n&&(n(),n=void 0)},"function"!=typeof e)throw new Error("callback must be a function");var n=e},r=function(t){if(this.ref=function(){return r},this.set=function(n,t){return d(n),null!==t&&y(t),new RSVP.Promise(function(i,o){function a(e){e?o("Error: Firebase synchronization failed: "+e):i()}if(null===t)r.child(n).remove(a);else{var u=p(t);r.child(n).setWithPriority(e(t,u),u,a)}})},this.get=function(e){return d(e),new RSVP.Promise(function(t,i){r.child(e).once("value",function(e){t(null===e.val()?null:n(e.val()))},function(e){i("Error: Firebase synchronization failed: "+e)})})},this.remove=function(e){return this.set(e,null)},this.query=function(e){return new P(r,e)},"[object Object]"!==Object.prototype.toString.call(t))throw new Error("firebaseRef must be an instance of Firebase");var r=t};r.distance=function(e,n){y(e),y(n);var t=6371,r=b(n[0]-e[0]),i=b(n[1]-e[1]),o=Math.sin(r/2)*Math.sin(r/2)+Math.cos(b(e[0]))*Math.cos(b(n[0]))*Math.sin(i/2)*Math.sin(i/2),a=2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o));return t*a};var i=10,o="0123456789bcdefghjkmnpqrstuvwxyz",a=40007860,u=110574,f=5,c=22*f,l=6378137,s=.00669447819799,h=1e-12;Math.log2=Math.log2||function(e){return Math.log(e)/Math.log(2)};var d=function(e){var n;if("string"!=typeof e?n="key must be a string":0===e.length?n="key cannot be the empty string":1+i+e.length>755?n="key is too long to be stored in Firebase":/[\[\].#$\/\u0000-\u001F\u007F]/.test(e)&&(n="key cannot contain any of the following characters: . # $ ] [ /"),"undefined"!=typeof n)throw new Error("Invalid GeoFire key '"+e+"': "+n)},y=function(e){var n;if("[object Array]"!==Object.prototype.toString.call(e))n="location must be an array";else if(2!==e.length)n="expected array of length 2, got length "+e.length;else{var t=e[0],r=e[1];"number"!=typeof t||isNaN(t)?n="latitude must be a number":-90>t||t>90?n="latitude must be within the range [-90, 90]":"number"!=typeof r||isNaN(r)?n="longitude must be a number":(-180>r||r>180)&&(n="longitude must be within the range [-180, 180]")}if("undefined"!=typeof n)throw new Error("Invalid GeoFire location '"+e+"': "+n)},v=function(e){var n;if("string"!=typeof e)n="geohash must be a string";else if(0===e.length)n="geohash cannot be the empty string";else for(var t=0,r=e.length;r>t;++t)-1===o.indexOf(e[t])&&(n='geohash cannot contain "'+e[t]+'"');if("undefined"!=typeof n)throw new Error("Invalid GeoFire geohash '"+e+"': "+n)},m=function(e,n){if("object"!=typeof e)throw new Error("query criteria must be an object");if("undefined"==typeof e.center&&"undefined"==typeof e.radius)throw new Error("radius and/or center must be specified");if(n&&("undefined"==typeof e.center||"undefined"==typeof e.radius))throw new Error("query criteria for a new query must contain both a center and a radius");for(var t in e)if(e.hasOwnProperty(t)&&"center"!==t&&"radius"!==t)throw new Error("Unexpected attribute '"+t+"'' found in query criteria");if("undefined"!=typeof e.center&&y(e.center),"undefined"!=typeof e.radius){if("number"!=typeof e.radius||isNaN(e.radius))throw new Error("radius must be a number");if(e.radius<0)throw new Error("radius must be greater than or equal to 0")}},b=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Error: degrees must be a number");return e*Math.PI/180},p=function(e,n){if(y(e),"undefined"!=typeof n){if("number"!=typeof n||isNaN(n))throw new Error("precision must be a number");if(0>=n)throw new Error("precision must be greater than 0");if(n>22)throw new Error("precision cannot be greater than 22");if(Math.round(n)!==n)throw new Error("precision must be an integer")}n=n||i;for(var t={min:-90,max:90},r={min:-180,max:180},a="",u=0,f=0,c=1;a.lengthh?(u=(u<<1)+1,s.min=h):(u=(u<<1)+0,s.max=h),c=!c,4>f?f++:(f=0,a+=o[u],u=0)}return a},w=function(e,n){var t=b(n),r=Math.cos(t)*l*Math.PI/180,i=1/Math.sqrt(1-s*Math.sin(t)*Math.sin(t)),o=r*i;return h>o?e>0?360:0:Math.min(360,e/o)},g=function(e,n){var t=w(e,n);return Math.abs(t)>1e-6?Math.max(1,Math.log2(360/t)):1},M=function(e){return Math.min(Math.log2(a/2/e),c)},k=function(e){if(180>=e&&e>=-180)return e;var n=e+180;return n>0?n%360-180:180- -n%360},E=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=2*Math.floor(M(n)),a=2*Math.floor(g(n,r))-1,f=2*Math.floor(g(n,i))-1;return Math.min(o,a,f,c)},x=function(e,n){var t=n/u,r=Math.min(90,e[0]+t),i=Math.max(-90,e[0]-t),o=w(n,r),a=w(n,i),f=Math.max(o,a);return[[e[0],e[1]],[e[0],k(e[1]-f)],[e[0],k(e[1]+f)],[r,e[1]],[r,k(e[1]-f)],[r,k(e[1]+f)],[i,e[1]],[i,k(e[1]-f)],[i,k(e[1]+f)]]},O=function(e,n){v(e);var t=Math.ceil(n/f);if(e.length>u<31?[r+o[c],r+"~"]:[r+o[c],r+o[l]]},_=function(e,n){y(e);var t=Math.max(1,E(e,n)),r=Math.ceil(t/f),i=x(e,n),o=i.map(function(e){return O(p(e,r),t)});return o.filter(function(e,n){return!o.some(function(t,r){return n>r&&e[0]===t[0]&&e[1]===t[1]})})},P=function(e,o){function a(e,n,t,r){O[e].forEach(function(e){"undefined"==typeof t||null===t?e(n,null,null):e(n,t,r)})}function u(){O.ready.forEach(function(e){e()})}function f(e){var n=e.split(":");if(2!==n.length)throw new Error("Invalid internal state! Not a valid geohash query: "+e);return n}function c(e){if(2!==e.length)throw new Error("Not a valid geohash query: "+e);return e[0]+":"+e[1]}function l(e,n){var t=x.startAt(e[0]).endAt(e[1]);t.off("child_added",n.childAddedCallback),t.off("child_removed",n.childRemovedCallback),t.off("child_changed",n.childChangedCallback),t.off("value",n.valueCallback)}function s(){for(var e in I)if(I.hasOwnProperty(e)){var n=I[e];if(n.active===!1){var t=f(e);l(t,n),delete I[e]}}for(var r in F)if(F.hasOwnProperty(r)&&!d(F[r].geohash)){if(F[r].isInQuery)throw new Error("Internal State error, trying to remove location that is still in query");delete F[r]}C=!1,null!==q&&(clearTimeout(q),q=null)}function h(e,n){y(n);var t,o,u=F.hasOwnProperty(e)?F[e].isInQuery:!1,f=F.hasOwnProperty(e)?F[e].location:null;t=r.distance(n,N),o=A>=t,F[e]={location:n,distanceFromCenter:t,isInQuery:o,geohash:p(n,i)},o&&!u?a("key_entered",e,n,t):!o||null===f||n[0]===f[0]&&n[1]===f[1]?!o&&u&&a("key_exited",e,n,t):a("key_moved",e,n,t)}function d(e){for(var n in I)if(I.hasOwnProperty(n)){var t=f(n);if(e>=t[0]&&e<=t[1])return!0}return!1}function v(e,n){var t=F[e];if(delete F[e],"undefined"!=typeof t&&t.isInQuery){var i=n?r.distance(n,N):null;a("key_exited",e,n,i)}}function b(e){h(e.name(),n(e.val()))}function w(e){h(e.name(),n(e.val()))}function g(e){var t=e.name();F.hasOwnProperty(t)&&x.child(t).once("value",function(e){var r=null===e.val()?null:n(e.val()),i=null!==r?p(r):null;d(i)||v(t,r)})}function M(e){var n=E.indexOf(e);n>-1&&E.splice(n,1),P=0===E.length,P&&u()}function k(){var e=_(N,1e3*A).map(c);e=e.filter(function(n,t){return e.indexOf(n)===t});for(var n in I)if(I.hasOwnProperty(n)){var t=e.indexOf(n);-1===t?I[n].active=!1:(I[n].active=!0,e.splice(t,1))}C===!1&&Object.keys(I).length>25&&(C=!0,q=setTimeout(s,10)),E=e.slice(),e.forEach(function(e){var n=f(e),t=x.startAt(n[0]).endAt(n[1]),r=t.on("child_added",b),i=t.on("child_removed",g),o=t.on("child_changed",w),a=t.on("value",function(){t.off("value",a),M(e)});I[e]={active:!0,childAddedCallback:r,childRemovedCallback:i,childChangedCallback:o,valueCallback:a}}),0===e.length&&M()}if(this.center=function(){return N},this.radius=function(){return A},this.updateCriteria=function(e){m(e),N=e.center||N,A=e.radius||A;for(var n in F)if(F.hasOwnProperty(n)){var t=F[n],i=t.isInQuery;t.distanceFromCenter=r.distance(t.location,N),t.isInQuery=t.distanceFromCenter<=A,i&&!t.isInQuery?a("key_exited",n,t.location,t.distanceFromCenter):!i&&t.isInQuery&&a("key_entered",n,t.location,t.distanceFromCenter)}P=!1,k()},this.on=function(e,n){if(-1===["ready","key_entered","key_exited","key_moved"].indexOf(e))throw new Error('event type must be "ready", "key_entered", "key_exited", or "key_moved"');if("function"!=typeof n)throw new Error("callback must be a function");if(O[e].push(n),"key_entered"===e)for(var r in F)if(F.hasOwnProperty(r)){var i=F[r];i.isInQuery&&n(r,i.location,i.distanceFromCenter)}return"ready"===e&&P&&n(),new t(function(){O[e].splice(O[e].indexOf(n),1)})},this.cancel=function(){O={ready:[],key_entered:[],key_exited:[],key_moved:[]};for(var e in I)if(I.hasOwnProperty(e)){var n=f(e);l(n,I[e]),delete I[e]}F={},clearInterval(j)},"[object Object]"!==Object.prototype.toString.call(e))throw new Error("firebaseRef must be an instance of Firebase");var E,x=e,O={ready:[],key_entered:[],key_exited:[],key_moved:[]},P=!1,F={},I={},C=!1,q=null,j=setInterval(function(){C===!1&&s()},1e4);m(o,!0);var N=o.center,A=o.radius;k()};return r}();"undefined"!=typeof module&&"undefined"!=typeof process&&(module.exports=GeoFire); \ No newline at end of file diff --git a/src/geoFire.js b/src/geoFire.js index 87ece976..38edd181 100644 --- a/src/geoFire.js +++ b/src/geoFire.js @@ -99,7 +99,7 @@ var GeoFire = function(firebaseRef) { /*****************/ /* CONSTRUCTOR */ /*****************/ - if (firebaseRef instanceof Firebase === false) { + if (Object.prototype.toString.call(firebaseRef) !== "[object Object]") { throw new Error("firebaseRef must be an instance of Firebase"); } diff --git a/src/geoQuery.js b/src/geoQuery.js index b3905352..49a4495d 100644 --- a/src/geoQuery.js +++ b/src/geoQuery.js @@ -489,7 +489,7 @@ var GeoQuery = function (firebaseRef, queryCriteria) { /* CONSTRUCTOR */ /*****************/ // Firebase reference of the GeoFire which created this query - if (firebaseRef instanceof Firebase === false) { + if (Object.prototype.toString.call(firebaseRef) !== "[object Object]") { throw new Error("firebaseRef must be an instance of Firebase"); } var _firebaseRef = firebaseRef; diff --git a/tests/specs/common.spec.js b/tests/specs/common.spec.js index 7f5f70d2..34c22f3b 100644 --- a/tests/specs/common.spec.js +++ b/tests/specs/common.spec.js @@ -8,7 +8,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; var demoFirebaseUrl = "https://geofire.firebaseio.com"; // Define examples of valid and invalid parameters -var invalidFirebaseRefs = [null, undefined, NaN, true, false, [], {}, 0, 5, "", "a", {a:1}, ["hi", 1]]; +var invalidFirebaseRefs = [null, undefined, NaN, true, false, [], 0, 5, "", "a", ["hi", 1]]; var validKeys = ["a", "loc1", "(e@Xi:4t>*E2)hc<5oa:1s6{B0d?u", Array(743).join("a")]; var invalidKeys = ["", 1, true, false, [], {}, [1, 2], {a: 1}, null, undefined, NaN, "loc.1", "loc$1", "[loc1", "loc1]", "loc#1", "loc/1", "a#i]$da[s", "te/nst", "te/rst", "te/u0000st", "te/u0015st", "te/007Fst", Array(800).join("a")]; var validLocations = [[0, 0], [-90, 180], [90, -180], [23, 74], [47.235124363, 127.2379654226]];