Skip to content

Commit 883d9d1

Browse files
committed
workable prototype
1 parent 751110e commit 883d9d1

File tree

21 files changed

+9679
-109
lines changed

21 files changed

+9679
-109
lines changed

www/assets/javascripts/application.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ Backbone.View.prototype.close = function () {
99
var QuickNav = Backbone.Router.extend({
1010
routes: {
1111
"": "index",
12-
"locations/:id": "show",
13-
"locations/new": "newLocation"
12+
"locations/new": "newLocation",
13+
"locations/edit": "editLocation",
14+
"locations/create": "createLocation",
15+
"locations/:id": "show"
1416
},
1517
index: function(){
1618
this.before(function(){
17-
try{
18-
app.showView(new LocationIndexView({model: app.locations}));
19-
}catch(e){
20-
console.log(e)
21-
}
22-
19+
app.showView(new LocationIndexView({collection: app.locations}));
2320
});
2421
},
2522
show: function(id){
@@ -30,13 +27,29 @@ var QuickNav = Backbone.Router.extend({
3027
},
3128
newLocation: function(){
3229
this.before(function(){
33-
app.showView(new NewLocationView());
30+
app.showView(new NewLocationView());
3431
});
3532
},
33+
createLocation: function(){
34+
var location = new Location({name: $("#name").val(), address: $("#address").val()});
35+
location.save([], {
36+
success: function(){
37+
app.navigate("", true);
38+
app.locations.fetch();
39+
},
40+
error: function(x){
41+
alert(x);
42+
}
43+
});
44+
},
45+
updateLocation: function(){
46+
alert(name);
47+
alert(address);
48+
},
3649
showView: function(view){
3750
if (this.currentView)
3851
this.currentView.close();
39-
$('body').html(view.render().el);
52+
$('#jqt').html(view.render().el);
4053
this.currentView = view;
4154
return view;
4255
},
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(function($) {
2+
if ($.jQTouch)
3+
{
4+
$.jQTouch.addExtension(function Location(){
5+
6+
var latitude, longitude, callback, callback2;
7+
8+
function updateLocation(fn, fn2) {
9+
if (navigator.geolocation)
10+
{
11+
callback = fn;
12+
callback2 = fn2;
13+
navigator.geolocation.getCurrentPosition(savePosition, failResponse);
14+
return true;
15+
} else {
16+
console.log('Device not capable of geo-location.');
17+
fn(false);
18+
return false;
19+
}
20+
}
21+
function failResponse(error){
22+
if (callback2) {
23+
callback2(error);
24+
}
25+
}
26+
function savePosition(position) {
27+
latitude = position.coords.latitude;
28+
longitude = position.coords.longitude;
29+
if (callback) {
30+
callback(getLocation());
31+
}
32+
}
33+
function getLocation() {
34+
if (latitude && longitude) {
35+
return {
36+
latitude: latitude,
37+
longitude: longitude
38+
};
39+
40+
} else {
41+
console.log('No location available. Try calling updateLocation() first.');
42+
return false;
43+
}
44+
}
45+
return {
46+
updateLocation: updateLocation,
47+
getLocation: getLocation
48+
};
49+
});
50+
}
51+
})($);

www/assets/javascripts/lib/jqt.location.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/*
2+
3+
jQuery Bridge for jQTouch
4+
(adds events which Zepto includes by default)
5+
6+
Created by David Kaneda <http://www.davidkaneda.com>
7+
Maintained by Jonathan Stark <http://jonathanstark.com/>
8+
Sponsored by Sencha Labs <http://www.sencha.com/>
9+
10+
Documentation and issue tracking on GitHub <http://wiki.github.com/senchalabs/jQTouch/>
11+
12+
(c) 2009-2011 by jQTouch project members.
13+
See LICENSE.txt for license.
14+
15+
*/
16+
17+
(function($) {
18+
var SUPPORT_TOUCH = (!!window.Touch),
19+
START_EVENT = SUPPORT_TOUCH ? 'touchstart' : 'mousedown',
20+
MOVE_EVENT = SUPPORT_TOUCH ? 'touchmove' : 'mousemove',
21+
END_EVENT = SUPPORT_TOUCH ? 'touchend' : 'mouseup',
22+
CANCEL_EVENT = SUPPORT_TOUCH ? 'touchcancel' : 'mouseout', // mouseout on document
23+
lastTime = 0,
24+
tapReady = true,
25+
jQTSettings = {
26+
useFastTouch: true, // experimental
27+
debug: true,
28+
moveThreshold: 10,
29+
hoverDelay: 50,
30+
pressDelay: 750
31+
};
32+
33+
function warn(message) {
34+
if (window.console !== undefined) {
35+
console.log(message);
36+
}
37+
}
38+
39+
function touchStartHandler(e) {
40+
41+
if (!tapReady) {
42+
warn('TouchStart handler aborted because tap is not ready');
43+
e.preventDefault();
44+
return false;
45+
}
46+
47+
var $el = $(e.target);
48+
49+
// Error check
50+
if (!$el.length) {
51+
warn('Could not find target of touchstart event.');
52+
return;
53+
}
54+
55+
var startTime = new Date().getTime(),
56+
hoverTimeout = null,
57+
pressTimeout = null,
58+
touch,
59+
startX,
60+
startY,
61+
deltaX = 0,
62+
deltaY = 0,
63+
deltaT = 0;
64+
65+
touch = SUPPORT_TOUCH? event.changedTouches[0]: event;
66+
startX = touch.pageX;
67+
startY = touch.pageY;
68+
69+
// Prep the element
70+
bindEvents($el);
71+
72+
hoverTimeout = setTimeout(function() {
73+
$el.makeActive();
74+
}, jQTSettings.hoverDelay);
75+
76+
pressTimeout = setTimeout(function() {
77+
unbindEvents($el);
78+
$el.unselect();
79+
clearTimeout(hoverTimeout);
80+
$el.trigger('press');
81+
}, jQTSettings.pressDelay);
82+
83+
// Private touch functions
84+
function touchCancelHandler(e) {
85+
clearTimeout(hoverTimeout);
86+
$el.unselect();
87+
unbindEvents($el);
88+
}
89+
90+
function touchEndHandler(e) {
91+
// updateChanges();
92+
unbindEvents($el);
93+
clearTimeout(hoverTimeout);
94+
clearTimeout(pressTimeout);
95+
if (Math.abs(deltaX) < jQTSettings.moveThreshold && Math.abs(deltaY) < jQTSettings.moveThreshold && deltaT < jQTSettings.pressDelay) {
96+
// e.preventDefault();
97+
// e.stopImmediatePropagation();
98+
if (SUPPORT_TOUCH && jQTSettings.useFastTouch) {
99+
$el.trigger('tap', e);
100+
}
101+
} else {
102+
$el.unselect();
103+
}
104+
}
105+
106+
function touchMoveHandler(e) {
107+
updateChanges();
108+
var absX = Math.abs(deltaX);
109+
var absY = Math.abs(deltaY);
110+
var direction;
111+
if (absX > absY && (absX > 30) && deltaT < 1000) {
112+
if (deltaX < 0) {
113+
direction = 'left';
114+
} else {
115+
direction = 'right';
116+
}
117+
unbindEvents($el);
118+
$el.trigger('swipe', {direction:direction, deltaX:deltaX, deltaY: deltaY});
119+
}
120+
$el.unselect();
121+
clearTimeout(hoverTimeout);
122+
if (absX > jQTSettings.moveThreshold || absY > jQTSettings.moveThreshold) {
123+
clearTimeout(pressTimeout);
124+
}
125+
}
126+
127+
function updateChanges() {
128+
var firstFinger = SUPPORT_TOUCH? event.changedTouches[0]: event;
129+
deltaX = firstFinger.pageX - startX;
130+
deltaY = firstFinger.pageY - startY;
131+
deltaT = new Date().getTime() - startTime;
132+
}
133+
134+
function bindEvents($el) {
135+
$el.bind(MOVE_EVENT, touchMoveHandler).bind(END_EVENT, touchEndHandler);
136+
if (SUPPORT_TOUCH) {
137+
$el.bind(CANCEL_EVENT, touchCancelHandler);
138+
} else {
139+
$(document).bind('mouseout', touchCancelHandler);
140+
}
141+
}
142+
143+
function unbindEvents($el) {
144+
if (!$el) return;
145+
146+
$el.unbind(MOVE_EVENT, touchMoveHandler).unbind(END_EVENT, touchEndHandler);
147+
if (SUPPORT_TOUCH) {
148+
$el.unbind(CANCEL_EVENT, touchCancelHandler);
149+
} else {
150+
$(document).unbind('mouseout', touchCancelHandler);
151+
}
152+
}
153+
} // End touch handler
154+
155+
$.jQTouch = function(options) {
156+
157+
// take in options
158+
for (var i in options) {
159+
jQTSettings[i] = options[i];
160+
}
161+
162+
$(document).bind('ready', function() {
163+
$('#jqt').bind(START_EVENT, touchStartHandler);
164+
});
165+
166+
$.fn.press = function(fn) {
167+
if ($.isFunction(fn)) {
168+
return $(this).live('press', fn);
169+
} else {
170+
return $(this).trigger('press');
171+
}
172+
};
173+
$.fn.swipe = function(fn) {
174+
if ($.isFunction(fn)) {
175+
return $(this).live('swipe', fn);
176+
} else {
177+
return $(this).trigger('swipe');
178+
}
179+
};
180+
$.fn.tap = function(fn) {
181+
if ($.isFunction(fn)) {
182+
return $(this).live('tap', fn);
183+
} else {
184+
return $(this).trigger('tap');
185+
}
186+
};
187+
188+
options.framework = $;
189+
190+
var core = jQTouchCore(options);
191+
192+
return core;
193+
};
194+
195+
// Extensions directly manipulate the jQTouch object, before it's initialized.
196+
$.jQTouch.addExtension = function(extension) {
197+
jQTouchCore.prototype.extensions.push(extension);
198+
};
199+
200+
})(jQuery);

www/assets/javascripts/lib/jqtouch-jquery.min.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)