Commits

Marco Yuen committed e009028

Switch to coffee script.

  • Participants
  • Parent commits e213ed3

Comments (0)

Files changed (2)

File resources/public/js/location.coffee

+$ ->
+    success = (position) ->
+        console.log(position)
+        $('#lat').html(position.coords.latitude)
+        $('#lng').html(position.coords.longitude)
+        true
+
+    errorhandler = (error) ->
+        console.log("Cannot acquire location.")
+        switch error.code
+            when error.PERMISSION_DENIED then alert "User did not share location data."
+            when error.POSITION_UNAVAILABLE then alert "Could not detect current position"
+            when error.TIMEOUT then alert "Retrieving position timed out"
+            else alert "Unknown error"
+
+
+    if navigator.geolocation
+        navigator.geolocation.getCurrentPosition(success, errorhandler
+                                                 {enableHighAccuracy: true})
+    else
+        alert("Cannot determine your location.")
+

File resources/public/js/location.js

-$(function() {
-  if (navigator.geolocation) {
-    navigator.geolocation.getCurrentPosition(success, handleError,
-                                             {enableHighAccuracy: true});
-  } else {
-    alert('Geolocation not supported');
-  }
+// Generated by CoffeeScript 1.3.3
 
-  function success(position) {
+$(function() {
+  var errorhandler, success;
+  success = function(position) {
     console.log(position);
-    $("#lng").html(position.coords.longitude);
-    $("#lat").html(position.coords.latitude);
-  }
-
-  function handleError(error) {
-    console.log("No location");
-    switch(error.code)
-    {
-      case error.PERMISSION_DENIED: alert("user did not share geolocation data");
-      break;
-
-      case error.POSITION_UNAVAILABLE: alert("could not detect current position");
-      break;
-
-      case error.TIMEOUT: alert("retrieving position timed out");
-      break;
-
-      default: alert("unknown error");
-      break;
+    $('#lat').html(position.coords.latitude);
+    $('#lng').html(position.coords.longitude);
+    return true;
+  };
+  errorhandler = function(error) {
+    console.log("Cannot acquire location.");
+    switch (error.code) {
+      case error.PERMISSION_DENIED:
+        return alert("User did not share location data.");
+      case error.POSITION_UNAVAILABLE:
+        return alert("Could not detect current position");
+      case error.TIMEOUT:
+        return alert("Retrieving position timed out");
+      default:
+        return alert("Unknown error");
     }
+  };
+  if (navigator.geolocation) {
+    return navigator.geolocation.getCurrentPosition(success, errorhandler, {
+      enableHighAccuracy: true
+    });
+  } else {
+    return alert("Cannot determine your location.");
   }
 });
-
-//var loc = {};
-//if(google.loader.ClientLocation) {
-//  loc.lat = google.loader.ClientLocation.latitude;
-//  loc.lng = google.loader.ClientLocation.longitude;
-//}