Skip to content

Commit

Permalink
new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
orktes committed Apr 16, 2012
1 parent 69c3b35 commit 9ad3bd0
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 30 deletions.
2 changes: 2 additions & 0 deletions lib/repositories/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ exports.saveMessage = function (message, callback) {

multi.hmset(hash, serializeMessage(data));

data.ts = new Date(data.ts);

multi.zadd('messages', time, id);

if (data.s) {
Expand Down
47 changes: 26 additions & 21 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
max-width: 266px;
}

.message .time {
float: right;
}

</style>
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">

Expand Down Expand Up @@ -61,51 +65,52 @@
<div class="media">
<div class="row">
<div class="span3">
<a href="#" data-action="play" data-type="<%=url.metadata.content.type%>" data-src="<%=encodeURI(url.metadata.content.src)%>"><img src="<%=url.metadata.thumbnail%>" /></a>
<a href="#" data-action="play" data-type="<%=url.metadata.content.type%>"
data-src="<%=encodeURI(url.metadata.content.src)%>"><img src="<%=url.metadata.thumbnail%>"/></a>
</div>
<div class="span3 description">
<h4><%=url.metadata.title%></h4>
<p><%=url.metadata.description%></p>

<p class="description-text"><%=url.metadata.description%></p>
<% if (url.metadata.fullDescription) { %>
<a href="#" data-action="show-full-description">Show full description</a>
<% } %>


</div>
</div>
</div>
</script>
<script id="media-website-template" type="text/template">
<div class="media">
<a target="_blank" href="<%=url.url%>"><img src="/img/thumbnails/<%=msg.id%>.png" /></a>
<a target="_blank" href="<%=url.url%>"><img src="/img/thumbnails/<%=msg.id%>.png"/></a>
</div>
</script>
<script id="media-image-template" type="text/template">
<div class="media">
<a target="_blank" href="<%=url.url%>"><img src="<%=url.url%>" /></a>
<a target="_blank" href="<%=url.url%>"><img src="<%=url.url%>"/></a>
</div>
</script>
<script id="special-message-template" type="text/template">
<div class="message">
<div class="row">
<div class="span1 message-icon"><img src="<%=icon%>"/></div>
<div class="span8">
<div class="row">
<div class="from"><%=from%>@<a href="#!/to/<%=to%>"><%=to%></a></div>
<div class="message"><%=msg%></div>
</div>

<div class="time pretty-time" data-ts="<%=ts%>"><%=utils.convertDateToText(ts)%></div>
<div class="from"><%=from%>@<a href="#!/to/<%=to%>"><%=to%></a></div>
<div class="message"><%=msg%></div>
<% if (urls.length > 0) { %>
<div class="row urls well">
<div class="urls well">

</div>
<% } %>
</div>

</div>
<hr/>
</div>
</script>
<script id="message-template" type="text/template">
<div class="message">
<div class="row">
<div class="span8">...</div>
<hr/>
</div>

<div class="time pretty-time" data-ts="<%=ts%>"><%=utils.convertDateToText(ts)%></div>
<div class="from"><%=from%>@<a href="#!/to/<%=to%>"><%=to%></a></div>
<div class="message"><%=msg%></div>
<hr/>
</div>
</script>
Expand All @@ -126,8 +131,8 @@ <h4><%=url.metadata.title%></h4>

<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="#!/special">Special</a></li>
<li><a href="#!/all">All messages</a></li>
<li class="active menu-item menu-item-special"><a href="#!/special">Special</a></li>
<li class="menu-item menu-item-all"><a href="#!/all">All messages</a></li>
</ul>
</div>
<!--/.nav-collapse -->
Expand Down
11 changes: 10 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,14 @@ $(function () {
socket.on('new_message', function (msg) {
ui.addMessage(msg, true);
});



function prettyTime() {
var item = $('.pretty-time');
item.html(window.utils.convertDateToText(item.data('ts')));
}

setInterval(prettyTime, 1000 * 60);
prettyTime();

});
43 changes: 43 additions & 0 deletions public/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,48 @@
},
addMessage: function (msg, prepend) {
var self = this;

if (this.filterType != 'all') {
switch (this.filterType) {
case "tag":
if ($.inArray(this.filterValue, msg.tags) === -1) {
return false;
}
break;
case "to":
if (msg.to != this.filterValue) {
return false;
}
break;
case "type":
var found = false;

$.each(msg.urls, function (indx, url) {
if (url.type == self.filterValue) {
found = true;
}
});

if (!found) {
return false;
}
break;
case "special":
if (!msg.s) {
return false;
}
break;
case "search":
return false;
break;
}
}


this.messageCount++;
var messages = $('.messages');
var element;
msg.msg = $("<div></div>").text(msg.msg).html();
if (msg.s) { // Special message
if (msg.urls.length > 0) {
msg.icon = this.media[msg.urls[0].type].icon;
Expand Down Expand Up @@ -69,16 +108,20 @@
var skip = this.messageCount;
var path = "";

$('.menu-item').removeClass('active');

switch (this.filterType) {
case "tag":
case "type":
case "to":
path = "/messages/" + this.filterType + "/" + encodeURIComponent(this.filterValue);
break;
case "all":
$('.menu-item-all').addClass('active');
path = "/messages/";
break;
case "special":
$('.menu-item-special').addClass('active');
path = "/messages/special"
break;
case "single":
Expand Down
15 changes: 12 additions & 3 deletions public/js/ui.media.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
youtube: {
icon: "/img/icons/vimeo.png",
createElement: function (url, msg) {

if (url.metadata.description.length > 450) {
url.metadata.fullDescription = url.metadata.description;
url.metadata.description = url.metadata.description.substring(0, 450) + "...";
}

var html = tmpl($('#media-youtube-template').html(), {url: url, msg: msg});
var element = $(html);
var media = $(html);

element.find('a').click(function (e) {
media.find('a').click(function (e) {


var item = $(this);
Expand All @@ -49,11 +55,14 @@
break;
}

} else if (action == "show-full-description") {
e.preventDefault();
media.find('.description-text').html(url.metadata.fullDescription);
}

});

return element;
return media;
}
},
vimeo: {
Expand Down
43 changes: 38 additions & 5 deletions public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,45 @@
return data ? fn( data ) : fn;
};

/*
* JavaScript Pretty Date
* Copyright (c) 2011 John Resig (ejohn.org)
* Licensed under the MIT and GPL licenses.
*/

// Takes an ISO time and returns a string representing how
// long ago the date represents.
function prettyDate(time){
var date = new Date(time),
diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);

if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
return;

return day_diff == 0 && (
diff < 60 && "just now" ||
diff < 120 && "1 minute ago" ||
diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
diff < 7200 && "1 hour ago" ||
diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
day_diff == 1 && "Yesterday" ||
day_diff < 7 && day_diff + " days ago" ||
day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks ago";
}

// If jQuery is included in the page, adds a jQuery plugin to handle it as well
if ( typeof jQuery != "undefined" )
jQuery.fn.prettyDate = function(){
return this.each(function(){
var date = prettyDate(this.title);
if ( date )
jQuery(this).text( date );
});
};

var utils = {
convertDateToText: function (date) {
if (typeof date === "string") {
date = new Date(date);
}
}
convertDateToText: prettyDate
};

if (window.utils === undefined) {
Expand Down

0 comments on commit 9ad3bd0

Please sign in to comment.