Skip to content

Commit

Permalink
hashtags are blue
Browse files Browse the repository at this point in the history
  • Loading branch information
Danwhy committed Jun 12, 2015
1 parent 16cb5e0 commit 804bb70
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module.exports = function(fake){
// }
var base = {};

base.addQuack = function(id, quack, time, userID, lat, lon, address, callback){
client.hmset(id, "quack", quack, "time", time, "userID", userID, "id", id, "lat", lat, "lon", lon, "address", address, callback);
base.addQuack = function(id, quack, hashtag, time, userID, lat, lon, address, callback){
client.hmset(id, "quack", quack, "hashtag", hashtag, "time", time, "userID", userID, "id", id, "lat", lat, "lon", lon, "address", address, callback);
};


Expand Down
20 changes: 11 additions & 9 deletions endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ endpoints = function(fake){
userID = forUserID && forUserID.split(/&lat=\S+/)[0],
interim = forUserID && forUserID.split("&lon="),
lat = interim && interim[0].split("&lat=")[1],
lon = interim && interim[1];

time = new Date().toDateString() + " at " + new Date().toTimeString();
var geolocationName;


lon = interim && interim[1],
time = new Date().toDateString() + " at " + new Date().toTimeString(),
hashtag,
geolocationName;

// HACKY HACKY HACKY way of dealing with url encoding anomalies
quack = quack && quack.replace(/%20/g, ' ').replace(/%2E/g, '.').replace(/%27/g, "'").replace(/%A3/g, "£").replace(/%80/g, "€");
quack = quack && quack.replace(/%22/g, '"').replace(/%3E/g, ">").replace(/%3C/g, "<").replace(/%23/g, '#');
quack = quack && quack.replace(/%22/g, '"').replace(/%3E/g, ">").replace(/%3C/g, "<").replace(/%23/g, '#');
quack = quack && duckTranslate(quack);

if (quack.indexOf('#')){
hashtag = quack.match(/#\w+$|#\w+/);
}

if (!quack){
res.writeHead(500);
res.end();
Expand All @@ -49,8 +51,8 @@ endpoints = function(fake){
request("https://nominatim.openstreetmap.org/reverse?format=json&lat=" + lat + "&lon=" + lon, function(err, response, body){
if (!err && response.statusCode === 200){
geolocationName = JSON.parse(body).address.road + ", " + JSON.parse(body).address.suburb;
base.addQuack(id, quack, time, userID, lat, lon, geolocationName, function handler(err, reply){
res.end(JSON.stringify([{quack : quack, time : time, userID : userID, id : id, lat: lat, lon: lon, address: geolocationName}]));
base.addQuack(id, quack, hashtag, time, userID, lat, lon, geolocationName, function handler(err, reply){
res.end(JSON.stringify([{quack : quack, hashtag : hashtag, time : time, userID : userID, id : id, lat: lat, lon: lon, address: geolocationName}]));
next();
});
}
Expand Down
8 changes: 5 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var sendQuack = document.getElementById('sendQuack'),
'I\'ll be Quack.', 'Use the Quack, Luke.', 'Quacks. Why\'d it have to be Quacks?',
'I have had it with these motherQuacking snakes on this motherQuacking plane!',
'I wish I knew how to Quack you.', 'I\'ll Quack what she\'s Quacking.', 'Here\'s Quacking at you, kid.',
'Don\'t cross the Quacks.', 'If you wanna be my Quacker, you gotta get with my Quack'],
'Don\'t cross the Quacks.', 'If you wanna be my Quacker, you gotta get with my Quack',
'Never gonna Quack you up, never gonna Quack you down'],
quacks,
socket = io();

Expand Down Expand Up @@ -82,7 +83,9 @@ function getQuackFromArray(quacksArray){

function showQuack(quack){
ducksOnMap({lat: quack.lat, lon: quack.lon, quack: quack.quack});

if (quack.hashtag){
quack.quack = quack.quack.replace(/(#\w+$|#\w+)/, '<span class="hash">' + '$1' + '</span>');
}
var geolocationName = quack.address;
var quackContainer = document.createElement("div");
quackContainer.className = 'quack';
Expand Down Expand Up @@ -157,7 +160,6 @@ function deleteQuack(){
}
var request = new XMLHttpRequest();
request.open('DELETE', '/main');
console.log(JSON.stringify(this.parentNode.firstChild.id));
request.send(JSON.stringify(this.parentNode.firstChild.id));

this.parentNode.remove();
Expand Down
4 changes: 4 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@
.hidden {
display: none;
}

.hash {
color: blue;
}

0 comments on commit 804bb70

Please sign in to comment.