Permalink
Browse files

Client side relative timestamps on the mobile version

  • Loading branch information...
1 parent 95100ae commit 1befd26102d0fa7739ab4cf60149f438dc0344b0 @elektronaut committed Feb 20, 2012
View
3 app/assets/javascripts/application.js
@@ -1,6 +1,3 @@
-/*jslint browser: true, devel: true, onevar: false, regexp: false*/
-/*global window: false, jQuery: false, $: false, Sugar: false*/
-
//= require jquery
//= require jquery_ujs
//= require underscore
View
32 app/assets/javascripts/mobile.js
@@ -1,10 +1,16 @@
-/*jslint browser: true, devel: true, onevar: false, regexp: false*/
-/*global window: false, jQuery: false, $: false*/
-
//= require jquery
//= require jquery_ujs
+//= require underscore
+//= require backbone
+//= require backbone_rails_sync
+//= require backbone_datalink
+
+//= require vendor/jquery.timeago
+
+//= require backbone/sugar
//= require sugar
//= require sugar/amazon_associates
+//= require sugar/timestamps
function toggleNavigation() {
$('#navigation').toggle();
@@ -20,7 +26,7 @@ function resizeYoutube() {
}
var maxWidth = window.innerWidth - 20;
var maxHeight = window.innerHeight - 20;
-
+
if (maxWidth > this.originalWidth) {
maxWidth = this.originalWidth;
}
@@ -30,12 +36,12 @@ function resizeYoutube() {
var newWidth = maxWidth;
var newHeight = Math.floor(this.originalHeight * (newWidth / this.originalWidth));
-
+
if (newHeight > maxHeight) {
newHeight = maxHeight;
newWidth = Math.floor(this.originalWidth * (newHeight / this.originalHeight));
}
-
+
this.width = newWidth;
this.height = newHeight;
});
@@ -60,7 +66,7 @@ window.quotePost = function (postId) {
var currentWidth = 0;
var currentHeight = 0;
function checkWindowOrientation() {
- if (window.innerWidth !== currentWidth) {
+ if (window.innerWidth !== currentWidth) {
currentWidth = window.innerWidth;
currentHeight = window.innerHeight;
var orient = (currentWidth < currentHeight) ? 'profile' : 'landscape';
@@ -95,7 +101,7 @@ function hideImagesInPosts() {
$(this).removeClass('imageloader');
this.image.src = this.image.originalSrc;
});
-
+
}
$(document).ready(function () {
@@ -118,18 +124,18 @@ $(document).ready(function () {
// Scroll to top w/o location bar unless targeting an anchor
setTimeout(scrollTo, 100, 0, 1);
}
-
+
jQuery('#search_mode').change(function () {
this.parentNode.action = this.value;
});
-
+
// Post quoting
$('.post .functions a.quote_post').click(function () {
var postId = this.id.match(/-([\d]+)$/)[1];
window.quotePost(postId);
return false;
});
-
+
// Spoiler tags
$('.spoiler').each(function () {
var container = this;
@@ -148,7 +154,9 @@ $(document).ready(function () {
container.spoilerApplied = true;
}
});
-
+
resizeYoutube();
+
+ Sugar.init();
});
View
4 app/views/discussions/_table.mobile.erb
@@ -16,7 +16,7 @@
</h2>
<p>
<% if d.kind_of?(Conversation) %>
- <%
+ <%
other_participants = d.participants.reject{|p| p == @current_user}
%>
<% if other_participants.length == 0 %>
@@ -30,7 +30,7 @@
By <%= d.poster.username %>,
<% end %>
<%= d.posts_count %> posts.
- Last: <%= d.last_poster.username %> <%= formatted_time d.last_post_at %>
+ Last: <%= d.last_poster.username %> <%= time_tag d.last_post_at, :class => 'relative' %>
</p>
</div><% end %>
</div>
View
14 app/views/layouts/default.mobile.erb
@@ -1,9 +1,7 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<!DOCTYPE html>
+<html>
<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><%= [@page_title,Sugar.config(:forum_name)].compact.join(' - ') %></title>
<% if @current_user && @current_user.mobile_stylesheet_url? %>
@@ -88,10 +86,10 @@
<%= yield %>
</div>
<div id="footer">
- <%= link_to "Discussions", discussions_path %> |
+ <%= link_to "Discussions", discussions_path %> |
<% if @current_user %>
- <%= link_to "Following", following_discussions_path %> |
- <%= link_to "Favorites", favorites_discussions_path %> |
+ <%= link_to "Following", following_discussions_path %> |
+ <%= link_to "Favorites", favorites_discussions_path %> |
<% end %>
<%= link_to "Regular site", :mobile_format => 'html' %>
</div>
View
8 app/views/posts/_posts.mobile.erb
@@ -27,30 +27,30 @@
<% if post.me_post? %>
<div class="body">
<%= meify post.body, post.user %>
- <span class="date">&ndash; <%= formatted_time post.created_at %></span>
+ <span class="date">&ndash; <%= time_tag post.created_at, :class => 'relative' %></span>
</div>
<% else %>
<div class="post_info">
<a name="post-<%= post.id %>" class="anchor"></a>
<span class="username"><%= profile_link(post.user) %></span>
<span class="date">
- <%= formatted_time post.created_at %>
+ <%= time_tag post.created_at, :class => 'relative' %>
</span>
<span class="permalink">
<%= link_to "#", paged_discussion_path(:id => (discussion||post.discussion), :page => post_page(post), :anchor => "post-#{post.id}"), :title => "Permalink to this post" %>
</span>
</div>
<div class="functions">
<% if post.editable_by?(@current_user) %>
- <%= link_to "Edit", edit_discussion_post_path((discussion||post.discussion), post) %> /
+ <%= link_to "Edit", edit_discussion_post_path((discussion||post.discussion), post) %> /
<% end %>
<%= link_to "Quote", discussion_post_path((discussion||post.discussion), post), :class => 'quote_post', :id => "quotePost-#{post.id}" %>
</div>
<div class="body">
<%= post.user.html_disabled? ? post.body.gsub(/\n/,'<br />') : post.body_html %>
</div>
<% if post.edited? %>
- <div class="post_edited">Edited <%= formatted_time post.edited_at %></div>
+ <div class="post_edited">Edited <%= time_tag post.edited_at, :class => 'relative' %></div>
<% end %>
<% end %>
</div>
View
8 app/views/users/index.mobile.erb
@@ -1,6 +1,6 @@
-<%
+<%
add_body_class "users"
- @page_title = "Users"
+ @page_title = "Users"
%>
<table class="list users_list">
@@ -16,6 +16,8 @@
<%= profile_link(user) %>
<% end %>
</td>
- <td class="last_active"><%= (user.online?) ? "<strong>Online now</strong>".html_safe : formatted_time(user.last_active) %></td>
+ <td class="last_active">
+ <%= (user.online?) ? "<strong>Online now</strong>".html_safe : time_tag(user.last_active, :class => 'relative') %>
+ </td>
</tr><% end %>
</table>
View
4 app/views/users/show.mobile.erb
@@ -71,11 +71,11 @@
</tr><% end %>
<tr>
<th>Joined</th>
- <td><%= formatted_time(@user.created_at) %></td>
+ <td><%= time_tag @user.created_at, :class => 'relative' %></td>
</tr>
<tr>
<th>Last active</th>
- <td><%= @user.online? ? "<strong>Online now</strong>" : formatted_time(@user.last_active) %></td>
+ <td><%= @user.online? ? "<strong>Online now</strong>".html_safe : time_tag(@user.last_active, :class => 'relative') %></td>
</tr>
<tr>
<th>Discussions</th>

0 comments on commit 1befd26

Please sign in to comment.