Permalink
Browse files

Created helpers

  • Loading branch information...
1 parent 5f68ed3 commit 887bc008e2dbaff7e3c471764646d9f7a639cdc3 @parolkar committed Oct 19, 2009
View
@@ -1,4 +1,4 @@
-Copyright (c) 2009 [name of plugin creator]
+Copyright (c) 2009 Abhishek Parolkar
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
6 README
@@ -1,13 +1,15 @@
GeoMereLaal
===========
-Introduction goes here.
+This plugin allows you to detect geo-loacation of your users through http://www.mozilla.com/en-US/firefox/geolocation/
+
+Requirement: Firefox 3+
Example
=======
-Example goes here.
+soon to come..
Copyright (c) 2009 Abhishek Parolkar, released under the MIT license
@@ -1,9 +1,7 @@
class GeoMereLaalController < ApplicationController
- def init
-
- response["Content-type"] = "text/javascript"
-
+ def init
+ response["Content-type"] = "text/javascript"
end
end
@@ -0,0 +1,30 @@
+<% model_name ||= "geo" %>
+
+<div id="geo-mere-laal-wait" style="display:none;" > Please wait while we retrieve your location... </div>
+<div id="geo-mere-laal-fields" style="display:none;">
+ <%= label model_name,"lat","Latitude" -%>
+ <%= text_field model_name, "lat" %>
+ <br>
+ <%= label model_name,"lng","Longitude" -%>
+ <%= text_field model_name, "lng" %>
+</div >
+
+<script>
+ if(GeoMereLaal.isBrowserCompatible)
+ {
+ document.getElementById("geo-mere-laal-wait").style.display = "block";
+ GeoMereLaal.onReceive = function(){
+ document.getElementById("<%=model_name+"_lat" -%>").setAttribute("value",GeoMereLaal.lat());
+ document.getElementById("<%=model_name+"_lng" -%>").setAttribute("value",GeoMereLaal.lng());
+ document.getElementById("geo-mere-laal-fields").style.display = "block";
+ document.getElementById("geo-mere-laal-wait").style.display = "none";
+ }
+ GeoMereLaal.request();
+ }else{
+
+ document.getElementById("geo-mere-laal-fields").style.display = "block";
+ }
+
+
+
+</script>
@@ -1,18 +1,41 @@
//Author: Abhishek Parolkar ( abhishek@parolkar.com )
-GeoMereLaal = function(){
- var latitude = new String();
+GeoMereLaal = function(){
var longitude = new String();
+ var latitude = new String();
return {
lat: function(){
- return latitude;
+ return this.getCookie("latitude");
},
lng: function(){
- return longitude;
+ return this.getCookie("longitude");
},
+ setCookie: function (c_name,value,expiredays)
+ {
+ var exdate=new Date();
+ exdate.setDate(exdate.getDate()+expiredays);
+ document.cookie=c_name+ "=" +escape(value)+
+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
+ },
+ getCookie: function (c_name)
+ {
+ if (document.cookie.length>0)
+ {
+ c_start=document.cookie.indexOf(c_name + "=");
+ if (c_start!=-1)
+ {
+ c_start=c_start + c_name.length+1;
+ c_end=document.cookie.indexOf(";",c_start);
+ if (c_end==-1) c_end=document.cookie.length;
+ return unescape(document.cookie.substring(c_start,c_end));
+ }
+ }
+ return "";
+ },
+ dataExpires: 1, //These are number of days
isBrowserCompatible: function(){
var userAgent = navigator.userAgent.toLowerCase();
// Figure out what browser is being used in Jquery Style
@@ -31,19 +54,40 @@ GeoMereLaal = function(){
}
},
- request: function(){
+ fetch: function(){
if(this.isBrowserCompatible())
- {
- navigator.geolocation.getCurrentPosition(function(position) {
- latitude = position.coords.latitude;
- longitude = position.coords.longitude;
+ {
+
+ navigator.geolocation.getCurrentPosition(function(position) {
+
+ GeoMereLaal.setCookie("latitude",position.coords.latitude,GeoMereLaal.dataExpires);
+ GeoMereLaal.setCookie("longitude",position.coords.longitude,GeoMereLaal.dataExpires);
+ GeoMereLaal.onReceive();
- });
+ },GeoMereLaal.onError);
return true;
}else{return false;}
- }
-
+ },
+ request:function(){
+ var lat = this.lat();
+ var lng = this.lng();
+ if(lat =='' || lng == '')
+ {
+ this.fetch();
+ }else{
+ GeoMereLaal.onReceive();
+ }
+
+ },
+ onReceive:function(){
+ //This is a stub to be overridden by user's code
+ },
+ onError:function(error){
+ //This can be overridden by user's code
+ alert("We couldn't retrieve your location ");
+ }
+

0 comments on commit 887bc00

Please sign in to comment.