Skip to content

Commit

Permalink
prettydate bug - replaced with humaneDate; reverted lightbox
Browse files Browse the repository at this point in the history
  • Loading branch information
garyhodgson committed Sep 13, 2012
1 parent f0e128c commit 59baf43
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 402 deletions.
2 changes: 1 addition & 1 deletion _includes/footer.html
@@ -1,4 +1,4 @@
<footer>
<hr>
<small>Built with: <a href="https://github.com">Github Pages</a>, <a href="http://twitter.github.com/bootstrap">Twitter Bootstrap</a>, <a href="http://lokeshdhakar.com/projects/lightbox2/">Lightbox2</a>, <a href="http://github.com/tbuser/thingiview.js">Thingiview.js</a>, <a href="https://github.com/k33g/gh3">gh3</a></small>
<small>Built with: <a href="https://github.com">Github Pages</a>, <a href="http://twitter.github.com/bootstrap">Twitter Bootstrap</a>, <a href="http://lokeshdhakar.com/projects/lightbox2/">Lightbox2</a>, <a href="http://github.com/tbuser/thingiview.js">Thingiview.js</a>, <a href="https://github.com/k33g/gh3">gh3</a></small>, <a href="https://github.com/zachleat/Humane-Dates">Humane-Dates</a>
</footer>
8 changes: 5 additions & 3 deletions _layouts/default.html
Expand Up @@ -116,7 +116,7 @@ <h3>STLs</h3>
<!-- Javascript -->

<script src="http://code.jquery.com/jquery-1.8.1.min.js"> </script>
<script src="js/prettydate.js"> </script>
<script src="js/humane.js"> </script>
<script src="js/bootstrap/bootstrap.min.js"></script>
<script src="js/lightbox/lightbox.min.js"></script>
<script src="js/thingiview/Three.js"></script>
Expand Down Expand Up @@ -365,8 +365,10 @@ <h3>STLs</h3>
processDirectories('{{ page.img_dir }}', showImages);
processDirectories('{{ page.stl_dir }}', showSTLs);

$('#updated').append("&nbsp;"+prettyDate(githubRepo.updated_at));
$('#created').append("&nbsp;"+prettyDate(githubRepo.created_at));
$('#updated').append("&nbsp;"+humaneDate(githubRepo.updated_at));
$('#updated').attr('title', (new Date(githubRepo.updated_at)).toLocaleString());
$('#created').append("&nbsp;"+humaneDate(githubRepo.created_at));
$('#created').attr('title', (new Date(githubRepo.created_at)).toLocaleString());

{% if page.description_file %}

Expand Down
12 changes: 11 additions & 1 deletion index.md
Expand Up @@ -28,7 +28,7 @@ stl_dir: stl
src_dir: src

## The headline image
lead_image: assembly.png
lead_image: test-jig.jpg
show_lead_image: true

## Preview the first STL in the list when the page loads.
Expand All @@ -48,3 +48,13 @@ layout: default
<br />

An implementation of movement \#27 from ["501 Mechanical Movements"](http://books.google.de/books/about/507_Mechanical_Movements.html?id=CSH5UgzD8oIC&redir_esc=y) by Henry T. Brown.

**This is still a work in progress.**

***

##### Instructions

* Attach three 623ZZ bearings to the small wheel with short M3 bolts or screws
* Connect the small and large wheel to the frame with an M4 and M5 bolt respectively.
(Note: So far the wheels have been printed and tested, but not yet the frame.)
134 changes: 134 additions & 0 deletions js/humane.js
@@ -0,0 +1,134 @@
/*
* Javascript Humane Dates
* Copyright (c) 2008 Dean Landolt (deanlandolt.com)
* Re-write by Zach Leatherman (zachleat.com)
*
* Adopted from the John Resig's pretty.js
* at http://ejohn.org/blog/javascript-pretty-date
* and henrah's proposed modification
* at http://ejohn.org/blog/javascript-pretty-date/#comment-297458
*
* Licensed under the MIT license.
*/

function humaneDate(date, compareTo){

if(!date) {
return;
}

var lang = {
ago: 'Ago',
from: '',
now: 'Just Now',
minute: 'Minute',
minutes: 'Minutes',
hour: 'Hour',
hours: 'Hours',
day: 'Day',
days: 'Days',
week: 'Week',
weeks: 'Weeks',
month: 'Month',
months: 'Months',
year: 'Year',
years: 'Years'
},
formats = [
[60, lang.now],
[3600, lang.minute, lang.minutes, 60], // 60 minutes, 1 minute
[86400, lang.hour, lang.hours, 3600], // 24 hours, 1 hour
[604800, lang.day, lang.days, 86400], // 7 days, 1 day
[2628000, lang.week, lang.weeks, 604800], // ~1 month, 1 week
[31536000, lang.month, lang.months, 2628000], // 1 year, ~1 month
[Infinity, lang.year, lang.years, 31536000] // Infinity, 1 year
],
isString = typeof date == 'string',
date = isString ?
new Date(('' + date).replace(/-/g,"/").replace(/[TZ]/g," ")) :
date,
compareTo = compareTo || new Date,
seconds = (compareTo - date +
(compareTo.getTimezoneOffset() -
// if we received a GMT time from a string, doesn't include time zone bias
// if we got a date object, the time zone is built in, we need to remove it.
(isString ? 0 : date.getTimezoneOffset())
) * 60000
) / 1000,
token;

if(seconds < 0) {
seconds = Math.abs(seconds);
token = lang.from ? ' ' + lang.from : '';
} else {
token = lang.ago ? ' ' + lang.ago : '';
}

/*
* 0 seconds && < 60 seconds Now
* 60 seconds 1 Minute
* > 60 seconds && < 60 minutes X Minutes
* 60 minutes 1 Hour
* > 60 minutes && < 24 hours X Hours
* 24 hours 1 Day
* > 24 hours && < 7 days X Days
* 7 days 1 Week
* > 7 days && < ~ 1 Month X Weeks
* ~ 1 Month 1 Month
* > ~ 1 Month && < 1 Year X Months
* 1 Year 1 Year
* > 1 Year X Years
*
* Single units are +10%. 1 Year shows first at 1 Year + 10%
*/

function normalize(val, single)
{
var margin = 0.1;
if(val >= single && val <= single * (1+margin)) {
return single;
}
return val;
}

for(var i = 0, format = formats[0]; formats[i]; format = formats[++i]) {
if(seconds < format[0]) {
if(i === 0) {
// Now
return format[1];
}

var val = Math.ceil(normalize(seconds, format[3]) / (format[3]));
return val +
' ' +
(val != 1 ? format[2] : format[1]) +
(i > 0 ? token : '');
}
}
};

if(typeof jQuery != 'undefined') {
jQuery.fn.humaneDates = function(options)
{
var settings = jQuery.extend({
'lowercase': false
}, options);

return this.each(function()
{
var $t = jQuery(this),
date = $t.attr('datetime') || $t.attr('title');

date = humaneDate(date);

if(date && settings['lowercase']) {
date = date.toLowerCase();
}

if(date && $t.html() != date) {
// don't modify the dom if we don't have to
$t.html(date);
}
});
};
}

0 comments on commit 59baf43

Please sign in to comment.