From e7076380d3c929bdbe5f7f3d1b4f79db3f9c6da2 Mon Sep 17 00:00:00 2001 From: arzynik Date: Wed, 11 Jul 2012 15:41:41 -0700 Subject: [PATCH] added location services --- include/library/Crunchbutton/Community.php | 3 + .../default/crunchbutton/layout/html.phtml | 20 +++++++ www/assets/css/style.css | 10 +++- www/assets/js/app.js | 60 +++++++++++++++++-- 4 files changed, 86 insertions(+), 7 deletions(-) diff --git a/include/library/Crunchbutton/Community.php b/include/library/Crunchbutton/Community.php index 2b7637f30..39a5011b1 100644 --- a/include/library/Crunchbutton/Community.php +++ b/include/library/Crunchbutton/Community.php @@ -1,6 +1,9 @@ _restaurants)) { $this->_restaurants = Restaurant::q(' diff --git a/include/views/default/crunchbutton/layout/html.phtml b/include/views/default/crunchbutton/layout/html.phtml index 15298bac8..bc825f7c9 100755 --- a/include/views/default/crunchbutton/layout/html.phtml +++ b/include/views/default/crunchbutton/layout/html.phtml @@ -18,9 +18,29 @@ */ ?> + + + + + diff --git a/www/assets/css/style.css b/www/assets/css/style.css index d2a29f2e0..33bcfd53d 100644 --- a/www/assets/css/style.css +++ b/www/assets/css/style.css @@ -868,6 +868,14 @@ and (max-width : 768px) { .restaurant-item-title:first-child { margin-top: 10px; } + .cart-summary { + height: 30px; + background: red; + position: fixed; + width: 100%; + left: 0; + margin-top: -9px; + } } @media only screen @@ -950,8 +958,6 @@ and (min-width : 1024px) { position: absolute; margin-top: -4px; } - - } diff --git a/www/assets/js/app.js b/www/assets/js/app.js index 2114a0fe7..98a43f286 100644 --- a/www/assets/js/app.js +++ b/www/assets/js/app.js @@ -46,7 +46,9 @@ if (typeof(Ti) != 'undefined') { var triggerCache = arguments[2] ? true : false; $.getJSON(url,function(json) { if (triggerCache) { - $('body').triggerHandler('cache-item-loaded-' + arguments[2]); + setTimeout(function() { + $('body').triggerHandler('cache-item-loaded-' + arguments[2]); + },10); } complete(json); }); @@ -102,12 +104,17 @@ App.loadPaymentinfo = function() { } App.loadCommunity = function(id) { + if (id == 'brown' || id == 'santa-monica') { + $('.main-content-item').show(); + $('.main-content-item').html('coming soon'); + return; + } App.cache('Community',id, function() { App.community = App.cached['Community'][id]; console.log(App.community, id); if (!App.community.id_community) { $('.main-content-item').show(); - $('.main-content-item').html('invalid community'); + $('.main-content-item').html('just a sec...'); setTimeout(function() { App.page.community('yale'); @@ -180,6 +187,7 @@ App.page.restaurant = function(id) { document.title = App.restaurant.name; $('.main-content-item').html( + '
' + '

' + App.restaurant.name + '

' + '
' + '
' + @@ -384,9 +392,15 @@ App.loadPage = function() { // force to yale if there isnt a place yet // @todo: detect community if (location.pathname == '/') { - loc = '/yale'; + var closest = App.loc.closest(); + if (closest.permalink) { + loc = '/' + closest.permalink; + path = ['',closest.permalink]; + } else { + loc = '/yale'; + path = ['','yale']; + } history.replaceState({},loc,loc); - path = ['','yale']; } if (!App.community) { @@ -1006,4 +1020,40 @@ var init = function() { window.addEventListener('DOMContentLoaded', init, false); })(); -*/ \ No newline at end of file +*/ + +App.loc = { + distance: function(params) { + // {from: {lat: 1, lon: 1}, to: {lat: 2, lon: 2}} + var R = 6371; // Radius of the earth in km + var dLat = (params.to.lat - params.from.lat).toRad(); // Javascript functions in radians + + var dLon = (params.to.lon - params.from.lon).toRad(); + var a = Math.sin(dLat/2) * Math.sin(dLat/2) + + Math.cos(params.from.lat.toRad()) * Math.cos(params.to.lat.toRad()) * + Math.sin(dLon/2) * Math.sin(dLon/2); + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); + var d = R * c; // Distance in km + + return d; + }, + closest: function() { + var closest; + for (x in App.cached['Community']) { + App.cached['Community'][x].distance = App.loc.distance({ + from: {lat: App.loc.lat, lon: App.loc.lon}, + to: {lat: parseFloat(App.cached['Community'][x].loc_lat), lon: parseFloat(App.cached['Community'][x].loc_lon)} + }); + if (!closest || App.cached['Community'][x].distance < closest.distance) { + closest = App.cached['Community'][x]; + } + } + return closest; + } +} + +if (typeof(Number.prototype.toRad) === "undefined") { + Number.prototype.toRad = function() { + return this * Math.PI / 180; + } +} \ No newline at end of file