From 5784b33936855531d20010f5fb34d9fad3cfa3c4 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 27 Nov 2014 14:32:08 +0900 Subject: add today's date and toggle button between British and American styles --- index.html | 10 +++++++++- js/main.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 3a3c811..97134a5 100644 --- a/index.html +++ b/index.html @@ -37,7 +37,8 @@ @@ -84,6 +85,13 @@ btn-block">Reset timer (end of class) +
+
+
+

,

+
+
+
diff --git a/js/main.js b/js/main.js index 11d76b6..a1afda2 100644 --- a/js/main.js +++ b/js/main.js @@ -108,6 +108,43 @@ function activityClockCustom() activityClockGo(parseInt(minutes) * 60 + parseInt(seconds)); } +// mplungjan on stack overflow: http://stackoverflow.com/a/15397495 +function nth(d) { + if(d>3 && d<21) return 'th'; // thanks kennebec + switch (d % 10) { + case 1: return "st"; + case 2: return "nd"; + case 3: return "rd"; + default: return "th"; + } +} + +function toggleDateStyle() +{ + var currentDate = $('#date').html(); + var today = new Date(); + + var month = "January,February,March,April,May,June,July,August,September,October,November,December" + .split(",")[today.getMonth()]; + var day = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday" + .split(",")[today.getDay()]; + var date = today.getDate(); + var British = day + " " + date + nth(date) + " " + month + " " + today.getFullYear(); + var American = day + " " + month + " " + date + nth(date) + ", " + today.getFullYear(); + + if (currentDate.indexOf(',') > -1) + { + $('#date').html(British); + } + else + { + $('#date').html(American); + } +} + +// set initial date to British style +toggleDateStyle(); + $(document).bind('keydown', 's', timeWastingClockReset); $(document).bind('keydown', 'r', activityClockReset); $(document).bind('keydown', 'c', activityClockCustom); @@ -159,5 +196,8 @@ $(document).ready(function(){ $('#activityClock300s').button(); $('#activityClock300s').click(function (){activityClockGo(300);}) + + $('#date-toggle').button(); + $('#date-toggle').click(function (){toggleDateStyle();}); }); -- cgit v1.2.3