Commits

Jon Nylander committed fa11b28

Continued work on geolocation and IP lookups. Geolocation is still dodgy, works differently in different browsers. No suprise there I suppose.

Comments (0)

Files changed (1)

detect_timezone.js

         },
     
         ip_lookup = function () {
-            var url = "http://www.pageloom.com/timezone/api/?callback=jstz.tz_lookup_callback";
+            var url = "http://www.pageloom.com/timezone/api/?callback=jstz.api_callback";
             var script = document.createElement('script');
             script.src = url;
             document.body.appendChild(script);
+            if (!config.blocking) {
+                config.callback(preliminary_result);
+            }
         },
         
-        geo_lookup_fallback = function (error) {
+        geo_lookup_fallback = function () {
             if (config.ip) {
                 ip_lookup();
-            }
-            else {
+            } else {
                 config.callback(preliminary_result);
             }
         },
         
         geo_lookup_callback = function (position) {
-            var url = "http://www.pageloom.com/timezone/api/?callback=jstz.tz_lookup_callback&latitude=" + position.coords.latitude + "&longitude=" + position.coords.longitude;
+            var url = "http://www.pageloom.com/timezone/api/?callback=jstz.api_callback&latitude=" + position.coords.latitude + "&longitude=" + position.coords.longitude;
             var script = document.createElement('script');
             script.src = url;
             document.body.appendChild(script);
         
         geo_lookup = function () {
             if (navigator.geolocation) {
-                navigator.geolocation.getCurrentPosition(geo_lookup_callback, geo_lookup_fallback);
+                navigator.geolocation.getCurrentPosition(geo_lookup_callback, function () {
+                        if (config.blocking) {
+                            geo_lookup_fallback();
+                        }
+                    }
+                );
             }
             
-            geo_lookup_fallback();
+            if (!config.blocking) {
+                geo_lookup_fallback();
+            }
         },
         
-        tz_lookup_callback = function (ip_timezone_data) {
-            if (ip_timezone_data) {
-                if (ip_timezone_data.timezone !== preliminary_result.name()) {
-                    preliminary_result.compare_with(ip_timezone_data);
+        api_callback = function (timezone_data) {
+            if (timezone_data) {
+                if (timezone_data.timezone !== preliminary_result.name()) {
+                    preliminary_result.compare_with(timezone_data);
+                    config.callback(preliminary_result);
                 }
             }
-            config.callback(preliminary_result);
         },
         
         determine = function (settings) {
             // Result via pure JavaScript
             preliminary_result = new jstz.TimeZone(jstz.olson.timezones[key]);
             
-            if (!config.geoloc) {
-                if (config.ip) {
-                    ip_lookup();
-                } else {
-                    config.callback(preliminary_result);
-                }                
+            if (config.geoloc) {
+                geo_lookup();
+            } else if (config.ip) {
+                ip_lookup();
             } else {
-                geo_lookup();
+                settings.callback(preliminary_result);    
             }
+            
         };
     
     return {
         determine : determine,
-        tz_lookup_callback : tz_lookup_callback,
+        api_callback : api_callback,
         date_is_dst : date_is_dst
     };
 }());
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.