UNPKG

mock-geolocation

Version:
1 lines 2.02 kB
!function(e,t){function o(e){for(var t in f)e.hasOwnProperty(t)&&(f[t]=e[t]);void 0!==e.lat&&(f.latitude=e.lat),void 0!==e.lng&&(f.longitude=e.lng)}function n(e){e=e||{};var t={coords:{}};for(var o in f)t.coords[o]=f[o];return void 0!==e.timestamp?t.timestamp=e.timestamp:t.timestamp=Date.now(),t}function i(e){e=e||{};var t={};return void 0!==e.code?t.code=e.code:t.code=d.code,void 0!==e.message?t.message=e.message:t.message=d.message,t}function r(){var t=e.geolocate;c.noConflict=function(){return void 0!==t?e.geolocate=t:delete e.geolocate,c},e.geolocate=c}var a,c={},u=0,f={accuracy:50,altitude:null,altitudeAccuracy:null,heading:null,latitude:54.9799,longitude:82.89683699999999,speed:null},d={code:1,message:"The acquisition of the geolocation information failed because the page didn't have the permission to do it."},l={},s={},g=function(e){if(Object.defineProperty)Object.defineProperty(t,"geolocation",{get:function(){return e},configurable:!0});else{if(!t.__defineGetter__)throw new Error("Cannot change navigator.geolocation method");t.__defineGetter__("geolocation",function(){return e})}};c.use=function(){return a=t.geolocation,g({getCurrentPosition:function(e,t,o){u++,l[u]=arguments},watchPosition:function(e,t,o){return u++,l[u]=arguments,s[u]=arguments,u},clearWatch:function(e){s[e]&&(delete s[e],l[e]&&delete l[e])}}),this},c.restore=function(){return a?g(a):delete t.geolocation,l={},s={},this},c.send=function(e){e&&o(e);for(var t in l)"function"==typeof l[t][0]&&l[t][0](n(e));return l={},this},c.sendError=function(e){for(var t in l)"function"==typeof l[t][1]&&l[t][1](i(e));return l={},this},c.change=function(e){e&&o(e);for(var t in s)"function"==typeof s[t][0]&&s[t][0](n(e)),l[t]&&delete l[t];return this},c.changeError=function(e){for(var t in s)"function"==typeof s[t][1]&&s[t][1](i(e)),l[t]&&delete l[t];return this},"object"==typeof module&&"object"==typeof module.exports?module.exports=c:"function"==typeof define&&define.amd?define(c):"undefined"!=typeof e&&r()}(window,navigator);