Keyboard Tabbing to Anchors with jQuery

Working on keyboard accessibility the other day, I found out that an anchor will receive focus if you tab to it but will only trigger a jQuery click event if the anchor has an href attribute.

<a>
	Doesn't work with return/enter key
</a><br />

<a href="#keyboard-click-event">
	It works!
</a><br />

To trigger a click event using keyboard, tab to the element and press return/enter key.

Text to Links

Replace any ‘http://’ text URLs with clickable hyperlink that open in a new window:

<?php
function textToHyperlinks( $string ) {
	return preg_replace(
		'@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@',
		'<a href="$1" target="_blank">$1</a>',
		$string
	);
}

Stack Overflow

Handling NTFS Drives in OSX

Was having problems swapping an external hard drive between Windows 7 and Mac OSX. NTFS is a proprietary Microsoft format. Here’s how to solve the problem:

  1. Get MacFUSE and install on OSX: http://code.google.com/p/macfuse/
  2. Get NTFS-3G and install on OSX: http://www.tuxera.com/community/ntfs-3g-download/

There is no app to run since OSX operating system is updated directly. You will also be able to format external drives to NTFS after the install is complete in OSX Disk Utility. You can uninstall MacFUSE or NTFS-3G from System Preferences.

Javascript Slugify

Javascript function to “slugify” a string:

function slugify ( str ) {
  str   = str.toLowerCase();
  str   = str.replace( /\s/gi, "-" );
  str   = str.replace( /\//gi, "-" );
  str   = str.replace( /[^-a-zA-Z0-9,&/\\s]+/ig, '' );
  
  // Trim dash from beginning, end.
  while( str.substr( 0, 1 ) == '-' )  str   = str.substr( 1 );
  while( str.substr( -1 ) == '-' )    str   = str.substr( 0, str.length -1 );
  
  return str;
}

Windows Recursively Delete Folders

Dreamweaver creates _notes folders in each directory when you upload a file. Recently switched to Aptana and wanted to remove all of these folders that are now useless clutter in my filesystem. Here’s how to do it on Windows CLI in one fell swoop:

> cd \path\to\my\project\folder
> for /d /r . %d in (_notes) do @if exist "%d" rd /s/q "%d"

Links

Stack Overflow
Index of Windows CLI

WordPress Menu Posts

Making a Menu containing a bunch of Posts is a good way to create a Page with custom ordering/selection. The new WordPress Menus make it really easy to drag and drop and they give you the option to add Posts in the Screen Options tab.

If you want to swap out Menus in your Theme’s Menu Location frequently, it could get PITA to update your Theme every time you make a new Menu. Here’s how to get those Posts to display on your site with only knowing your Theme’s Menu Location slug instead of hard coding the Menu’s slug into your Theme:

// ---	Get the menu locations. Returns array of ( slugs => ids )
//		The menu location slugs are set in the theme's functions.php file. 
//		@see http://codex.wordpress.org/Function_Reference/register_nav_menus
$menuloc 	= get_nav_menu_locations();
$menuid 	= $menuloc[ 'my-themes-menu-location-slug' ];

// ---	Get the currently assigned containing menu and associated posts.
$menuposts 	= wp_get_nav_menu_items( $menuid );