var arrowMode = false
var lastDay = 31
$(document).ready(function(){
// capture keypresses on body and links that have the 'a' class
// need the 'a' links because as they become focused, the trigger
// from the body no longer works
jQuery(document).keydown(function(e){
if( e.target.nodeName == 'BODY' || $(e.target).hasClass('a') ) {
if( e.keyCode == 65 ) { // 'a' to toggle arrow mode
toggleArrowMode();
e.preventDefault();
} else if( e.keyCode == 39 ) { // left arrow
nextDay()
e.preventDefault();
} else if( e.keyCode == 37) { // right arrow
prevDay()
e.preventDefault();
} else if( e.keyCode == 40) { // down arrow
addWeek()
e.preventDefault();
} else if( e.keyCode == 38) { // up arrow
subWeek()
e.preventDefault();
}
}
});
// give some feedback when an event is clicked
$('a.a').click(function(){
alert('clicked link: ' + $(this).html() + " on day " + $(this).parent().data('d'))
})
}); // end of ready
// turn arrowMode on/off
function toggleArrowMode() {
if( arrowMode ) {
arrowMode = false;
clearSelected(); // turn off current selection
} else {
arrowMode = true;
selectCell(1); // always start with first day
}
}
// add selected class the currently selected
// cell and focus the first link (or any other
// link if that makes more sense.)
function selectCell(cid) {
clearSelected()
var $c = $("td[data-d='"+ cid +"']");
$c.addClass('selected');
$c.find('a').first().focus();
}
// clear the selected cell
function clearSelected() {
$("table tbody td").removeClass('selected');
}
// get the id for the currently selected day
function currentDay() {
return $("td.selected").data('d')
}
// figure out and select the next day, with wrap around for end of month
function nextDay() {
var d = currentDay();
if( d == lastDay ) {
d = 1;
} else {
d++
}
selectCell(d)
}
// figure out...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.