From 59baf43d92d81a3a4c41ccf9b643ac20977e2ed0 Mon Sep 17 00:00:00 2001 From: Gary Hodgson Date: Thu, 13 Sep 2012 21:50:08 +0100 Subject: [PATCH] prettydate bug - replaced with humaneDate; reverted lightbox --- _includes/footer.html | 2 +- _layouts/default.html | 8 +- index.md | 12 +- js/humane.js | 134 ++++++++++++++ js/lightbox/lightbox.js | 355 ------------------------------------ js/lightbox/lightbox.min.js | 12 +- js/prettydate.js | 36 ---- 7 files changed, 157 insertions(+), 402 deletions(-) create mode 100644 js/humane.js delete mode 100644 js/lightbox/lightbox.js delete mode 100644 js/prettydate.js diff --git a/_includes/footer.html b/_includes/footer.html index 003aaf6..207ca17 100644 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -1,4 +1,4 @@ \ No newline at end of file diff --git a/_layouts/default.html b/_layouts/default.html index 15bb7ca..a169771 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -116,7 +116,7 @@

STLs

- + @@ -365,8 +365,10 @@

STLs

processDirectories('{{ page.img_dir }}', showImages); processDirectories('{{ page.stl_dir }}', showSTLs); - $('#updated').append(" "+prettyDate(githubRepo.updated_at)); - $('#created').append(" "+prettyDate(githubRepo.created_at)); + $('#updated').append(" "+humaneDate(githubRepo.updated_at)); + $('#updated').attr('title', (new Date(githubRepo.updated_at)).toLocaleString()); + $('#created').append(" "+humaneDate(githubRepo.created_at)); + $('#created').attr('title', (new Date(githubRepo.created_at)).toLocaleString()); {% if page.description_file %} diff --git a/index.md b/index.md index 21f33df..9a185ed 100644 --- a/index.md +++ b/index.md @@ -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. @@ -48,3 +48,13 @@ layout: default
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.) \ No newline at end of file diff --git a/js/humane.js b/js/humane.js new file mode 100644 index 0000000..83245ba --- /dev/null +++ b/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); + } + }); + }; +} \ No newline at end of file diff --git a/js/lightbox/lightbox.js b/js/lightbox/lightbox.js deleted file mode 100644 index 9d26a36..0000000 --- a/js/lightbox/lightbox.js +++ /dev/null @@ -1,355 +0,0 @@ - -/* -Lightbox v2.51 -by Lokesh Dhakar - http://www.lokeshdhakar.com - - -Slight modification by Gary Hodgson: images larger than screen should be scaled down. - - -For more information, visit: -http://lokeshdhakar.com/projects/lightbox2/ - -Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/ -- free for use in both personal and commercial projects -- attribution requires leaving author name, author link, and the license info intact - -Thanks -- Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.com), and Thomas Fuchs(mir.aculo.us) for ideas, libs, and snippets. -- Artemy Tregubenko (arty.name) for cleanup and help in updating to latest proto-aculous in v2.05. - - -Table of Contents -================= -LightboxOptions - -Lightbox -- constructor -- init -- enable -- build -- start -- changeImage -- sizeContainer -- showImage -- updateNav -- updateDetails -- preloadNeigbhoringImages -- enableKeyboardNav -- disableKeyboardNav -- keyboardAction -- end - -options = new LightboxOptions -lightbox = new Lightbox options -*/ - -(function() { - var $, Lightbox, LightboxOptions; - - $ = jQuery; - - LightboxOptions = (function() { - - function LightboxOptions() { - this.fileLoadingImage = 'img/lightbox/loading.gif'; - this.fileCloseImage = 'img/lightbox/close.png'; - this.resizeDuration = 100; - this.fadeDuration = 100; - this.labelImage = "Image"; - this.labelOf = "of"; - } - - return LightboxOptions; - - })(); - - Lightbox = (function() { - - function Lightbox(options) { - this.options = options; - this.album = []; - this.currentImageIndex = void 0; - this.init(); - } - - Lightbox.prototype.init = function() { - this.enable(); - return this.build(); - }; - - Lightbox.prototype.enable = function() { - var _this = this; - return $('body').on('click', 'a[rel^=lightbox], area[rel^=lightbox]', function(e) { - _this.start($(e.currentTarget)); - return false; - }); - }; - - Lightbox.prototype.build = function() { - var $lightbox, - _this = this; - $("
", { - id: 'lightboxOverlay' - }).after($('
', { - id: 'lightbox' - }).append($('
', { - "class": 'lb-outerContainer' - }).append($('
', { - "class": 'lb-container' - }).append($('', { - "class": 'lb-image' - }), $('
', { - "class": 'lb-nav' - }).append($('', { - "class": 'lb-prev' - }), $('', { - "class": 'lb-next' - })), $('
', { - "class": 'lb-loader' - }).append($('', { - "class": 'lb-cancel' - }).append($('', { - src: this.options.fileLoadingImage - }))))), $('
', { - "class": 'lb-dataContainer' - }).append($('
', { - "class": 'lb-data' - }).append($('
', { - "class": 'lb-details' - }).append($('', { - "class": 'lb-caption' - }), $('', { - "class": 'lb-number' - })), $('
', { - "class": 'lb-closeContainer' - }).append($('', { - "class": 'lb-close' - }).append($('', { - src: this.options.fileCloseImage - }))))))).appendTo($('body')); - $('#lightboxOverlay').hide().on('click', function(e) { - _this.end(); - return false; - }); - $lightbox = $('#lightbox'); - $lightbox.hide().on('click', function(e) { - if ($(e.target).attr('id') === 'lightbox') _this.end(); - return false; - }); - $lightbox.find('.lb-outerContainer').on('click', function(e) { - if ($(e.target).attr('id') === 'lightbox') _this.end(); - return false; - }); - $lightbox.find('.lb-prev').on('click', function(e) { - _this.changeImage(_this.currentImageIndex - 1); - return false; - }); - $lightbox.find('.lb-next').on('click', function(e) { - _this.changeImage(_this.currentImageIndex + 1); - return false; - }); - $lightbox.find('.lb-loader, .lb-close').on('click', function(e) { - _this.end(); - return false; - }); - }; - - Lightbox.prototype.start = function($link) { - var $lightbox, $window, a, i, imageNumber, left, top, _len, _ref; - $(window).on("resize", this.sizeOverlay); - $('select, object, embed').css({ - visibility: "hidden" - }); - $('#lightboxOverlay').width($(document).width()).height($(document).height()).fadeIn(this.options.fadeDuration); - this.album = []; - imageNumber = 0; - if ($link.attr('rel') === 'lightbox') { - this.album.push({ - link: $link.attr('href'), - title: $link.attr('title') - }); - } else { - _ref = $($link.prop("tagName") + '[rel="' + $link.attr('rel') + '"]'); - for (i = 0, _len = _ref.length; i < _len; i++) { - a = _ref[i]; - this.album.push({ - link: $(a).attr('href'), - title: $(a).attr('title') - }); - if ($(a).attr('href') === $link.attr('href')) imageNumber = i; - } - } - $window = $(window); - top = $window.scrollTop() + $window.height() / 10; - left = $window.scrollLeft(); - $lightbox = $('#lightbox'); - $lightbox.css({ - top: top + 'px', - left: left + 'px' - }).fadeIn(this.options.fadeDuration); - this.changeImage(imageNumber); - }; - - Lightbox.prototype.changeImage = function(imageNumber) { - var $image, $lightbox, preloader, - _this = this; - this.disableKeyboardNav(); - $lightbox = $('#lightbox'); - $image = $lightbox.find('.lb-image'); - this.sizeOverlay(); - $('#lightboxOverlay').fadeIn(this.options.fadeDuration); - $('.loader').fadeIn('slow'); - $lightbox.find('.lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide(); - $lightbox.find('.lb-outerContainer').addClass('animating'); - preloader = new Image; - preloader.onload = function() { - $image.attr('src', _this.album[imageNumber].link); - $image.width = Math.min(preloader.width, window.innerWidth); - $image.height = Math.min(preloader.height, window.innerHeight); - return _this.sizeContainer($image.width, $image.height); - }; - preloader.src = this.album[imageNumber].link; - this.currentImageIndex = imageNumber; - }; - - Lightbox.prototype.sizeOverlay = function() { - return $('#lightboxOverlay').width($(window).width()).height($(window).height()); - }; - - Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) { - var $container, $lightbox, $outerContainer, containerBottomPadding, containerLeftPadding, containerRightPadding, containerTopPadding, newHeight, newWidth, oldHeight, oldWidth, - _this = this; - $lightbox = $('#lightbox'); - $outerContainer = $lightbox.find('.lb-outerContainer'); - oldWidth = $outerContainer.outerWidth(); - oldHeight = $outerContainer.outerHeight(); - $container = $lightbox.find('.lb-container'); - containerTopPadding = parseInt($container.css('padding-top'), 10); - containerRightPadding = parseInt($container.css('padding-right'), 10); - containerBottomPadding = parseInt($container.css('padding-bottom'), 10); - containerLeftPadding = parseInt($container.css('padding-left'), 10); - newWidth = imageWidth + containerLeftPadding + containerRightPadding; - newHeight = imageHeight + containerTopPadding + containerBottomPadding; - if (newWidth !== oldWidth && newHeight !== oldHeight) { - $outerContainer.animate({ - width: newWidth, - height: newHeight - }, this.options.resizeDuration, 'swing'); - } else if (newWidth !== oldWidth) { - $outerContainer.animate({ - width: newWidth - }, this.options.resizeDuration, 'swing'); - } else if (newHeight !== oldHeight) { - $outerContainer.animate({ - height: newHeight - }, this.options.resizeDuration, 'swing'); - } - setTimeout(function() { - $lightbox.find('.lb-dataContainer').width(newWidth); - $lightbox.find('.lb-prevLink').height(newHeight); - $lightbox.find('.lb-nextLink').height(newHeight); - _this.showImage(); - }, this.options.resizeDuration); - }; - - Lightbox.prototype.showImage = function() { - var $lightbox; - $lightbox = $('#lightbox'); - $lightbox.find('.lb-loader').hide(); - $lightbox.find('.lb-image').fadeIn('slow'); - this.updateNav(); - this.updateDetails(); - this.preloadNeighboringImages(); - this.enableKeyboardNav(); - }; - - Lightbox.prototype.updateNav = function() { - var $lightbox; - $lightbox = $('#lightbox'); - $lightbox.find('.lb-nav').show(); - if (this.currentImageIndex > 0) $lightbox.find('.lb-prev').show(); - if (this.currentImageIndex < this.album.length - 1) { - $lightbox.find('.lb-next').show(); - } - }; - - Lightbox.prototype.updateDetails = function() { - var $lightbox, - _this = this; - $lightbox = $('#lightbox'); - if (typeof this.album[this.currentImageIndex].title !== 'undefined' && this.album[this.currentImageIndex].title !== "") { - $lightbox.find('.lb-caption').html(this.album[this.currentImageIndex].title).fadeIn('fast'); - } - if (this.album.length > 1) { - $lightbox.find('.lb-number').html(this.options.labelImage + ' ' + (this.currentImageIndex + 1) + ' ' + this.options.labelOf + ' ' + this.album.length).fadeIn('fast'); - } else { - $lightbox.find('.lb-number').hide(); - } - $lightbox.find('.lb-outerContainer').removeClass('animating'); - $lightbox.find('.lb-dataContainer').fadeIn(this.resizeDuration, function() { - return _this.sizeOverlay(); - }); - }; - - Lightbox.prototype.preloadNeighboringImages = function() { - var preloadNext, preloadPrev; - if (this.album.length > this.currentImageIndex + 1) { - preloadNext = new Image; - preloadNext.src = this.album[this.currentImageIndex + 1].link; - } - if (this.currentImageIndex > 0) { - preloadPrev = new Image; - preloadPrev.src = this.album[this.currentImageIndex - 1].link; - } - }; - - Lightbox.prototype.enableKeyboardNav = function() { - $(document).on('keyup.keyboard', $.proxy(this.keyboardAction, this)); - }; - - Lightbox.prototype.disableKeyboardNav = function() { - $(document).off('.keyboard'); - }; - - Lightbox.prototype.keyboardAction = function(event) { - var KEYCODE_ESC, KEYCODE_LEFTARROW, KEYCODE_RIGHTARROW, key, keycode; - KEYCODE_ESC = 27; - KEYCODE_LEFTARROW = 37; - KEYCODE_RIGHTARROW = 39; - keycode = event.keyCode; - key = String.fromCharCode(keycode).toLowerCase(); - if (keycode === KEYCODE_ESC || key.match(/x|o|c/)) { - this.end(); - } else if (key === 'p' || keycode === KEYCODE_LEFTARROW) { - if (this.currentImageIndex !== 0) { - this.changeImage(this.currentImageIndex - 1); - } - } else if (key === 'n' || keycode === KEYCODE_RIGHTARROW) { - if (this.currentImageIndex !== this.album.length - 1) { - this.changeImage(this.currentImageIndex + 1); - } - } - }; - - Lightbox.prototype.end = function() { - this.disableKeyboardNav(); - $(window).off("resize", this.sizeOverlay); - $('#lightbox').fadeOut(this.options.fadeDuration); - $('#lightboxOverlay').fadeOut(this.options.fadeDuration); - return $('select, object, embed').css({ - visibility: "visible" - }); - }; - - return Lightbox; - - })(); - - $(function() { - var lightbox, options; - options = new LightboxOptions; - return lightbox = new Lightbox(options); - }); - -}).call(this); diff --git a/js/lightbox/lightbox.min.js b/js/lightbox/lightbox.min.js index 6324bdb..ddb3272 100644 --- a/js/lightbox/lightbox.min.js +++ b/js/lightbox/lightbox.min.js @@ -1,12 +1,12 @@ (function(){var a,j;a=jQuery;j=function(){this.fileLoadingImage="img/lightbox/loading.gif";this.fileCloseImage="img/lightbox/close.png";this.fadeDuration=this.resizeDuration=100;this.labelImage="Image";this.labelOf="of"};var d=function(a){this.options=a;this.album=[];this.currentImageIndex=void 0;this.init()};d.prototype.init=function(){this.enable();return this.build()};d.prototype.enable=function(){var b=this;return a("body").on("click","a[rel^=lightbox], area[rel^=lightbox]",function(c){b.start(a(c.currentTarget)); return!1})};d.prototype.build=function(){var b,c=this;a("
",{id:"lightboxOverlay"}).after(a("
",{id:"lightbox"}).append(a("
",{"class":"lb-outerContainer"}).append(a("
",{"class":"lb-container"}).append(a("",{"class":"lb-image"}),a("
",{"class":"lb-nav"}).append(a("",{"class":"lb-prev"}),a("",{"class":"lb-next"})),a("
",{"class":"lb-loader"}).append(a("",{"class":"lb-cancel"}).append(a("",{src:this.options.fileLoadingImage}))))),a("
",{"class":"lb-dataContainer"}).append(a("
", {"class":"lb-data"}).append(a("
",{"class":"lb-details"}).append(a("",{"class":"lb-caption"}),a("",{"class":"lb-number"})),a("
",{"class":"lb-closeContainer"}).append(a("",{"class":"lb-close"}).append(a("",{src:this.options.fileCloseImage}))))))).appendTo(a("body"));a("#lightboxOverlay").hide().on("click",function(){c.end();return!1});b=a("#lightbox");b.hide().on("click",function(b){"lightbox"===a(b.target).attr("id")&&c.end();return!1});b.find(".lb-outerContainer").on("click", -function(b){"lightbox"===a(b.target).attr("id")&&c.end();return!1});b.find(".lb-prev").on("click",function(){c.changeImage(c.currentImageIndex-1);return!1});b.find(".lb-next").on("click",function(){c.changeImage(c.currentImageIndex+1);return!1});b.find(".lb-loader, .lb-close").on("click",function(){c.end();return!1})};d.prototype.start=function(b){var c,k,d,f,h;a(window).on("resize",this.sizeOverlay);a("select, object, embed").css({visibility:"hidden"});a("#lightboxOverlay").width(a(document).width()).height(a(document).height()).fadeIn(this.options.fadeDuration); -this.album=[];d=0;if("lightbox"===b.attr("rel"))this.album.push({link:b.attr("href"),title:b.attr("title")});else{h=a(b.prop("tagName")+'[rel="'+b.attr("rel")+'"]');k=0;for(f=h.length;kthis.currentImageIndex+1&&(a=new Image,a.src=this.album[this.currentImageIndex+1].link);0< this.currentImageIndex&&(a=new Image,a.src=this.album[this.currentImageIndex-1].link)};d.prototype.enableKeyboardNav=function(){a(document).on("keyup.keyboard",a.proxy(this.keyboardAction,this))};d.prototype.disableKeyboardNav=function(){a(document).off(".keyboard")};d.prototype.keyboardAction=function(a){var c;c=a.keyCode;a=String.fromCharCode(c).toLowerCase();27===c||a.match(/x|o|c/)?this.end():"p"===a||37===c?0!==this.currentImageIndex&&this.changeImage(this.currentImageIndex-1):("n"===a||39=== c)&&this.currentImageIndex!==this.album.length-1&&this.changeImage(this.currentImageIndex+1)};d.prototype.end=function(){this.disableKeyboardNav();a(window).off("resize",this.sizeOverlay);a("#lightbox").fadeOut(this.options.fadeDuration);a("#lightboxOverlay").fadeOut(this.options.fadeDuration);return a("select, object, embed").css({visibility:"visible"})};a(function(){var a;a=new j;return new d(a)})}).call(this); \ No newline at end of file diff --git a/js/prettydate.js b/js/prettydate.js deleted file mode 100644 index eeed979..0000000 --- a/js/prettydate.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 || "").replace(/-/g,"/").replace(/[TZ]/g," ")), - 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 ); - }); - }; \ No newline at end of file