Permalink
Browse files

Add Vantrash Mobile Version

  • Loading branch information...
1 parent aa8218a commit 4831411fb65a1f75933beb20d5b0cb6d44ed4ae0 @kevinj kevinj committed Oct 7, 2009
View
@@ -1,6 +1,7 @@
*.swp
*.swo
static/javascript/vantrash-*compiled*
+static/javascript/vantrash-*mobile*
static/about.html
static/api.html
static/index.html
View
@@ -24,16 +24,32 @@ JS_MAP_FILES=\
$(JS_DIR)/epoly.js \
$(JS_DIR)/map.js \
+JS_MOBILE_TARGET=$(JS_DIR)/vantrash-mobile.js
+JS_MOBILE_MINI=$(JS_DIR)/vantrash-mobile-mini.js
+JS_MOBILE_FILES=\
+ $(JS_DIR)/jquery-latest.js \
+ $(JS_DIR)/jquery-json-1.3.js \
+ $(JS_DIR)/cal.js \
+ $(JS_DIR)/map.js \
+ $(JS_DIR)/reminders.js \
+ $(JS_DIR)/gears_init.js \
+
WIKI_PAGES=about_us faq
CRONJOB=etc/cron.d/vantrash
TESTS=$(wildcard t/*.t)
WIKITESTS=$(wildcard t/wikitests/*.t)
-all: $(JS_MINI) $(JS_MAP_TARGET) $(JS_MAP_MINI)
+all: \
+ $(JS_MINI) \
+ $(JS_MAP_TARGET) $(JS_MAP_MINI) \
+ $(JS_MOBILE_MINI) $(JS_MOBILE_TARGET)
clean:
- rm -f $(JS_MINI) $(JS_TARGET) $(JS_MAP_TARGET) $(JS_MAP_MINI)
+ rm -f \
+ $(JS_MINI) $(JS_TARGET) \
+ $(JS_MAP_TARGET) $(JS_MAP_MINI) \
+ $(JS_MOBILE_TARGET) $(JS_MOBILE_MINI)
.SUFFIXES: .js -mini.js
@@ -52,6 +68,12 @@ $(JS_MAP_TARGET): $(JS_MAP_FILES) Makefile
(echo "// BEGIN $$js"; cat $$js | perl -pe 's/\r//g') >> $@; \
done
+$(JS_MOBILE_TARGET): $(JS_MOBILE_FILES) Makefile
+ rm -f $@;
+ for js in $(JS_MOBILE_FILES); do \
+ (echo "// BEGIN $$js"; cat $$js | perl -pe 's/\r//g') >> $@; \
+ done
+
$(INSTALL_DIR)/%:
mkdir $@
@@ -24,15 +24,18 @@ sub handle_request {
my $self = shift;
my $req = shift;
+ my $coord = qr{[+-]?\d+\.\d+};
+
my $path = $req->path;
my %func_map = (
GET => [
[ qr{^/$} => \&ui_html ],
- [ qr{^/([^/]+)\.html$} => \&ui_html ],
+ [ qr{^/m/?$} => \&ui_html ],
+ [ qr{^/(.+)\.html$} => \&ui_html ],
[ qr{^/zones$} => \&zones_html ],
[ qr{^/zones\.txt$} => \&zones_txt ],
[ qr{^/zones\.json$} => \&zones_json ],
- [ qr{^/zones/([-.\d]+),([-.\d]+)} => \&zone_at_latlng ],
+ [ qr{^/zones/($coord),($coord)(.*)?} => \&zone_at_latlng ],
[ qr{^/zones/([^./]+)$} => \&zone_html ],
[ qr{^/zones/([^/]+)\.txt$} => \&zone_txt ],
[ qr{^/zones/([^/]+)\.json$} => \&zone_json ],
@@ -88,10 +91,23 @@ sub handle_request {
return $self->_static_file($path);
}
+sub is_mobile {
+ my ($self, $req) = @_;
+ my $headers = $req->headers;
+ return $headers->{'user-agent'} =~ m{Android|iPhone|BlackBerry}i ? 1 : 0;
+}
+
+sub default_page {
+ my ($self, $req) = @_;
+ return $self->is_mobile($req) ? 'm/index' : 'index';
+}
+
sub ui_html {
my ($self, $req, $tmpl) = @_;
- $tmpl ||= 'index';
+ $tmpl ||= $self->default_page($req);
my $params = $req->params;
+ $params->{zones} = $self->model->zones->all;
+ $params->{host_port} = $req->uri->host_port;
return $self->process_template("$tmpl.tt2", $params);
}
@@ -127,11 +143,12 @@ sub zone_at_latlng {
my $req = shift;
my $lat = shift;
my $lng = shift;
+ my $rest = shift || "";
my $zone = $self->model->kml->find_zone_for_latlng($lat,$lng);
if ($zone) {
return HTTP::Engine::Response->new(
- headers => [ Location => "/zones/$zone" ],
+ headers => [ Location => "/zones/$zone$rest" ],
status => 302,
);
}
@@ -304,10 +321,16 @@ sub confirm_reminder {
my $req = shift;
my $zone = shift;
my $hash = shift;
+
+ my $is_mobile = $self->is_mobile($req);
my $rem = $self->model->reminders->by_hash($hash);
unless ($rem) {
- my $resp = $self->process_template('zones/reminders/bad_confirm.html');
+ my $resp = $self->process_template(
+ $is_mobile
+ ? 'm/reminder_bad_confirm.tt2'
+ : 'zones/reminders/bad_confirm.html'
+ );
$resp->status(404);
$self->log("CONFIRM_FAIL $zone $hash");
return $resp;
@@ -320,7 +343,12 @@ sub confirm_reminder {
my %param = (
reminder => $rem,
);
- return $self->process_template('zones/reminders/good_confirm.html', \%param);
+ return $self->process_template(
+ $is_mobile
+ ? 'm/reminder_good_confirm.tt2'
+ : 'zones/reminders/good_confirm.html',
+ \%param,
+ );
}
sub put_reminder {
View
@@ -167,6 +167,7 @@ a img {
height: 220px;
width: 220px;
text-align: center;
+ margin: auto;
}
.balloon .buttons {
margin-top: 4px;
@@ -376,3 +377,41 @@ a img {
font-style: italic;
color: #666;
}
+
+#mobile {
+ width: 100%;
+ background-color: #ddd;
+ font-size: 105%;
+}
+
+#mobile .balloon { width: 230px }
+#mobile .legend { width: 120px }
+#mobile .buttons { display: none }
+
+#mobile .logo {
+ font-size: 120%;
+ text-decoration: none;
+}
+#mobile .logo img {
+ height: 20px;
+ vertical-align: middle
+}
+
+#mobile input,
+#mobile select {
+ vertical-align: middle;
+ padding: 5px;
+}
+#mobile input {
+ border: 1px solid #666;
+}
+
+#mobile .elem {
+ display: block;
+ padding: 10px;
+ border-top: 1px solid #666;
+ color: #000;
+}
+#mobile .last {
+ border-bottom: 1px solid #666;
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,87 @@
+// Copyright 2007, Google Inc.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// 3. Neither the name of Google Inc. nor the names of its contributors may be
+// used to endorse or promote products derived from this software without
+// specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Sets up google.gears.*, which is *the only* supported way to access Gears.
+//
+// Circumvent this file at your own risk!
+//
+// In the future, Gears may automatically define google.gears.* without this
+// file. Gears may use these objects to transparently fix bugs and compatibility
+// issues. Applications that use the code below will continue to work seamlessly
+// when that happens.
+
+(function() {
+ // We are already defined. Hooray!
+ if (window.google && google.gears) {
+ return;
+ }
+
+ var factory = null;
+
+ // Firefox
+ if (typeof GearsFactory != 'undefined') {
+ factory = new GearsFactory();
+ } else {
+ // IE
+ try {
+ factory = new ActiveXObject('Gears.Factory');
+ // privateSetGlobalObject is only required and supported on IE Mobile on
+ // WinCE.
+ if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
+ factory.privateSetGlobalObject(this);
+ }
+ } catch (e) {
+ // Safari
+ if ((typeof navigator.mimeTypes != 'undefined')
+ && navigator.mimeTypes["application/x-googlegears"]) {
+ factory = document.createElement("object");
+ factory.style.display = "none";
+ factory.width = 0;
+ factory.height = 0;
+ factory.type = "application/x-googlegears";
+ document.documentElement.appendChild(factory);
+ }
+ }
+ }
+
+ // *Do not* define any objects if Gears is not installed. This mimics the
+ // behavior of Gears defining the objects in the future.
+ if (!factory) {
+ return;
+ }
+
+ // Now set up the objects, being careful not to overwrite anything.
+ //
+ // Note: In Internet Explorer for Windows Mobile, you can't add properties to
+ // the window object. However, global objects are automatically added as
+ // properties of the window object in all browsers.
+ if (!window.google) {
+ google = {};
+ }
+
+ if (!google.gears) {
+ google.gears = {factory: factory};
+ }
+})();
Oops, something went wrong.

0 comments on commit 4831411

Please sign in to comment.