Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Issue 171 rev1 (team 4) #190

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions piplmesh/frontend/static/piplmesh/jquery/jquery.simplegeo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* jQuery Simple-Geolocation
*
* @author Ziga Zupanec <[email protected]>
* @public domain
* @version 0.1
*/

;(function($) {
var defaultlocation = {lat: 46.17, lng: 14.96, zoom: 8};

var methods = {
init: function(params) {
return this.each(function(){
var $this = $(this),
data = $this.data('simplegeo'),
simplegeo = $this;

if (!data) {
if (params.callback === undefined) {
params.callback = alert;
}
if (params.zoom === undefined) {
params.zoom = defaultlocation.zoom;
}
if (params.lat === undefined || params.lng === undefined) {
params.lat = false || params.lat;
params.lng = false || params.lng;

var nodeResponse = $this.simplegeo('node');
if (nodeResponse) {
params.callback(nodeResponse);
}
else {
$this.simplegeo('html5', params.callback);
}
}
else {
params.callback({lat: params.lat, lng: params.lng, zoom: params.zoom});
}
}
});
},

node: function() {
// TODO: Remove stub.
if (Math.random() < 0.5)
return false;
var randomNode = nodes[Math.floor(Math.random() * nodes.length)];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify this to return assigned node?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, no. We will use HTML5 geolocation to send this information to the server, which will then based on that find closest node and then other parts of the portal will work as expected. So this should be done only on /outside/ view.

return {lat: randomNode.lat, lng: randomNode.long, zoom: 15};
},

html5: function(callback) {
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(
function(position) {
callback({lat: position.coords.latitude, lng: position.coords.longitude, zoom: 15});
},
function(msg) {
callback(defaultlocation);
}
);
}
else {
callback(defaultlocation);
}
},

update: function(params) {
return this.each(function() {
var $this = $(this),
data = $this.data('simplegeo');

if (params === undefined)
params = data;

$(this).data('simplegeo', {
target: $this,
lat: params.lat || data.lat,
lng: params.lng || data.lng,
zoom: params.zoom || data.zoom
});
})
}
};

$.fn.simplegeo = function(method) {
if (methods[method]) {
return methods[method].apply(
this,
Array.prototype.slice.call(arguments, 1)
);
}
else if (typeof method === 'object' || !method) {
return methods.init.apply(
this,
arguments
);
}
else {
$.error('Method '+method+' does not exist on jQuery.simplegeo');
}
};
})(jQuery);
Loading