]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - js/geometa.js
Drop the Google Client API-based AJAX geolocation lookup shim -- it fails to ask...
[quix0rs-gnu-social.git] / js / geometa.js
1 // A shim to implement the W3C Geolocation API Specification using Gears
2 if (typeof navigator.geolocation == "undefined" || navigator.geolocation.shim ) (function(){
3
4 // -- BEGIN GEARS_INIT
5 (function() {
6   // We are already defined. Hooray!
7   if (window.google && google.gears) {
8     return;
9   }
10
11   var factory = null;
12
13   // Firefox
14   if (typeof GearsFactory != 'undefined') {
15     factory = new GearsFactory();
16   } else {
17     // IE
18     try {
19       factory = new ActiveXObject('Gears.Factory');
20       // privateSetGlobalObject is only required and supported on WinCE.
21       if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
22         factory.privateSetGlobalObject(this);
23       }
24     } catch (e) {
25       // Safari
26       if ((typeof navigator.mimeTypes != 'undefined')
27            && navigator.mimeTypes["application/x-googlegears"]) {
28         factory = document.createElement("object");
29         factory.style.display = "none";
30         factory.width = 0;
31         factory.height = 0;
32         factory.type = "application/x-googlegears";
33         document.documentElement.appendChild(factory);
34       }
35     }
36   }
37
38   // *Do not* define any objects if Gears is not installed. This mimics the
39   // behavior of Gears defining the objects in the future.
40   if (!factory) {
41     return;
42   }
43
44   // Now set up the objects, being careful not to overwrite anything.
45   //
46   // Note: In Internet Explorer for Windows Mobile, you can't add properties to
47   // the window object. However, global objects are automatically added as
48   // properties of the window object in all browsers.
49   if (!window.google) {
50     google = {};
51   }
52
53   if (!google.gears) {
54     google.gears = {factory: factory};
55   }
56 })();
57 // -- END GEARS_INIT
58
59 var GearsGeoLocation = (function() {
60     // -- PRIVATE
61     var geo = google.gears.factory.create('beta.geolocation');
62     
63     var wrapSuccess = function(callback, self) { // wrap it for lastPosition love
64         return function(position) {
65             callback(position);
66             self.lastPosition = position;
67         }
68     }
69     
70     // -- PUBLIC
71     return {
72         shim: true,
73         
74         type: "Gears",
75         
76         lastPosition: null,
77         
78         getCurrentPosition: function(successCallback, errorCallback, options) {
79             var self = this;
80             var sc = wrapSuccess(successCallback, self);
81             geo.getCurrentPosition(sc, errorCallback, options);
82         },
83         
84         watchPosition: function(successCallback, errorCallback, options) {
85             geo.watchPosition(successCallback, errorCallback, options);
86         },
87         
88         clearWatch: function(watchId) {
89             geo.clearWatch(watchId);
90         },
91         
92         getPermission: function(siteName, imageUrl, extraMessage) {
93             geo.getPermission(siteName, imageUrl, extraMessage);
94         }
95
96     };
97 });
98
99 // If you have Gears installed use that
100 if (window.google && google.gears) {
101     navigator.geolocation = GearsGeoLocation();
102 }
103
104 })();