1XA.component.locationService = (function ($, document) { 2 3 "use strict"; 4 5 var api = {}, 6 getCurrentLocation, 7 getLocationOptions, 8 detectBrowser, 9 gettingLocation = false, 10 errorCallbacks = [], 11 successCallbacks = [], 12 reportError; 13 14 15 getCurrentLocation = function(success, error) { 16 var i; 17 18 errorCallbacks.push(error); 19 successCallbacks.push(success); 20 21 if (gettingLocation) { 22 //process for getting current location has already been started, just subscribe for proper event and wait 23 return; 24 } 25 gettingLocation = true; 26 if (navigator.geolocation) { 27 navigator.geolocation.getCurrentPosition( 28 function (position) { 29 for (i = 0; i < successCallbacks.length; i++) { 30 successCallbacks[i]([position.coords.latitude, position.coords.longitude]); 31 } 32 gettingLocation = false; 33 }, 34 function (error) { 35 reportError("Error while detecting user location location"); 36 gettingLocation = false; 37 }, 38 getLocationOptions() 39 ); 40 } else { 41 reportError("Your browser doesn\'t support geolocation"); 42 gettingLocation = false; 43 } 44 }; 45 46 getLocationOptions = function() { 47 var browser = detectBrowser(); 48 if (browser.indexOf("Chrome") !== -1) { 49 return { 50 enableHighAccuracy: true, 51 timeout: 10000, 52 maximumAge: 0 53 }; 54 } else { 55 return { 56 timeout: 1000, 57 maximumAge: Infinity 58 }; 59 } 60 }; 61 62 detectBrowser = function() { 63 var ua = navigator.userAgent, 64 tem, 65 M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; 66 67 if (/trident/i.test(M[1])) { 68 tem= /\brv[ :]+(\d+)/g.exec(ua) || []; 69 return "IE " + (tem[1] || ""); 70 } 71 if (M[1] === "Chrome") { 72 tem = ua.match(/\b(OPR|Edge)\/(\d+)/); 73 if(tem != null) { 74 return tem.slice(1).join(" ").replace("OPR", "Opera"); 75 } 76 } 77 M= M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, "-?"]; 78 if ((tem= ua.match(/version\/(\d+)/i)) != null) { 79 M.splice(1, 1, tem[1]); 80 } 81 return M.join(" "); 82 }; 83 84 reportError = function(errorMessage) { 85 var i; 86 for (i = 0; i < errorCallbacks.length; i++) { 87 if (typeof errorCallbacks[i] === "function") { 88 errorCallbacks[i](errorMessage); 89 } 90 } 91 }; 92 93 api.detectLocation = function(success, error) { 94 getCurrentLocation(success, error); 95 }; 96 97 return api; 98 99}(jQuery, document)); 100 101XA.register("locationService", XA.component.locationService);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.