Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 19, 2016
0 parents commit faa454f
Show file tree
Hide file tree
Showing 300 changed files with 3,671 additions and 0 deletions.
Binary file added 9781484202364.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2015 Stephan Alber and Wilkins Fernandez

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*Beginning App Development with Parse and PhoneGap*](http://www.apress.com/9781484202364) by Stephan Alber and Wilkins Fernandez (Apress, 2015).

![Cover image](9781484202364.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
Binary file added ch1/__MACOSX/ch1/._.DS_Store
Binary file not shown.
Binary file added ch1/ch1/.DS_Store
Binary file not shown.
12 changes: 12 additions & 0 deletions ch1/ch1/1-1.js
@@ -0,0 +1,12 @@
// Initialize Parse JavaScript SDK
Parse.initialize("APPLICATION ID", "JAVASCRIPT KEY");
// Define a new Parse class named "Toy"
var Toy = Parse.Object.extend("Toy");
// Create a new Instance of the Toy Parse Class
var myToy = new Toy();

// Set some Example Values
myToy.set("name", "Rocking Horse");
myToy.set("color", "brown");
// Save Object to Parse Cloud Database
myToy.save();
7 changes: 7 additions & 0 deletions ch1/ch1/1-2.js
@@ -0,0 +1,7 @@
var app = {
settings: {
version: "0.0.1"
}
};
app.user = {};
app.user.register = function () {};
4 changes: 4 additions & 0 deletions ch1/ch1/1-3
@@ -0,0 +1,4 @@
<script src="framework.js"></script>
<script src="plugin.framework.js"></script>
<script src="myplugin.framework.js"></script>
<script src="init.js"></script>
7 changes: 7 additions & 0 deletions ch1/ch1/1-4
@@ -0,0 +1,7 @@
<script>
$LAB
.script("framework.js").wait()
.script("plugin.framework.js")
.script("myplugin.framework.js").wait()
.script("init.js").wait();
</script>
1 change: 1 addition & 0 deletions ch10/10-1.js
@@ -0,0 +1 @@
$('a.location-text').on('click', app.conversation.addMap);
1 change: 1 addition & 0 deletions ch10/10-10.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ch10/10-11.html
@@ -0,0 +1,2 @@
<div id="myMap"></div>
<a href="#" id="closeMyMap" class="btn btn-primary">Close Map</a>
16 changes: 16 additions & 0 deletions ch10/10-12.css
@@ -0,0 +1,16 @@
#myMap {
display: none;
position: fixed;
background: red;
top: 60px;
left: 10px;
bottom: 55px;
right: 10px;
}
#closeMyMap {
display: none;
position: fixed;
left: 10px;
bottom: 10px;
right: 10px;
}
26 changes: 26 additions & 0 deletions ch10/10-13.js
@@ -0,0 +1,26 @@
app.modules.map = (function () {
// Module Variables
var map, Message;
// Initialize Module
var _init = function () {
};
// Event for "Close Map" Button
var closeEvent = function () {
};
// Convert a Message Location into a Gmaps Location
var getGLocationFromMessage = function () {
};
// Get a new Map Instance
var getMap = function () {
};
// Call when Map is Ready
var onMapReady = function () {
};
// Hide Conversation and Show Map
var switchView = function () {
};
// Make _init() function accessible form outside
return {
init: _init
};
})();
4 changes: 4 additions & 0 deletions ch10/10-14.js
@@ -0,0 +1,4 @@
var switchView = function() {
$('.container').hide();
$('#myMap, #closeMyMap').css('display', 'block');
};
9 changes: 9 additions & 0 deletions ch10/10-15.js
@@ -0,0 +1,9 @@
var getMap = function() {
map = plugin.google.maps.Map.getMap($('#myMap')[0], {
'controls': {
'compass': true,
'myLocationButton': true,
'zoom': true
}
});
};
5 changes: 5 additions & 0 deletions ch10/10-16.js
@@ -0,0 +1,5 @@
var getGLocationFromMessage = function(Message) {
return new plugin.google.maps.LatLng(
Message.get('location').latitude,
Message.get('location').longitude);
};
9 changes: 9 additions & 0 deletions ch10/10-17.js
@@ -0,0 +1,9 @@
var onMapReady = function(map) {
map.animateCamera({
'target': getGLocationFromMessage(Message),
'zoom': 15,
'duration': 3000,
'tilt': 0,
'bearing': 0
});
};
7 changes: 7 additions & 0 deletions ch10/10-18.js
@@ -0,0 +1,7 @@
var closeEvent = function() {
$('#closeMyMap').on('tap click', function() {
$('.container').show();
$('#myMap, #closeMyMap').css('display', 'none');
map.remove();
});
};
7 changes: 7 additions & 0 deletions ch10/10-19.js
@@ -0,0 +1,7 @@
var _init = function(_Message) {
Message = _Message;
switchView();
getMap();
closeEvent();
map.addEventListener(plugin.google.maps.event.MAP_READY, onMapReady);
};
13 changes: 13 additions & 0 deletions ch10/10-2.js
@@ -0,0 +1,13 @@
addMap: function (event) {
event.preventDefault();
// Add Map Element
var mapClasses = 'alert well-sm alert-info';
$('<div id="mapbox" class="' + mapClasses + '"></div>').insertBefore(this);
// Set Mapbox Access Token
L.mapbox.accessToken = '{your-mapbox-access-token}';
// Create Mapbox Instance
var map = L.mapbox.map('mapbox', '{your-mapbox-map-id}', {
zoomControl: false,
attributionControl: false
});
}
5 changes: 5 additions & 0 deletions ch10/10-20.js
@@ -0,0 +1,5 @@
addMap: function(event) {
event.preventDefault();
var Message = app.conversation.Messages[$(this).data('id')];
app.modules.map.init(Message);
}
8 changes: 8 additions & 0 deletions ch10/10-21.js
@@ -0,0 +1,8 @@
$('#navigation').on('hide.bs.collapse', function () {
map.setClickable(true);
$('.modal-backdrop').remove();
});
$('#navigation').on('show.bs.collapse', function () {
map.setClickable(false);
$('body').append('<div class="modal-backdrop fade in" style="z-index: 999"></div>');
});
7 changes: 7 additions & 0 deletions ch10/10-22.js
@@ -0,0 +1,7 @@
var addMessageMarker = function(Message) {
map.addMarker({
'position': getGLocationFromMessage(Message),
'title': Message.get('sender').get('first_name'),
'snippet': Message.get('message_body')
});
};
4 changes: 4 additions & 0 deletions ch10/10-23.js
@@ -0,0 +1,4 @@
var onMapReady = function(_map) {
addMessageMarker(Message);
// map.animateCamera() ...
};
1 change: 1 addition & 0 deletions ch10/10-24.js
@@ -0,0 +1 @@
var map, Message, message_ids = [], loading = false;
6 changes: 6 additions & 0 deletions ch10/10-25.js
@@ -0,0 +1,6 @@
var onMapReady = function(_map) {
// Keep existing code...
map.animateCamera(options, function() {
map.on(plugin.google.maps.event.CAMERA_CHANGE, getMapCenter);
});
});
7 changes: 7 additions & 0 deletions ch10/10-26.js
@@ -0,0 +1,7 @@
var getMapCenter = function(position) {
if (loading) {
return;
}
loading = true;
getMessagesNearBy(position).then(addMarkersToMap);
};
13 changes: 13 additions & 0 deletions ch10/10-27.js
@@ -0,0 +1,13 @@
var getMessagesNearBy = function (position) {
var currentPosition = new Parse.GeoPoint({
latitude: position.target.lat,
longitude: position.target.lng
});
var query = new Parse.Query(MyParseMessage);
query.near("location", currentPosition);
// Alternatives:
// query.withinMiles("location", currentPosition, 3);
// query.withinKilometers("location", currentPosition, 5);
query.limit(10);
return query.find();
};
10 changes: 10 additions & 0 deletions ch10/10-28.js
@@ -0,0 +1,10 @@
var addMarkersToMap = function(Messages) {
$.each(Messages, function(index, Message) {
if ($.inArray(Message.id, message_ids) > -1) {
return;
}
message_ids.push(Message.id);
addMessageMarker(Message);
});
loading = false;
};
7 changes: 7 additions & 0 deletions ch10/10-29.js
@@ -0,0 +1,7 @@
var onMapReady = function(_map) {
// Keep existing code...
// Replace getMapCenter with getVisibleRegion
map.animateCamera(options, function() {
map.on(plugin.google.maps.event.CAMERA_CHANGE, getVisibleRegion);
});
});
10 changes: 10 additions & 0 deletions ch10/10-3.js
@@ -0,0 +1,10 @@
renderMessages: function() {
var limit = 5;
MyParseConversation.getMessages(app.conversation.Receiver,
limit).then(function(Messages) {
// Render Messages ...
$(Messages).each(function(index, Message) {
app.conversation.Messages[Message.id] = Message;
});
});
}
9 changes: 9 additions & 0 deletions ch10/10-30.js
@@ -0,0 +1,9 @@
var getVisibleRegion = function(position) {
if (loading) {
return;
}
loading = true;
map.getVisibleRegion(function(latLngBounds) {
getMessagesWithinBounds(latLngBounds).then(addMarkersToMap);
});
};
10 changes: 10 additions & 0 deletions ch10/10-31.js
@@ -0,0 +1,10 @@
var getMessagesWithinBounds = function(latLngBounds) {
var southwest = new Parse.GeoPoint(latLngBounds.southwest.lat,
latLngBounds.southwest.lng);
var northeast = new Parse.GeoPoint(latLngBounds.northeast.lat,
latLngBounds.northeast.lng);
var query = new Parse.Query(MyParseMessage);
query.withinGeoBox("location", southwest, northeast);
query.limit(10);
return query.find();
};
19 changes: 19 additions & 0 deletions ch10/10-4.js
@@ -0,0 +1,19 @@
var Message = app.conversation.Messages[$(this).data('id')];
map.setView([Message.get('location').latitude, Message.get('location').longitude], 14);
L.mapbox.featureLayer({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [
Message.get('location').longitude,
Message.get('location').latitude
]
},
properties: {
title: Message.get('sender').get('first_name'),
description: Message.get('message_body'),
'marker-size': 'large',
'marker-color': '#BE9A6B',
'marker-symbol': 'post'
}
}).addTo(map);
11 changes: 11 additions & 0 deletions ch10/10-5.js
@@ -0,0 +1,11 @@
// Remove Map on Click
map.on('click', function(e) {
map.remove();
$('#mapbox').remove();
});
// Disable drag and zoom handlers.
map.dragging.disable();
map.touchZoom.disable();
map.doubleClickZoom.disable();
// Disable tap handler, if present.
if (map.tap) map.tap.disable();
7 changes: 7 additions & 0 deletions ch10/10-6.js
@@ -0,0 +1,7 @@
addMap: function(event) {
event.preventDefault();
if ($('#mapbox').length) {
$('#mapbox').remove();
}
// ...
}
2 changes: 2 additions & 0 deletions ch10/10-7.html
@@ -0,0 +1,2 @@
<script src="https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v0.0.3/Leaflet.fullscreen.min.js"></script>
<link href="https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v0.0.3/leaflet.fullscreen.css" rel="stylesheet" />
1 change: 1 addition & 0 deletions ch10/10-8.js
@@ -0,0 +1 @@
L.control.fullscreen().addTo(map);
13 changes: 13 additions & 0 deletions ch10/10-9.js
@@ -0,0 +1,13 @@
map.on('fullscreenchange', function(e) {
map.setView([Message.get('location').latitude,
Message.get('location').longitude]);
if (map.isFullscreen()) {
$('#mapbox').removeClass(mapClasses);
map.dragging.enable();
map.touchZoom.enable();
} else {
$('#mapbox').addClass(mapClasses);
map.dragging.disable();
map.touchZoom.disable();
}
});
1 change: 1 addition & 0 deletions ch11/11-1
@@ -0,0 +1 @@
cordova plugin add org.apache.cordova.camera

0 comments on commit faa454f

Please sign in to comment.