Created
August 26, 2011 03:25
-
-
Save wyattdanger/1172608 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
$(function() { | |
var Map, NomsApp, infoBox, nom, textBox; | |
if (!navigator.geolocation) { | |
alert('bro you need geolocation'); | |
} | |
textBox = $('#text'); | |
infoBox = $("#infoBox"); | |
Map = (function() { | |
function Map() { | |
this.getLocation = __bind(this.getLocation, this); | |
var mapOpts, mapStyles, mapType; | |
mapOpts = { | |
zoom: 17, | |
draggable: false, | |
disableDoubleClickZoom: true, | |
disableDefaultUI: true, | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
scrollwheel: false | |
}; | |
mapStyles = [ | |
{ | |
featureType: "all", | |
stylers: [ | |
{ | |
saturation: -100 | |
} | |
] | |
} | |
]; | |
mapType = new google.maps.StyledMapType(mapStyles, { | |
name: 'nom' | |
}); | |
this.map = new google.maps.Map(document.getElementById('map'), mapOpts); | |
this.map.mapTypes.set("nom", mapType); | |
this.map.setMapTypeId("nom"); | |
this.service = new google.maps.places.PlacesService(this.map); | |
} | |
Map.prototype.getLocation = function() { | |
return navigator.geolocation.getCurrentPosition(__bind(function(pos) { | |
var _ref; | |
_ref = [pos.coords.latitude, pos.coords.longitude], this.lat = _ref[0], this.lng = _ref[1]; | |
this.location = new google.maps.LatLng(this.lat, this.lng); | |
return this.setupClient(); | |
}, this), function() { | |
return textBox.html("Sorry partner. You need to enable HTML5 geolocation to ride this pony."); | |
}); | |
}; | |
Map.prototype.setupClient = function() { | |
textBox.html("Finding a place to eat..."); | |
return setTimeout(__bind(function() { | |
setTimeout(function() {}); | |
window.searchCallbackHandler = this.searchCallbackHandler; | |
return this.search(); | |
}, this), 1000); | |
}; | |
Map.prototype.addMarker = function(info) { | |
var markerOptions; | |
markerOptions = { | |
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAtCAMAAACQyRsgAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRFAAAATExM9/f3////GVqiygAAAAR0Uk5T////AEAqqfQAAABOSURBVHja7NE7CgAgDAPQJN7/zmqr+OniIjgYKNgHdWiRLAToL/S+iwMsH65C2Hq4ywYKI/RP2UCtL6IKwhQVwJJDIEcZpLnehT1ZgAEAjaUEjHrniXIAAAAASUVORK5CYII=", | |
visible: true, | |
map: this.map, | |
position: info.geometry.location | |
}; | |
this.restaurantMarker = new google.maps.Marker(markerOptions); | |
return this.map.setCenter(info.geometry.location); | |
}; | |
Map.prototype.search = function() { | |
if (this.data) { | |
return nom.draw(this.data); | |
} else { | |
return this.service.search({ | |
location: this.location, | |
radius: 3200, | |
types: ['restaurant', 'food', 'bar'] | |
}, searchCallbackHandler); | |
} | |
}; | |
Map.prototype.searchCallbackHandler = function(data, code) { | |
this.data = data; | |
return nom.draw(data); | |
}; | |
return Map; | |
})(); | |
NomsApp = (function() { | |
var phrases; | |
phrases = ["Nom on some <a>\#{ this.name }</a>, buddy!", "Break bread at <a>\#{ this.name }</a>, brother.", "Chow down at <a>\#{ this.name }</a>, champ!", "Put away some <a>\#{ this.name }</a>, partner!", "Demolish some <a>\#{ this.name }</a>, bro.", "Try out some <a>\#{ this.name }</a>, lil' guy.", "Gobble up some <a>\#{ this.name }</a>, turkey.", "Stuff your face at <a>\#{ this.name }</a>, dude.", "Throw back some <a>\#{ this.name }</a>, boss.", "Chew on some <a>\#{ this.name }</a>, chief.", "Chew on some <a>\#{ this.name }</a>, you animal.", "Chew on some <a>\#{ this.name }</a>, you animal."]; | |
function NomsApp() { | |
this.draw = __bind(this.draw, this); | |
this.detailsCallbackHandler = __bind(this.detailsCallbackHandler, this); | |
var tagline; | |
textBox.html("Finding your location..."); | |
this.map = new Map; | |
this.map.getLocation(); | |
this.counter = 0; | |
tagline = $('h2.tagline'); | |
tagline.css('cursor', 'pointer').click(__bind(function() { | |
tagline.removeClass("spinner-" + this.counter); | |
this.counter = (this.counter + 1) % 8; | |
tagline.addClass("spinner-" + this.counter); | |
return this.map.getLocation(); | |
}, this)); | |
} | |
NomsApp.prototype.selectRandom = function(data) { | |
return data[Math.floor(Math.random(data.total) * data.length)]; | |
}; | |
NomsApp.prototype.template = function(a,b){return function(c,d){return a.replace(/#{([^}]*)}/g,function(a,e){return Function("x","with(x)return "+e).call(c,d||b||{})})}}; | |
NomsApp.prototype.info = function(obj) { | |
var t; | |
t = this.template(($('#info')).text()); | |
infoBox.html(t(obj)); | |
return textBox.find('a').attr('href', obj.url); | |
}; | |
NomsApp.prototype.headline = function(obj) { | |
var t; | |
t = this.template(this.selectRandom(phrases)); | |
textBox.html(t(obj)); | |
window.detailsCallbackHandler = this.detailsCallbackHandler; | |
return this.map.service.getDetails({ | |
reference: obj.reference | |
}, detailsCallbackHandler); | |
}; | |
NomsApp.prototype.detailsCallbackHandler = function(info, status) { | |
nom.info(info); | |
return this.map.addMarker(info); | |
}; | |
NomsApp.prototype.draw = function(data) { | |
var choice; | |
if (!data.length) { | |
return textBox.html("Looks like you’re in the middle of nowhere, buddy!"); | |
} | |
choice = this.selectRandom(data); | |
return this.headline(choice); | |
}; | |
return NomsApp; | |
})(); | |
return nom = new NomsApp; | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment